@Override public void notifyBuffersAvailable(long numBuffers) throws IOException { availabilityListener.notifyBuffersAvailable(numBuffers); }
/** * This is the call back method for the spill writer. If a spill is still * in progress when this view is created we wait until this method is called * before we notify the availability listener. */ @Override public void onNotification() { isSpillInProgress = false; availabilityListener.notifyBuffersAvailable(numberOfSpilledBuffers); LOG.debug("Finished spilling. Notified about {} available buffers.", numberOfSpilledBuffers); }
@Override public Buffer getNextBuffer() throws IOException, InterruptedException { synchronized (buffers) { if (isReleased.get()) { return null; } else if (nextBuffer != null) { Buffer current = nextBuffer; nextBuffer = buffers.poll(); if (nextBuffer != null) { listener.notifyBuffersAvailable(1); } return current; } } // else: spilled SpilledSubpartitionView spilled = spilledView; if (spilled != null) { return spilled.getNextBuffer(); } else { throw new IllegalStateException("No in-memory buffers available, but also nothing spilled."); } }
SpillableSubpartitionView( SpillableSubpartition parent, ArrayDeque<Buffer> buffers, IOManager ioManager, int memorySegmentSize, BufferAvailabilityListener listener) { this.parent = checkNotNull(parent); this.buffers = checkNotNull(buffers); this.ioManager = checkNotNull(ioManager); this.memorySegmentSize = memorySegmentSize; this.listener = checkNotNull(listener); synchronized (buffers) { numBuffers = buffers.size(); nextBuffer = buffers.poll(); } if (nextBuffer != null) { listener.notifyBuffersAvailable(1); } }
SpilledSubpartitionView( ResultSubpartition parent, int memorySegmentSize, BufferFileWriter spillWriter, long numberOfSpilledBuffers, BufferAvailabilityListener availabilityListener) throws IOException { this.parent = checkNotNull(parent); this.bufferPool = new SpillReadBufferPool(2, memorySegmentSize); this.spillWriter = checkNotNull(spillWriter); this.fileReader = new SynchronousBufferFileReader(spillWriter.getChannelID(), false); checkArgument(numberOfSpilledBuffers >= 0); this.numberOfSpilledBuffers = numberOfSpilledBuffers; this.availabilityListener = checkNotNull(availabilityListener); // Check whether async spilling is still in progress. If not, this returns // false and we can notify our availability listener about all available buffers. // Otherwise, we notify only when the spill writer callback happens. if (!spillWriter.registerAllRequestsProcessedListener(this)) { isSpillInProgress = false; availabilityListener.notifyBuffersAvailable(numberOfSpilledBuffers); LOG.debug("No spilling in progress. Notified about {} available buffers.", numberOfSpilledBuffers); } else { LOG.debug("Spilling in progress. Waiting with notification about {} available buffers.", numberOfSpilledBuffers); } }