com.neeve.trace
Class TraceHistoryHandler

java.lang.Object
  extended by java.util.logging.Handler
      extended by com.neeve.trace.TraceHistoryHandler

public final class TraceHistoryHandler
extends Handler

Implements a 'history' handler.

A history handler is as an intermediary trace handler that forwards trace to downstream handlers while also maintaining a history of the trace. Trace log records are only forwarded to downstream handlers if they pass any installed filters and level checks.


Method Summary
 void close()
          Implementation of Handler.close() This method closes the downstream handler.
static TraceHistoryHandler create(Handler handler, int maxRecords)
          Create a new trace history handler
 void flush()
          Implementation of Handler.flush() This method flushes the downstream handler.
 Object getHistoryLock()
          Get the history lock object.
 Iterator<LogRecord> iterator()
          Create an iterator to traverse the history records
 void publish(LogRecord record)
          Implementation of Handler.publish(java.util.logging.LogRecord) This method stores the supplied log record into the history buffer and then publishes the record to the downstream handler.
 
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static TraceHistoryHandler create(Handler handler,
                                         int maxRecords)
Create a new trace history handler

Parameters:
handler - The downstream handler to forward log records to. This parameter can be null in which case published records are not forwarded downstream.
maxRecords - The maximum size, in trace records, of the history buffer.

publish

public final void publish(LogRecord record)
Implementation of Handler.publish(java.util.logging.LogRecord)

This method stores the supplied log record into the history buffer and then publishes the record to the downstream handler. Log records are only recorded in the history buffer if it passes any installed filters and level checks.

Specified by:
publish in class Handler

flush

public final void flush()
Implementation of Handler.flush()

This method flushes the downstream handler.

Specified by:
flush in class Handler

close

public final void close()
Implementation of Handler.close()

This method closes the downstream handler.

Specified by:
close in class Handler

getHistoryLock

public final Object getHistoryLock()
Get the history lock object.

This method returns the object used to protect against concurrent modification of the history buffer by multiple threads. The user should lock the object returned by this method while traversing the trace history.


iterator

public final Iterator<LogRecord> iterator()
Create an iterator to traverse the history records

Threading:
The caller should lock the object returned by getHistoryLock() while traversing the list to prevent concurrent modification by other threads during the traversal

All trace generated while the user is traversing the history buffer is ignored. To detect this, the handler invoked hasNext() on the iterator returned to the caller. If it returns true, the published trace is not recorded. Therefore, it is mandatory that the caller walk through the entire history buffer using an iterator returned from this method



Copyright © 2016 Neeve Research, LLC. All Rights Reserved.