@ SuppressWarnings ( "unchecked" ) public void set ( long sequenceId , T item ) { final E rbItem = convertToRingbufferFormat ( item ) ; // first we write the dataItem in the ring. ringbuffer . set ( sequenceId , rbItem ) ; if ( sequenceId > tailSequence ( ) ) { ringbuffer . setTailSequence ( sequenceId ) ; if ( ringbuffer . size ( ) > ringbuffer . getCapacity ( ) ) { ringbuffer . setHeadSequence ( ringbuffer . tailSequence ( ) - ringbuffer . getCapacity ( ) + 1 ) ; } } if ( sequenceId < headSequence ( ) ) { ringbuffer . setHeadSequence ( sequenceId ) ; } // and then we optionally write the expiration. if ( expirationPolicy != null ) { expirationPolicy . setExpirationAt ( sequenceId ) ; } }
Sets the item at the given sequence ID and updates the expiration time if TTL is configured . Unlike other methods for adding items into the ring buffer does not attempt to store the item in the data store . This method expands the ring buffer tail and head sequence to accommodate for the sequence . This means that it will move the head or tail sequence to the target sequence if the target sequence is less than the head sequence or greater than the tail sequence .