public void doAppend( KettleLoggingEvent event ) { if ( event.getMessage() instanceof LogMessage ) { lock.writeLock().lock(); try { buffer.add( new BufferLine( event ) ); while ( bufferSize > 0 && buffer.size() > bufferSize ) { buffer.remove( 0 ); } } finally { lock.writeLock().unlock(); } } }
/** * 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(); } }
/** * @return the number (sequence, 1..N) of the last log line. If no records are present in the buffer, 0 is returned. */ public int getLastBufferLineNr() { lock.readLock().lock(); try { if ( buffer.size() > 0 ) { return buffer.get( buffer.size() - 1 ).getNr(); } else { return 0; } } 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(); } }
/** * @param channelId channel IDs to grab * @param includeGeneral include general log lines * @param from * @param to * @return */ public List<KettleLoggingEvent> getLogBufferFromTo( List<String> channelId, boolean includeGeneral, int from, int to ) { lock.readLock().lock(); try { Stream<BufferLine> bufferStream = buffer.stream().filter( line -> line.getNr() > from && line.getNr() <= to ); if ( channelId != null ) { bufferStream = bufferStream.filter( line -> { String logChannelId = getLogChId( line ); return includeGeneral ? isGeneral( logChannelId ) || channelId.contains( logChannelId ) : channelId.contains( logChannelId ); } ); } return bufferStream.map( BufferLine::getEvent ).collect( Collectors.toList() ); } finally { lock.readLock().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(); } }