public boolean add ( T entry ) { assert entry != null ; if ( ! addEntries . get ( ) ) return false ; try { producerLock . lock ( ) ; long position = cursor . claim ( ) ; // blocks; if this fails, we will not have successfully claimed and nothing to do ... int index = ( int ) ( position & mask ) ; buffer [ index ] = entry ; return cursor . publish ( position ) ; } finally { producerLock . unlock ( ) ; } }
Add to this buffer a single entry . This method blocks if there is no room in the ring buffer providing back pressure on the caller in such cases . Note that if this method blocks for any length of time that means at least one consumer has yet to process all of the entries that are currently in the ring buffer . In such cases consider whether a larger ring buffer is warranted .