org.jwall.web.audit.io
Class BufferedAuditEventWriter

java.lang.Object
  extended by java.lang.Thread
      extended by org.jwall.web.audit.io.BufferedAuditEventWriter
All Implemented Interfaces:
java.lang.Runnable, AuditEventListener, AuditEventWriter

public class BufferedAuditEventWriter
extends java.lang.Thread
implements AuditEventWriter, AuditEventListener

Author:
Christian Bockermann <chris@jwall.org>

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BufferedAuditEventWriter(AuditEventWriter wr)
          This creates a new buffered event-writer that uses the given event-writer implementation to write audit-events to disk.
 
Method Summary
 void add(AuditEvent evt)
          Add a new event to the list of events that need to be written to disk.
 void addAll(java.util.Collection<AuditEvent> evts)
          This method can be used to add a collection of events to the queue.
 void close()
          This method sets the finish-signal for this writer instance.
 void eventArrived(AuditEvent evt)
          This method is called when a new event arrives at the listener.
 boolean hasEventsPending()
          This method can be used to check if any events are pending to be written to disk by the underlying writer.
 void run()
          This method loops until the finished-method has been called.
 void writeEvent(AuditEvent evt)
          This method simply enqueue the event evt to the list of events waiting to be written to disk.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BufferedAuditEventWriter

public BufferedAuditEventWriter(AuditEventWriter wr)
This creates a new buffered event-writer that uses the given event-writer implementation to write audit-events to disk.

Parameters:
wr - An instance that implements the AuditEventWriter interface.
Method Detail

run

public void run()
This method loops until the finished-method has been called. It checks for new events and writes them to disk.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
See Also:
Thread.run()

add

public void add(AuditEvent evt)
Add a new event to the list of events that need to be written to disk. Unless the writer is in finished-state, this will enqueue the event to the end of the list.
NOTE: The internal queue-length might grow to a size of Integer.MAX_VALUE events. If this maximum size is reached, a call to this method might block.

Parameters:
evt - The event to be written.

addAll

public void addAll(java.util.Collection<AuditEvent> evts)
This method can be used to add a collection of events to the queue. As with the add(AuditEvent evt)-method this might block if the maximum size of the internal queue is reached.

Parameters:
evts - A collection of events that are to be written.

close

public void close()
This method sets the finish-signal for this writer instance. After calling this method, new events will not be accepted and the thread finishes after having written all currently pending events to disk.


hasEventsPending

public boolean hasEventsPending()
This method can be used to check if any events are pending to be written to disk by the underlying writer.

Returns:
true, iff the event-queue is not empty.

writeEvent

public void writeEvent(AuditEvent evt)
                throws java.io.IOException
This method simply enqueue the event evt to the list of events waiting to be written to disk.

Specified by:
writeEvent in interface AuditEventWriter
Throws:
java.io.IOException

eventArrived

public void eventArrived(AuditEvent evt)
Description copied from interface: AuditEventListener
This method is called when a new event arrives at the listener. The Listener should be threaded and response-time to this method should be as small as possible. After the dispatcher calls this method each listener gets a call to notiy(), thus a listener might wait for packets to arrive.

Specified by:
eventArrived in interface AuditEventListener