@ Override public Collection < SegmentMetadata > getEvictionCandidates ( long sequenceNumberCutoff , int maxCount ) { long adjustedCutoff = Math . min ( sequenceNumberCutoff , this . lastTruncatedSequenceNumber . get ( ) ) ; List < SegmentMetadata > candidates ; synchronized ( this . lock ) { candidates = this . metadataById . values ( ) . stream ( ) . filter ( m -> isEligibleForEviction ( m , adjustedCutoff ) ) . collect ( Collectors . toList ( ) ) ; } // If we have more candidates than were requested to return, then return only the ones that were not recently used. if ( candidates . size ( ) > maxCount ) { candidates . sort ( Comparator . comparingLong ( SegmentMetadata :: getLastUsed ) ) ; candidates = candidates . subList ( 0 , maxCount ) ; } return candidates ; }
region EvictableMetadata Implementation