@Override public void finish() throws IOException { final Buffer buffer = EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE); // view reference accessible outside the lock, but assigned inside the locked scope final PipelinedSubpartitionView reader; synchronized (buffers) { if (isFinished || isReleased) { return; } buffers.add(buffer); reader = readView; updateStatistics(buffer); isFinished = true; } LOG.debug("Finished {}.", this); // Notify the listener outside of the synchronized block if (reader != null) { reader.notifyBuffersAvailable(1); } }
@Override public boolean add(Buffer buffer) throws IOException { checkNotNull(buffer); // view reference accessible outside the lock, but assigned inside the locked scope final PipelinedSubpartitionView reader; synchronized (buffers) { if (isFinished || isReleased) { return false; } // Add the buffer and update the stats buffers.add(buffer); reader = readView; updateStatistics(buffer); } // Notify the listener outside of the synchronized block if (reader != null) { reader.notifyBuffersAvailable(1); } return true; }
private boolean add(BufferConsumer bufferConsumer, boolean finish) { checkNotNull(bufferConsumer); final boolean notifyDataAvailable; synchronized (buffers) { if (isFinished || isReleased) { bufferConsumer.close(); return false; } // Add the bufferConsumer and update the stats buffers.add(bufferConsumer); updateStatistics(bufferConsumer); increaseBuffersInBacklog(bufferConsumer); notifyDataAvailable = shouldNotifyDataAvailable() || finish; isFinished |= finish; } if (notifyDataAvailable) { notifyDataAvailable(); } return true; }
private boolean add(BufferConsumer bufferConsumer, boolean finish) { checkNotNull(bufferConsumer); final boolean notifyDataAvailable; synchronized (buffers) { if (isFinished || isReleased) { bufferConsumer.close(); return false; } // Add the bufferConsumer and update the stats buffers.add(bufferConsumer); updateStatistics(bufferConsumer); increaseBuffersInBacklog(bufferConsumer); notifyDataAvailable = shouldNotifyDataAvailable() || finish; isFinished |= finish; } if (notifyDataAvailable) { notifyDataAvailable(); } return true; }
private boolean add(BufferConsumer bufferConsumer, boolean finish) { checkNotNull(bufferConsumer); synchronized (buffers) { if (isFinished || isReleased) { bufferConsumer.close(); return false; } // Add the bufferConsumer and update the stats buffers.add(bufferConsumer); updateStatistics(bufferConsumer); increaseBuffersInBacklog(bufferConsumer); if (finish) { isFinished = true; flush(); } else { maybeNotifyDataAvailable(); } } return true; }