/** * Offers a value to this buffer. This value will at a later point be part of a buffered chunk, * released by a call to {@link #maintenance()} when the safe threshold for the chunk, which is determined * when the chunk is full or otherwise queued. */ public synchronized void offer( long value ) { chunk[chunkCursor++] = value; if ( chunkCursor == chunkSize ) { flush(); } }
/** * Closes this buffer, releasing all {@link #offer(long)} values into the {@link Consumer}. * * This class is typically not used in a scenario suitable for try-with-resource * and so having it implement AutoCloseable would be more annoying */ public synchronized void close() { flush(); while ( !chunks.isEmpty() ) { chunkConsumer.accept( chunks.poll().values ); } }
/** * Offers a value to this buffer. This value will at a later point be part of a buffered chunk, * released by a call to {@link #maintenance()} when the safe threshold for the chunk, which is determined * when the chunk is full or otherwise queued. */ public synchronized void offer( long value ) { chunk[chunkCursor++] = value; if ( chunkCursor == chunkSize ) { flush(); } }
/** * Closes this buffer, releasing all {@link #offer(long)} values into the {@link Consumer}. * * This class is typically not used in a scenario suitable for try-with-resource * and so having it implement AutoCloseable would be more annoying */ public synchronized void close() { flush(); while ( !chunks.isEmpty() ) { chunkConsumer.accept( chunks.poll().values ); } }