/** * Add the given stream element queue entry to the operator's stream element queue. This * operation blocks until the element has been added. * * <p>For that it tries to put the element into the queue and if not successful then it waits on * the checkpointing lock. The checkpointing lock is also used by the {@link Emitter} to output * elements. The emitter is also responsible for notifying this method if the queue has capacity * left again, by calling notifyAll on the checkpointing lock. * * @param streamElementQueueEntry to add to the operator's queue * @param <T> Type of the stream element queue entry's result * @throws InterruptedException if the current thread has been interrupted */ private <T> void addAsyncBufferEntry(StreamElementQueueEntry<T> streamElementQueueEntry) throws InterruptedException { assert(Thread.holdsLock(checkpointingLock)); pendingStreamElementQueueEntry = streamElementQueueEntry; while (!queue.tryPut(streamElementQueueEntry)) { // we wait for the emitter to notify us if the queue has space left again checkpointingLock.wait(); } pendingStreamElementQueueEntry = null; }
@Test public void testPut() throws InterruptedException { OperatorActions operatorActions = mock(OperatorActions.class); StreamElementQueue queue = createStreamElementQueue(2, operatorActions); final Watermark watermark = new Watermark(0L); final StreamRecord<Integer> streamRecord = new StreamRecord<>(42, 1L); final Watermark nextWatermark = new Watermark(2L); final WatermarkQueueEntry watermarkQueueEntry = new WatermarkQueueEntry(watermark); final StreamRecordQueueEntry<Integer> streamRecordQueueEntry = new StreamRecordQueueEntry<>(streamRecord); queue.put(watermarkQueueEntry); queue.put(streamRecordQueueEntry); Assert.assertEquals(2, queue.size()); Assert.assertFalse(queue.tryPut(new WatermarkQueueEntry(nextWatermark))); Collection<StreamElementQueueEntry<?>> actualValues = queue.values(); List<StreamElementQueueEntry<?>> expectedValues = Arrays.asList(watermarkQueueEntry, streamRecordQueueEntry); Assert.assertEquals(expectedValues, actualValues); verify(operatorActions, never()).failOperator(any(Exception.class)); }
/** * Add the given stream element queue entry to the operator's stream element queue. This * operation blocks until the element has been added. * * <p>For that it tries to put the element into the queue and if not successful then it waits on * the checkpointing lock. The checkpointing lock is also used by the {@link Emitter} to output * elements. The emitter is also responsible for notifying this method if the queue has capacity * left again, by calling notifyAll on the checkpointing lock. * * @param streamElementQueueEntry to add to the operator's queue * @param <T> Type of the stream element queue entry's result * @throws InterruptedException if the current thread has been interrupted */ private <T> void addAsyncBufferEntry(StreamElementQueueEntry<T> streamElementQueueEntry) throws InterruptedException { assert(Thread.holdsLock(checkpointingLock)); pendingStreamElementQueueEntry = streamElementQueueEntry; while (!queue.tryPut(streamElementQueueEntry)) { // we wait for the emitter to notify us if the queue has space left again checkpointingLock.wait(); } pendingStreamElementQueueEntry = null; }
/** * Add the given stream element queue entry to the operator's stream element queue. This * operation blocks until the element has been added. * * <p>For that it tries to put the element into the queue and if not successful then it waits on * the checkpointing lock. The checkpointing lock is also used by the {@link Emitter} to output * elements. The emitter is also responsible for notifying this method if the queue has capacity * left again, by calling notifyAll on the checkpointing lock. * * @param streamElementQueueEntry to add to the operator's queue * @param <T> Type of the stream element queue entry's result * @throws InterruptedException if the current thread has been interrupted */ private <T> void addAsyncBufferEntry(StreamElementQueueEntry<T> streamElementQueueEntry) throws InterruptedException { assert(Thread.holdsLock(checkpointingLock)); pendingStreamElementQueueEntry = streamElementQueueEntry; while (!queue.tryPut(streamElementQueueEntry)) { // we wait for the emitter to notify us if the queue has space left again checkpointingLock.wait(); } pendingStreamElementQueueEntry = null; }
/** * Add the given stream element queue entry to the operator's stream element queue. This * operation blocks until the element has been added. * * <p>For that it tries to put the element into the queue and if not successful then it waits on * the checkpointing lock. The checkpointing lock is also used by the {@link Emitter} to output * elements. The emitter is also responsible for notifying this method if the queue has capacity * left again, by calling notifyAll on the checkpointing lock. * * @param streamElementQueueEntry to add to the operator's queue * @param <T> Type of the stream element queue entry's result * @throws InterruptedException if the current thread has been interrupted */ private <T> void addAsyncBufferEntry(StreamElementQueueEntry<T> streamElementQueueEntry) throws InterruptedException { assert(Thread.holdsLock(checkpointingLock)); pendingStreamElementQueueEntry = streamElementQueueEntry; while (!queue.tryPut(streamElementQueueEntry)) { // we wait for the emitter to notify us if the queue has space left again checkpointingLock.wait(); } pendingStreamElementQueueEntry = null; }