/** * Was used in a pair with {@link #removeBufferLines(List)}. * * @deprecated in favor of {@link #removeBufferLinesBefore(long)}. */ @Deprecated public List<BufferLine> getBufferLinesBefore( long minTimeBoundary ) { lock.readLock().lock(); try { return buffer.stream().filter( line -> line.getEvent().timeStamp < minTimeBoundary ) .collect( Collectors.toList() ); } finally { lock.readLock().unlock(); } }
public void removeBufferLinesBefore( long minTimeBoundary ) { // Using HashSet even though BufferLine does not implement hashcode and equals, // we just need to remove the exact objects we have found and put in the set. Set<BufferLine> linesToRemove = new HashSet<>(); lock.writeLock().lock(); try { for ( BufferLine bufferLine : buffer ) { if ( bufferLine.getEvent().timeStamp < minTimeBoundary ) { linesToRemove.add( bufferLine ); } else { break; } } // removeAll should run fast against a HashSet, // since ArrayList.batchRemove check for each element of a collection given if it is in the ArrayList. // Thus, removeAll should run in a linear time. buffer.removeAll( linesToRemove ); } finally { lock.writeLock().unlock(); } }
/** * It looks like this method is not used in the project. */ @Deprecated public String dump() { StringBuilder buf = new StringBuilder( 50000 ); lock.readLock().lock(); try { buffer.forEach( line -> { LogMessage message = (LogMessage) line.getEvent().getMessage(); buf.append( message.getLogChannelId() ).append( "\t" ) .append( message.getSubject() ).append( "\n" ); } ); return buf.toString(); } finally { lock.readLock().unlock(); } }
private static String getLogChId( BufferLine bufferLine ) { return ( (LogMessage) bufferLine.getEvent().getMessage() ).getLogChannelId(); } }