public void update ( long value , long timestamp ) { lockForRegularUsage ( ) ; try { final double priority = weight ( timestamp - startTime ) / random ( ) ; final long newCount = count . incrementAndGet ( ) ; if ( newCount <= reservoirSize ) { values . put ( priority , value ) ; } else { Double first = values . firstKey ( ) ; if ( first < priority ) { if ( values . putIfAbsent ( priority , value ) == null ) { // ensure we always remove an item while ( values . remove ( first ) == null ) { first = values . firstKey ( ) ; } } } } } finally { unlockForRegularUsage ( ) ; } final long now = System . nanoTime ( ) ; final long next = nextScaleTime . get ( ) ; if ( now >= next ) { rescale ( now , next ) ; } }
Adds an old value with a fixed timestamp to the sample .