Source:
private void setupInputChannels() { for (int i = 0; i < numInputChannels; i++) { final int channelIndex = i; final RecordSerializer<SerializationDelegate<Object>> recordSerializer = new SpanningRecordSerializer<SerializationDelegate<Object>>(); final SerializationDelegate<Object> delegate = (SerializationDelegate<Object>) (SerializationDelegate<?>) new SerializationDelegate<>(new StreamElementSerializer<T>(serializer)); inputQueues[channelIndex] = new ConcurrentLinkedQueue<>(); inputChannels[channelIndex] = new TestInputChannel(inputGate, i); final BufferAndAvailabilityProvider answer = () -> { ConcurrentLinkedQueue<InputValue<Object>> inputQueue = inputQueues[channelIndex]; InputValue<Object> input; Buffer.DataType nextType; synchronized (inputQueue) { input = inputQueue.poll(); nextType = !inputQueue.isEmpty() ? Buffer.DataType.DATA_BUFFER : Buffer.DataType.NONE; } if (input != null && input.isStreamEnd()) { inputChannels[channelIndex].setReleased(); return Optional.of(new BufferAndAvailability( EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE, false), nextType, 0)); } else if (input != null && input.isStreamRecord()) { Object inputElement = input.getStreamRecord(); delegate.setInstance(inputElement); recordSerializer.serializeRecord(delegate); BufferBuilder bufferBuilder = createBufferBuilder(bufferSize); BufferConsumer bufferConsumer = bufferBuilder.createBufferConsumer(); recordSerializer.copyToBufferBuilder(bufferBuilder); bufferBuilder.finish(); return Optional.of(new BufferAndAvailability(bufferConsumer.build(), nextType, 0)); } else if (input != null && input.isEvent()) { AbstractEvent event = input.getEvent(); if (event instanceof EndOfPartitionEvent) { inputChannels[channelIndex].setReleased(); } return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(event, false), nextType, 0)); } else { return Optional.empty(); } }; inputChannels[channelIndex].addBufferAndAvailability(answer); } inputGate.setInputChannels(inputChannels); }

Target:
private void setupInputChannels() { for (int i = 0; i < numInputChannels; i++) { final int channelIndex = i; final RecordSerializer<SerializationDelegate<Object>> recordSerializer = new SpanningRecordSerializer<SerializationDelegate<Object>>(); final SerializationDelegate<Object> delegate = (SerializationDelegate<Object>) (SerializationDelegate<?>) new SerializationDelegate<>(new StreamElementSerializer<T>(serializer)); inputQueues[channelIndex] = new ConcurrentLinkedQueue<>(); inputChannels[channelIndex] = new TestInputChannel(inputGate, i); final BufferAndAvailabilityProvider answer = () -> { ConcurrentLinkedQueue<InputValue<Object>> inputQueue = inputQueues[channelIndex]; InputValue<Object> input; Buffer.DataType nextType; synchronized (inputQueue) { input = inputQueue.poll(); nextType = !inputQueue.isEmpty() ? Buffer.DataType.DATA_BUFFER : Buffer.DataType.NONE; } if (input != null && input.isStreamEnd()) { inputChannels[channelIndex].setReleased(); return Optional.of(new BufferAndAvailability( EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE, false), nextType, 0, 0)); } else if (input != null && input.isStreamRecord()) { Object inputElement = input.getStreamRecord(); delegate.setInstance(inputElement); recordSerializer.serializeRecord(delegate); BufferBuilder bufferBuilder = createBufferBuilder(bufferSize); BufferConsumer bufferConsumer = bufferBuilder.createBufferConsumer(); recordSerializer.copyToBufferBuilder(bufferBuilder); bufferBuilder.finish(); return Optional.of(new BufferAndAvailability(bufferConsumer.build(), nextType, 0, 0)); } else if (input != null && input.isEvent()) { AbstractEvent event = input.getEvent(); if (event instanceof EndOfPartitionEvent) { inputChannels[channelIndex].setReleased(); } return Optional.of(new BufferAndAvailability( EventSerializer.toBuffer(event, false), nextType, 0, 0)); } else { return Optional.empty(); } }; inputChannels[channelIndex].addBufferAndAvailability(answer); } inputGate.setInputChannels(inputChannels); }