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:
Runnable, EventListener<AuditEvent>, AuditEventListener, AuditEventWriter

public class BufferedAuditEventWriter
extends Thread
implements AuditEventWriter, AuditEventListener

This class implements a simple persistency thread. It is created by specifying an AuditEventWriter implementation used for writing the events to disk. Upon startup, it waits for new events to arrive and writes them to disk asynchronously.

Author:
Christian Bockermann <chris@jwall.org>

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, 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(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.
 void eventsArrived(Collection<AuditEvent> events)
          This method is called for notifying the listener of arrival of several events in a block.
 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
equals, 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 Runnable
Overrides:
run in class 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(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 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:
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 #notify(), thus a listener might wait for packets to arrive.

Specified by:
eventArrived in interface EventListener<AuditEvent>
Specified by:
eventArrived in interface AuditEventListener
Parameters:
evt - The event which arrived.

eventsArrived

public void eventsArrived(Collection<AuditEvent> events)
Description copied from interface: AuditEventListener
This method is called for notifying the listener of arrival of several events in a block. Usually, this method is implemented by calling AuditEventListener.eventArrived(AuditEvent) for each of the given events, but may be handled in a more efficient way by implementations capable of processing blocks of events.

Specified by:
eventsArrived in interface AuditEventListener
Parameters:
events - The block of events arrived.


Copyright © 2012 jwall.org. All Rights Reserved.