org.jwall.web.audit
Class AuditEventDispatcher

java.lang.Object
  extended by java.lang.Thread
      extended by org.jwall.web.audit.AuditEventDispatcher
All Implemented Interfaces:
Runnable

public class AuditEventDispatcher
extends Thread

This class implements a dispatcher for audit-events. Classes implementing the AuditEventListener interface can register to an instance of this class for being notified upon arrival of new events.

An instance of this dispatcher class can be created by using a given AuditEventReader implementation in which case the dispatcher will continuously read events from that reader and dispatch these to all listeners

Another use is to create an empty or non-connected dispatcher without a given audit reader and externally inject events using the enqueueEvent() method. This method will add the event(s) to an internal queue and dispatch them to the listeners in a separate thread.

A dispatcher instance can either be persistent or non-peristent. In the persistent mode it will read all events from the given reader and wait for new events to arrive if the reader reached the end of file/input. In non-persistent mode the dispatcher will terminate once no more events can be read from the input-reader.

Author:
Christian Bockermann <chris@jwall.org>

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static int READER_WAITING_TIME
          The amount of milliseconds the dispatcher waits between polls when waiting for new events in persistent mode.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AuditEventDispatcher()
          This constructor creates a new instance which does externally receive events from other creators and dispatches them to registered listeners.
AuditEventDispatcher(AuditEventReader src)
          This constructor creates a new dispatcher which reads events from the given AuditEventReader.
 
Method Summary
 void add(AuditEvent evt)
          Deprecated. The same functionality is now provided by enqueueEvent(AuditEvent).
 void addAuditEventListener(AuditEventListener listener)
          Register another listener which is to be notified if another event has been created.
 void close()
          Closes this dispatcher by closing the underlying reader (if any) and terminating the dispatch thread.
 void enqueueEvent(AuditEvent evt)
          This method enqueues the given event into the list of events to be dispatched to the registered listeners.
 Collection<AuditEventListener> getAuditEventListeners()
          Returns the collection of currently registered listeners.
 int getNumberOfEvents()
          Returns the number of events that have been dispatched by this instance.
 boolean isPersistent()
          Signals whether the dispatcher is running in persistent mode.
 void removeAuditEventListener(AuditEventListener listener)
          Remove the given listener from the list of listeners.
 void removeAuditEventListeners()
          This method will clear the list of all listeners currently registered at this instance.
 void run()
          This is a loop that fetches events from the AuditEventSource associated with this dispatcher and notifies the registered listeners.
 void setPersistent(boolean p)
          This methods can be used to set the dispatcher into persistent or non-persistent mode.
 
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
 

Field Detail

READER_WAITING_TIME

public static final int READER_WAITING_TIME
The amount of milliseconds the dispatcher waits between polls when waiting for new events in persistent mode. This does not have any effect in non-persistent mode.

See Also:
Constant Field Values
Constructor Detail

AuditEventDispatcher

public AuditEventDispatcher()
This constructor creates a new instance which does externally receive events from other creators and dispatches them to registered listeners. The events are not stored, i.e. if events arrive and no listener is registered, they will simply be ignored.


AuditEventDispatcher

public AuditEventDispatcher(AuditEventReader src)
This constructor creates a new dispatcher which reads events from the given AuditEventReader. To make the dispatcher actually read events, the instance has to be started using the start() method inherited by the Thread-superclass.

Parameters:
src - The AuditEventReader used for reading events.
Method Detail

isPersistent

public boolean isPersistent()
Signals whether the dispatcher is running in persistent mode.

Returns:
true if working persistently.

setPersistent

public void setPersistent(boolean p)
This methods can be used to set the dispatcher into persistent or non-persistent mode.

Parameters:
p - A boolean flag indicating persistent (true) or non-persistent (false) mode.

add

public void add(AuditEvent evt)
Deprecated. The same functionality is now provided by enqueueEvent(AuditEvent).

This method adds the event to the dispatcher which will immediately dispatch it to all registered listeners.

Parameters:
evt - The event to be dispatched.

enqueueEvent

public void enqueueEvent(AuditEvent evt)
This method enqueues the given event into the list of events to be dispatched to the registered listeners. If this instance is reading events from a given AuditEventReader, then no internal buffer does exist and the event is immediately dispatched to the set of listeners currently registered.

Parameters:
evt - The event to be dispatched.

addAuditEventListener

public void addAuditEventListener(AuditEventListener listener)
Register another listener which is to be notified if another event has been created.

Parameters:
listener -

removeAuditEventListener

public void removeAuditEventListener(AuditEventListener listener)
Remove the given listener from the list of listeners. This method simply does nothing, if the given listener is not registered.

Parameters:
listener -

removeAuditEventListeners

public void removeAuditEventListeners()
This method will clear the list of all listeners currently registered at this instance.


getAuditEventListeners

public Collection<AuditEventListener> getAuditEventListeners()
Returns the collection of currently registered listeners.

Returns:
The set of listeners.

run

public void run()
This is a loop that fetches events from the AuditEventSource associated with this dispatcher and notifies the registered listeners.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

getNumberOfEvents

public int getNumberOfEvents()
Returns the number of events that have been dispatched by this instance.

Returns:
The number of dispatched events since startup.

close

public void close()
           throws IOException
Closes this dispatcher by closing the underlying reader (if any) and terminating the dispatch thread.

Throws:
IOException - In case the reader could not be closed without error. The dispatch thread is terminated in any case.


Copyright © 2012 jwall.org. All Rights Reserved.