org.apache.flink.runtime.io.network.api.serialization.SpanningRecordSerializer Java Examples
The following examples show how to use
org.apache.flink.runtime.io.network.api.serialization.SpanningRecordSerializer.
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: RecordWriter.java From flink with Apache License 2.0 | 6 votes |
RecordWriter(ResultPartitionWriter writer, long timeout, String taskName) { this.targetPartition = writer; this.numberOfChannels = writer.getNumberOfSubpartitions(); this.serializer = new SpanningRecordSerializer<T>(); checkArgument(timeout >= -1); this.flushAlways = (timeout == 0); if (timeout == -1 || timeout == 0) { outputFlusher = null; } else { String threadName = taskName == null ? DEFAULT_OUTPUT_FLUSH_THREAD_NAME : DEFAULT_OUTPUT_FLUSH_THREAD_NAME + " for " + taskName; outputFlusher = new OutputFlusher(threadName, timeout); outputFlusher.start(); } }
Example #2
Source File: RecordWriter.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public RecordWriter( ResultPartitionWriter writer, ChannelSelector<T> channelSelector, long timeout, String taskName) { this.targetPartition = writer; this.channelSelector = channelSelector; this.numberOfChannels = writer.getNumberOfSubpartitions(); this.channelSelector.setup(numberOfChannels); this.serializer = new SpanningRecordSerializer<T>(); this.bufferBuilders = new Optional[numberOfChannels]; this.broadcastChannels = new int[numberOfChannels]; for (int i = 0; i < numberOfChannels; i++) { broadcastChannels[i] = i; bufferBuilders[i] = Optional.empty(); } checkArgument(timeout >= -1); this.flushAlways = (timeout == 0); if (timeout == -1 || timeout == 0) { outputFlusher = Optional.empty(); } else { String threadName = taskName == null ? DEFAULT_OUTPUT_FLUSH_THREAD_NAME : DEFAULT_OUTPUT_FLUSH_THREAD_NAME + " for " + taskName; outputFlusher = Optional.of(new OutputFlusher(threadName, timeout)); outputFlusher.get().start(); } }
Example #3
Source File: IteratorWrappingTestSingleInputGate.java From Flink-CEPplus 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 #4
Source File: RecordWriter.java From flink with Apache License 2.0 | 5 votes |
RecordWriter(ResultPartitionWriter writer, ChannelSelector<T> channelSelector, long timeout, String taskName) { this.targetPartition = writer; this.channelSelector = channelSelector; this.numberOfChannels = writer.getNumberOfSubpartitions(); this.channelSelector.setup(numberOfChannels); this.serializer = new SpanningRecordSerializer<T>(); this.bufferBuilders = new Optional[numberOfChannels]; this.broadcastChannels = new int[numberOfChannels]; for (int i = 0; i < numberOfChannels; i++) { broadcastChannels[i] = i; bufferBuilders[i] = Optional.empty(); } checkArgument(timeout >= -1); this.flushAlways = (timeout == 0); if (timeout == -1 || timeout == 0) { outputFlusher = Optional.empty(); } else { String threadName = taskName == null ? DEFAULT_OUTPUT_FLUSH_THREAD_NAME : DEFAULT_OUTPUT_FLUSH_THREAD_NAME + " for " + taskName; outputFlusher = Optional.of(new OutputFlusher(threadName, timeout)); outputFlusher.get().start(); } }
Example #5
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 #6
Source File: StreamTaskNetworkInputTest.java From flink with Apache License 2.0 | 5 votes |
private void serializeRecord(long value, BufferBuilder bufferBuilder) throws IOException { RecordSerializer<SerializationDelegate<StreamElement>> serializer = new SpanningRecordSerializer<>(); SerializationDelegate<StreamElement> serializationDelegate = new SerializationDelegate<>( new StreamElementSerializer<>(LongSerializer.INSTANCE)); serializationDelegate.setInstance(new StreamRecord<>(value)); serializer.serializeRecord(serializationDelegate); assertFalse(serializer.copyToBufferBuilder(bufferBuilder).isFullBuffer()); }
Example #7
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 #8
Source File: StreamTaskNetworkInputTest.java From flink with Apache License 2.0 | 5 votes |
private void serializeRecord(long value, BufferBuilder bufferBuilder) throws IOException { RecordSerializer<SerializationDelegate<StreamElement>> serializer = new SpanningRecordSerializer<>(); SerializationDelegate<StreamElement> serializationDelegate = new SerializationDelegate<>( new StreamElementSerializer<>(LongSerializer.INSTANCE)); serializationDelegate.setInstance(new StreamRecord<>(value)); serializer.serializeRecord(serializationDelegate); assertFalse(serializer.copyToBufferBuilder(bufferBuilder).isFullBuffer()); }
Example #9
Source File: StreamTestSingleInputGate.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void setupInputChannels() throws IOException, InterruptedException { 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<StreamElement>(new StreamElementSerializer<T>(serializer)); inputQueues[channelIndex] = new ConcurrentLinkedQueue<InputValue<Object>>(); inputChannels[channelIndex] = new TestInputChannel(inputGate, i); final BufferAndAvailabilityProvider answer = () -> { ConcurrentLinkedQueue<InputValue<Object>> inputQueue = inputQueues[channelIndex]; InputValue<Object> input; boolean moreAvailable; synchronized (inputQueue) { input = inputQueue.poll(); moreAvailable = !inputQueue.isEmpty(); } if (input != null && input.isStreamEnd()) { inputChannels[channelIndex].setReleased(); return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), moreAvailable, 0)); } else if (input != null && input.isStreamRecord()) { Object inputElement = input.getStreamRecord(); delegate.setInstance(inputElement); recordSerializer.serializeRecord(delegate); BufferBuilder bufferBuilder = createBufferBuilder(bufferSize); recordSerializer.copyToBufferBuilder(bufferBuilder); bufferBuilder.finish(); // Call getCurrentBuffer to ensure size is set return Optional.of(new BufferAndAvailability(buildSingleBuffer(bufferBuilder), moreAvailable, 0)); } else if (input != null && input.isEvent()) { AbstractEvent event = input.getEvent(); return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(event), moreAvailable, 0)); } else { return Optional.empty(); } }; inputChannels[channelIndex].addBufferAndAvailability(answer); inputGate.setInputChannel(new IntermediateResultPartitionID(), inputChannels[channelIndex]); } }
Example #10
Source File: StreamTestSingleInputGate.java From flink with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void setupInputChannels() throws IOException, InterruptedException { 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<StreamElement>(new StreamElementSerializer<T>(serializer)); inputQueues[channelIndex] = new ConcurrentLinkedQueue<InputValue<Object>>(); inputChannels[channelIndex] = new TestInputChannel(inputGate, i); final BufferAndAvailabilityProvider answer = () -> { ConcurrentLinkedQueue<InputValue<Object>> inputQueue = inputQueues[channelIndex]; InputValue<Object> input; boolean moreAvailable; synchronized (inputQueue) { input = inputQueue.poll(); moreAvailable = !inputQueue.isEmpty(); } if (input != null && input.isStreamEnd()) { inputChannels[channelIndex].setReleased(); return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), moreAvailable, 0)); } else if (input != null && input.isStreamRecord()) { Object inputElement = input.getStreamRecord(); delegate.setInstance(inputElement); recordSerializer.serializeRecord(delegate); BufferBuilder bufferBuilder = createBufferBuilder(bufferSize); recordSerializer.copyToBufferBuilder(bufferBuilder); bufferBuilder.finish(); // Call getCurrentBuffer to ensure size is set return Optional.of(new BufferAndAvailability(buildSingleBuffer(bufferBuilder), moreAvailable, 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), moreAvailable, 0)); } else { return Optional.empty(); } }; inputChannels[channelIndex].addBufferAndAvailability(answer); inputGate.setInputChannel(new IntermediateResultPartitionID(), inputChannels[channelIndex]); } }
Example #11
Source File: StreamTestSingleInputGate.java From flink with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") 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; boolean moreAvailable; synchronized (inputQueue) { input = inputQueue.poll(); moreAvailable = !inputQueue.isEmpty(); } if (input != null && input.isStreamEnd()) { inputChannels[channelIndex].setReleased(); return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), moreAvailable, 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(); // Call getCurrentBuffer to ensure size is set return Optional.of(new BufferAndAvailability(bufferConsumer.build(), moreAvailable, 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), moreAvailable, 0)); } else { return Optional.empty(); } }; inputChannels[channelIndex].addBufferAndAvailability(answer); } inputGate.setInputChannels(inputChannels); }