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.
Thread.State, Thread.UncaughtExceptionHandler| Modifier and Type | Field and Description |
|---|---|
static int |
READER_WAITING_TIME
The amount of milliseconds the dispatcher waits between polls when waiting for new events
in persistent mode.
|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
activeCount, checkAccess, clone, 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, yieldpublic static final int READER_WAITING_TIME
public AuditEventDispatcher()
public AuditEventDispatcher(AuditEventReader src)
start() method inherited by the
Thread-superclass.src - The AuditEventReader used for reading events.public boolean isPersistent()
true if working persistently.public void setPersistent(boolean p)
p - A boolean flag indicating persistent (true) or non-persistent (false) mode.public void add(AuditEvent evt)
enqueueEvent(AuditEvent).evt - The event to be dispatched.public void enqueueEvent(AuditEvent evt)
evt - The event to be dispatched.public void addAuditEventListener(AuditEventListener listener)
listener - public void removeAuditEventListener(AuditEventListener listener)
listener - public void removeAuditEventListeners()
public Collection<AuditEventListener> getAuditEventListeners()
public void run()
public int getNumberOfEvents()
public void close()
throws IOException
IOException - In case the reader could not be closed without error. The
dispatch thread is terminated in any case.Copyright © 2015 jwall.org. All Rights Reserved.