org.apache.flink.runtime.io.network.api.serialization.EventSerializer Java Examples
The following examples show how to use
org.apache.flink.runtime.io.network.api.serialization.EventSerializer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NettyMessage.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
static TaskEventRequest readFrom(ByteBuf buffer, ClassLoader classLoader) throws IOException { // directly deserialize fromNetty's buffer int length = buffer.readInt(); ByteBuffer serializedEvent = buffer.nioBuffer(buffer.readerIndex(), length); // assume this event's content is read from the ByteBuf (positions are not shared!) buffer.readerIndex(buffer.readerIndex() + length); TaskEvent event = (TaskEvent) EventSerializer.fromSerializedEvent(serializedEvent, classLoader); ResultPartitionID partitionId = new ResultPartitionID( IntermediateResultPartitionID.fromByteBuf(buffer), ExecutionAttemptID.fromByteBuf(buffer)); InputChannelID receiverId = InputChannelID.fromByteBuf(buffer); return new TaskEventRequest(event, partitionId, receiverId); }
Example #2
Source File: RecordOrEventCollectingResultPartitionWriter.java From flink with Apache License 2.0 | 6 votes |
@Override protected void deserializeBuffer(Buffer buffer) throws IOException { if (buffer.isBuffer()) { deserializer.setNextBuffer(buffer); while (deserializer.hasUnfinishedData()) { RecordDeserializer.DeserializationResult result = deserializer.getNextRecord(delegate); if (result.isFullRecord()) { output.add(delegate.getInstance()); } if (result == RecordDeserializer.DeserializationResult.LAST_RECORD_FROM_BUFFER || result == RecordDeserializer.DeserializationResult.PARTIAL_RECORD) { break; } } } else { // is event AbstractEvent event = EventSerializer.fromBuffer(buffer, getClass().getClassLoader()); output.add(event); } }
Example #3
Source File: SpillableSubpartition.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public synchronized void finish() throws IOException { synchronized (buffers) { if (add(EventSerializer.toBufferConsumer(EndOfPartitionEvent.INSTANCE), true)) { isFinished = true; } flush(); } // If we are spilling/have spilled, wait for the writer to finish if (spillWriter != null) { spillWriter.close(); } LOG.debug("{}: Finished {}.", parent.getOwningTaskName(), this); }
Example #4
Source File: RecordOrEventCollectingResultPartitionWriter.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override protected void deserializeBuffer(Buffer buffer) throws IOException { if (buffer.isBuffer()) { deserializer.setNextBuffer(buffer); while (deserializer.hasUnfinishedData()) { RecordDeserializer.DeserializationResult result = deserializer.getNextRecord(delegate); if (result.isFullRecord()) { output.add(delegate.getInstance()); } if (result == RecordDeserializer.DeserializationResult.LAST_RECORD_FROM_BUFFER || result == RecordDeserializer.DeserializationResult.PARTIAL_RECORD) { break; } } } else { // is event AbstractEvent event = EventSerializer.fromBuffer(buffer, getClass().getClassLoader()); output.add(event); } }
Example #5
Source File: RecordOrEventCollectingResultPartitionWriter.java From flink with Apache License 2.0 | 6 votes |
@Override protected void deserializeBuffer(Buffer buffer) throws IOException { if (buffer.isBuffer()) { deserializer.setNextBuffer(buffer); while (deserializer.hasUnfinishedData()) { RecordDeserializer.DeserializationResult result = deserializer.getNextRecord(delegate); if (result.isFullRecord()) { output.add(delegate.getInstance()); } if (result == RecordDeserializer.DeserializationResult.LAST_RECORD_FROM_BUFFER || result == RecordDeserializer.DeserializationResult.PARTIAL_RECORD) { break; } } } else { // is event AbstractEvent event = EventSerializer.fromBuffer(buffer, getClass().getClassLoader()); output.add(event); } }
Example #6
Source File: SpilledBufferOrEventSequenceTest.java From flink with Apache License 2.0 | 6 votes |
private static BufferOrEvent generateAndWriteEvent(FileChannel fileChannel, Random rnd, int numberOfChannels) throws IOException { long magicNumber = rnd.nextLong(); byte[] data = new byte[rnd.nextInt(1000)]; rnd.nextBytes(data); TestEvent evt = new TestEvent(magicNumber, data); int channelIndex = rnd.nextInt(numberOfChannels); ByteBuffer serializedEvent = EventSerializer.toSerializedEvent(evt); ByteBuffer header = ByteBuffer.allocate(9); header.order(ByteOrder.LITTLE_ENDIAN); header.putInt(channelIndex); header.putInt(serializedEvent.remaining()); header.put((byte) 1); header.flip(); FileUtils.writeCompletely(fileChannel, header); FileUtils.writeCompletely(fileChannel, serializedEvent); return new BufferOrEvent(evt, channelIndex); }
Example #7
Source File: NettyMessage.java From flink with Apache License 2.0 | 6 votes |
static TaskEventRequest readFrom(ByteBuf buffer, ClassLoader classLoader) throws IOException { // directly deserialize fromNetty's buffer int length = buffer.readInt(); ByteBuffer serializedEvent = buffer.nioBuffer(buffer.readerIndex(), length); // assume this event's content is read from the ByteBuf (positions are not shared!) buffer.readerIndex(buffer.readerIndex() + length); TaskEvent event = (TaskEvent) EventSerializer.fromSerializedEvent(serializedEvent, classLoader); ResultPartitionID partitionId = new ResultPartitionID( IntermediateResultPartitionID.fromByteBuf(buffer), ExecutionAttemptID.fromByteBuf(buffer)); InputChannelID receiverId = InputChannelID.fromByteBuf(buffer); return new TaskEventRequest(event, partitionId, receiverId); }
Example #8
Source File: SpilledBufferOrEventSequenceTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private static BufferOrEvent generateAndWriteEvent(FileChannel fileChannel, Random rnd, int numberOfChannels) throws IOException { long magicNumber = rnd.nextLong(); byte[] data = new byte[rnd.nextInt(1000)]; rnd.nextBytes(data); TestEvent evt = new TestEvent(magicNumber, data); int channelIndex = rnd.nextInt(numberOfChannels); ByteBuffer serializedEvent = EventSerializer.toSerializedEvent(evt); ByteBuffer header = ByteBuffer.allocate(9); header.order(ByteOrder.LITTLE_ENDIAN); header.putInt(channelIndex); header.putInt(serializedEvent.remaining()); header.put((byte) 1); header.flip(); FileUtils.writeCompletely(fileChannel, header); FileUtils.writeCompletely(fileChannel, serializedEvent); return new BufferOrEvent(evt, channelIndex); }
Example #9
Source File: NettyMessage.java From flink with Apache License 2.0 | 6 votes |
static TaskEventRequest readFrom(ByteBuf buffer, ClassLoader classLoader) throws IOException { // directly deserialize fromNetty's buffer int length = buffer.readInt(); ByteBuffer serializedEvent = buffer.nioBuffer(buffer.readerIndex(), length); // assume this event's content is read from the ByteBuf (positions are not shared!) buffer.readerIndex(buffer.readerIndex() + length); TaskEvent event = (TaskEvent) EventSerializer.fromSerializedEvent(serializedEvent, classLoader); ResultPartitionID partitionId = new ResultPartitionID( IntermediateResultPartitionID.fromByteBuf(buffer), ExecutionAttemptID.fromByteBuf(buffer)); InputChannelID receiverId = InputChannelID.fromByteBuf(buffer); return new TaskEventRequest(event, partitionId, receiverId); }
Example #10
Source File: InputChannel.java From flink with Apache License 2.0 | 5 votes |
/** * Parses the buffer as an event and returns the {@link CheckpointBarrier} if the event is indeed a barrier or * returns null in all other cases. */ @Nullable protected CheckpointBarrier parseCheckpointBarrierOrNull(Buffer buffer) throws IOException { if (buffer.isBuffer()) { return null; } AbstractEvent event = EventSerializer.fromBuffer(buffer, getClass().getClassLoader()); // reset the buffer because it would be deserialized again in SingleInputGate while getting next buffer. // we can further improve to avoid double deserialization in the future. buffer.setReaderIndex(0); return event.getClass() == CheckpointBarrier.class ? (CheckpointBarrier) event : null; }
Example #11
Source File: TestInputChannel.java From flink with Apache License 2.0 | 5 votes |
TestInputChannel readEndOfPartitionEvent() { addBufferAndAvailability( () -> { setReleased(); return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), false, 0)); } ); return this; }
Example #12
Source File: IteratorWrappingTestSingleInputGate.java From flink with Apache License 2.0 | 5 votes |
private IteratorWrappingTestSingleInputGate<T> wrapIterator(MutableObjectIterator<T> iterator) throws IOException, InterruptedException { inputIterator = iterator; serializer = new SpanningRecordSerializer<T>(); // The input iterator can produce an infinite stream. That's why we have to serialize each // record on demand and cannot do it upfront. final BufferAndAvailabilityProvider answer = new BufferAndAvailabilityProvider() { private boolean hasData = inputIterator.next(reuse) != null; @Override public Optional<BufferAndAvailability> getBufferAvailability() throws IOException { if (hasData) { serializer.serializeRecord(reuse); BufferBuilder bufferBuilder = createBufferBuilder(bufferSize); serializer.copyToBufferBuilder(bufferBuilder); hasData = inputIterator.next(reuse) != null; // Call getCurrentBuffer to ensure size is set return Optional.of(new BufferAndAvailability(buildSingleBuffer(bufferBuilder), true, 0)); } else { inputChannel.setReleased(); return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), false, 0)); } } }; inputChannel.addBufferAndAvailability(answer); inputGate.setInputChannel(new IntermediateResultPartitionID(), inputChannel); return this; }
Example #13
Source File: ReadOnlySlicedBufferTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testForwardsIsBuffer() throws IOException { assertEquals(buffer.isBuffer(), buffer.readOnlySlice().isBuffer()); assertEquals(buffer.isBuffer(), buffer.readOnlySlice(1, 2).isBuffer()); Buffer eventBuffer = EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE); assertEquals(eventBuffer.isBuffer(), eventBuffer.readOnlySlice().isBuffer()); assertEquals(eventBuffer.isBuffer(), eventBuffer.readOnlySlice(1, 2).isBuffer()); }
Example #14
Source File: BufferSpiller.java From flink with Apache License 2.0 | 5 votes |
@Override public void add(BufferOrEvent boe) throws IOException { try { ByteBuffer contents; if (boe.isBuffer()) { Buffer buf = boe.getBuffer(); contents = buf.getNioBufferReadable(); } else { contents = EventSerializer.toSerializedEvent(boe.getEvent()); } headBuffer.clear(); headBuffer.putInt(boe.getChannelIndex()); headBuffer.putInt(contents.remaining()); headBuffer.put((byte) (boe.isBuffer() ? 0 : 1)); headBuffer.flip(); bytesWritten += (headBuffer.remaining() + contents.remaining()); FileUtils.writeCompletely(currentChannel, headBuffer); FileUtils.writeCompletely(currentChannel, contents); } finally { if (boe.isBuffer()) { boe.getBuffer().recycleBuffer(); } } }
Example #15
Source File: ChannelStateWriterImpl.java From flink with Apache License 2.0 | 5 votes |
private static String buildBufferTypeErrorMessage(Buffer buffer) { try { AbstractEvent event = EventSerializer.fromBuffer(buffer, ChannelStateWriterImpl.class.getClassLoader()); return String.format("Should be buffer but [%s] found", event); } catch (Exception ex) { return "Should be buffer"; } }
Example #16
Source File: RecordWriter.java From flink with Apache License 2.0 | 5 votes |
public void broadcastEvent(AbstractEvent event, boolean isPriorityEvent) throws IOException { try (BufferConsumer eventBufferConsumer = EventSerializer.toBufferConsumer(event)) { for (int targetChannel = 0; targetChannel < numberOfChannels; targetChannel++) { tryFinishCurrentBufferBuilder(targetChannel); // Retain the buffer so that it can be recycled by each channel of targetPartition targetPartition.addBufferConsumer(eventBufferConsumer.copy(), targetChannel, isPriorityEvent); } if (flushAlways) { flushAll(); } } }
Example #17
Source File: NettyMessage.java From flink with Apache License 2.0 | 5 votes |
@Override ByteBuf write(ByteBufAllocator allocator) throws IOException { ByteBuf result = null; try { // TODO Directly serialize to Netty's buffer ByteBuffer serializedEvent = EventSerializer.toSerializedEvent(event); result = allocateBuffer(allocator, ID, 4 + serializedEvent.remaining() + 20 + 16 + 16); result.writeInt(serializedEvent.remaining()); result.writeBytes(serializedEvent); partitionId.getPartitionId().writeTo(result); partitionId.getProducerId().writeTo(result); receiverId.writeTo(result); return result; } catch (Throwable t) { if (result != null) { result.release(); } throw new IOException(t); } }
Example #18
Source File: RecoveredInputChannel.java From flink with Apache License 2.0 | 5 votes |
private boolean isEndOfChannelStateEvent(Buffer buffer) throws IOException { if (buffer.isBuffer()) { return false; } AbstractEvent event = EventSerializer.fromBuffer(buffer, getClass().getClassLoader()); buffer.setReaderIndex(0); return event.getClass() == EndOfChannelStateEvent.class; }
Example #19
Source File: NettyMessage.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override ByteBuf write(ByteBufAllocator allocator) throws IOException { ByteBuf result = null; try { // TODO Directly serialize to Netty's buffer ByteBuffer serializedEvent = EventSerializer.toSerializedEvent(event); result = allocateBuffer(allocator, ID, 4 + serializedEvent.remaining() + 16 + 16 + 16); result.writeInt(serializedEvent.remaining()); result.writeBytes(serializedEvent); partitionId.getPartitionId().writeTo(result); partitionId.getProducerId().writeTo(result); receiverId.writeTo(result); return result; } catch (Throwable t) { if (result != null) { result.release(); } throw new IOException(t); } }
Example #20
Source File: SingleInputGate.java From flink with Apache License 2.0 | 5 votes |
private BufferOrEvent transformEvent( Buffer buffer, boolean moreAvailable, InputChannel currentChannel) throws IOException, InterruptedException { final AbstractEvent event; try { event = EventSerializer.fromBuffer(buffer, getClass().getClassLoader()); } finally { buffer.recycleBuffer(); } if (event.getClass() == EndOfPartitionEvent.class) { channelsWithEndOfPartitionEvents.set(currentChannel.getChannelIndex()); if (channelsWithEndOfPartitionEvents.cardinality() == numberOfInputChannels) { // Because of race condition between: // 1. releasing inputChannelsWithData lock in this method and reaching this place // 2. empty data notification that re-enqueues a channel // we can end up with moreAvailable flag set to true, while we expect no more data. checkState(!moreAvailable || !pollNext().isPresent()); moreAvailable = false; hasReceivedAllEndOfPartitionEvents = true; markAvailable(); } currentChannel.releaseAllResources(); } return new BufferOrEvent(event, currentChannel.getChannelInfo(), moreAvailable, buffer.getSize()); }
Example #21
Source File: BoundedBlockingSubpartition.java From flink with Apache License 2.0 | 5 votes |
@Override public void finish() throws IOException { checkState(!isReleased, "data partition already released"); checkState(!isFinished, "data partition already finished"); isFinished = true; flushCurrentBuffer(); writeAndCloseBufferConsumer(EventSerializer.toBufferConsumer(EndOfPartitionEvent.INSTANCE)); data.finishWrite(); }
Example #22
Source File: RecordWriterTest.java From flink with Apache License 2.0 | 5 votes |
static BufferOrEvent parseBuffer(BufferConsumer bufferConsumer, int targetChannel) throws IOException { Buffer buffer = buildSingleBuffer(bufferConsumer); if (buffer.isBuffer()) { return new BufferOrEvent(buffer, new InputChannelInfo(0, targetChannel)); } else { // is event: AbstractEvent event = EventSerializer.fromBuffer(buffer, RecordWriterTest.class.getClassLoader()); buffer.recycleBuffer(); // the buffer is not needed anymore return new BufferOrEvent(event, new InputChannelInfo(0, targetChannel)); } }
Example #23
Source File: PipelinedSubpartitionWithReadViewTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testBarrierOvertaking() throws Exception { subpartition.add(createFilledFinishedBufferConsumer(1)); assertEquals(0, availablityListener.getNumNotifications()); assertEquals(0, availablityListener.getNumPriorityEvents()); subpartition.add(createFilledFinishedBufferConsumer(2)); assertEquals(1, availablityListener.getNumNotifications()); assertEquals(0, availablityListener.getNumPriorityEvents()); BufferConsumer eventBuffer = EventSerializer.toBufferConsumer(EndOfSuperstepEvent.INSTANCE); subpartition.add(eventBuffer); assertEquals(1, availablityListener.getNumNotifications()); assertEquals(0, availablityListener.getNumPriorityEvents()); subpartition.add(createFilledFinishedBufferConsumer(4)); assertEquals(1, availablityListener.getNumNotifications()); assertEquals(0, availablityListener.getNumPriorityEvents()); CheckpointOptions options = new CheckpointOptions( CheckpointType.CHECKPOINT, new CheckpointStorageLocationReference(new byte[]{0, 1, 2}), true, true); BufferConsumer barrierBuffer = EventSerializer.toBufferConsumer(new CheckpointBarrier(0, 0, options)); subpartition.add(barrierBuffer, true); assertEquals(2, availablityListener.getNumNotifications()); assertEquals(0, availablityListener.getNumPriorityEvents()); List<Buffer> inflight = subpartition.requestInflightBufferSnapshot(); assertEquals(Arrays.asList(1, 2, 4), inflight.stream().map(Buffer::getSize).collect(Collectors.toList())); inflight.forEach(Buffer::recycleBuffer); assertNextEvent(readView, barrierBuffer.getWrittenBytes(), CheckpointBarrier.class, true, 2, false, true); assertNextBuffer(readView, 1, true, 1, false, true); assertNextBuffer(readView, 2, true, 0, true, true); assertNextEvent(readView, eventBuffer.getWrittenBytes(), EndOfSuperstepEvent.class, false, 0, false, true); assertNextBuffer(readView, 4, false, 0, false, true); assertNoNextBuffer(readView); }
Example #24
Source File: PipelinedSubpartitionWithReadViewTest.java From flink with Apache License 2.0 | 5 votes |
private static void assertNextBufferOrEvent( ResultSubpartitionView readView, int expectedReadableBufferSize, boolean expectedIsBuffer, @Nullable Class<? extends AbstractEvent> expectedEventClass, boolean expectedIsDataAvailable, int expectedBuffersInBacklog, boolean expectedIsEventAvailable, boolean expectedRecycledAfterRecycle) throws IOException, InterruptedException { checkArgument(expectedEventClass == null || !expectedIsBuffer); ResultSubpartition.BufferAndBacklog bufferAndBacklog = readView.getNextBuffer(); assertNotNull(bufferAndBacklog); try { assertEquals("buffer size", expectedReadableBufferSize, bufferAndBacklog.buffer().readableBytes()); assertEquals("buffer or event", expectedIsBuffer, bufferAndBacklog.buffer().isBuffer()); if (expectedEventClass != null) { Assert.assertThat(EventSerializer .fromBuffer(bufferAndBacklog.buffer(), ClassLoader.getSystemClassLoader()), instanceOf(expectedEventClass)); } assertEquals("data available", expectedIsDataAvailable, bufferAndBacklog.isDataAvailable()); assertEquals("data available", expectedIsDataAvailable, readView.isAvailable(Integer.MAX_VALUE)); assertEquals("backlog", expectedBuffersInBacklog, bufferAndBacklog.buffersInBacklog()); assertEquals("event available", expectedIsEventAvailable, bufferAndBacklog.isEventAvailable()); assertEquals("event available", expectedIsEventAvailable, readView.isAvailable(0)); assertFalse("not recycled", bufferAndBacklog.buffer().isRecycled()); } finally { bufferAndBacklog.buffer().recycleBuffer(); } assertEquals("recycled", expectedRecycledAfterRecycle, bufferAndBacklog.buffer().isRecycled()); }
Example #25
Source File: TestInputChannel.java From flink with Apache License 2.0 | 5 votes |
TestInputChannel readEndOfPartitionEvent() { addBufferAndAvailability( () -> { setReleased(); return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), false, 0)); } ); return this; }
Example #26
Source File: IteratorWrappingTestSingleInputGate.java From flink with Apache License 2.0 | 5 votes |
private IteratorWrappingTestSingleInputGate<T> wrapIterator(MutableObjectIterator<T> iterator) throws IOException, InterruptedException { inputIterator = iterator; serializer = new SpanningRecordSerializer<T>(); // The input iterator can produce an infinite stream. That's why we have to serialize each // record on demand and cannot do it upfront. final BufferAndAvailabilityProvider answer = new BufferAndAvailabilityProvider() { private boolean hasData = inputIterator.next(reuse) != null; @Override public Optional<BufferAndAvailability> getBufferAvailability() throws IOException { if (hasData) { serializer.serializeRecord(reuse); BufferBuilder bufferBuilder = createBufferBuilder(bufferSize); BufferConsumer bufferConsumer = bufferBuilder.createBufferConsumer(); serializer.copyToBufferBuilder(bufferBuilder); hasData = inputIterator.next(reuse) != null; // Call getCurrentBuffer to ensure size is set return Optional.of(new BufferAndAvailability(bufferConsumer.build(), true, 0)); } else { inputChannel.setReleased(); return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), false, 0)); } } }; inputChannel.addBufferAndAvailability(answer); inputGate.setInputChannels(inputChannel); return this; }
Example #27
Source File: ReadOnlySlicedBufferTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testForwardsIsBuffer() throws IOException { assertEquals(buffer.isBuffer(), buffer.readOnlySlice().isBuffer()); assertEquals(buffer.isBuffer(), buffer.readOnlySlice(1, 2).isBuffer()); Buffer eventBuffer = EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE); assertEquals(eventBuffer.isBuffer(), eventBuffer.readOnlySlice().isBuffer()); assertEquals(eventBuffer.isBuffer(), eventBuffer.readOnlySlice(1, 2).isBuffer()); }
Example #28
Source File: RecordWriterTest.java From flink with Apache License 2.0 | 5 votes |
private static BufferOrEvent parseBuffer(BufferConsumer bufferConsumer, int targetChannel) throws IOException { Buffer buffer = buildSingleBuffer(bufferConsumer); if (buffer.isBuffer()) { return new BufferOrEvent(buffer, targetChannel); } else { // is event: AbstractEvent event = EventSerializer.fromBuffer(buffer, RecordWriterTest.class.getClassLoader()); buffer.recycleBuffer(); // the buffer is not needed anymore return new BufferOrEvent(event, targetChannel); } }
Example #29
Source File: RecordWriter.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public void broadcastEvent(AbstractEvent event) throws IOException { try (BufferConsumer eventBufferConsumer = EventSerializer.toBufferConsumer(event)) { for (int targetChannel = 0; targetChannel < numberOfChannels; targetChannel++) { tryFinishCurrentBufferBuilder(targetChannel); // Retain the buffer so that it can be recycled by each channel of targetPartition targetPartition.addBufferConsumer(eventBufferConsumer.copy(), targetChannel); } if (flushAlways) { flushAll(); } } }
Example #30
Source File: RecordWriterTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private static BufferOrEvent parseBuffer(BufferConsumer bufferConsumer, int targetChannel) throws IOException { Buffer buffer = buildSingleBuffer(bufferConsumer); if (buffer.isBuffer()) { return new BufferOrEvent(buffer, targetChannel); } else { // is event: AbstractEvent event = EventSerializer.fromBuffer(buffer, RecordWriterTest.class.getClassLoader()); buffer.recycleBuffer(); // the buffer is not needed anymore return new BufferOrEvent(event, targetChannel); } }