org.jwall.web.audit
Class AuditEventQueue

java.lang.Object
  extended by org.jwall.web.audit.AuditEventQueue
All Implemented Interfaces:
AuditEventListener, AuditEventReader, AuditEventSource

public class AuditEventQueue
extends java.lang.Object
implements AuditEventSource, AuditEventListener, AuditEventReader

A simple queue which holds some audit-events. The events are lined up in first-come-first-serve order. Accessing events may result in blocking if the queue is empty. See the methods comment for details.

Author:
Christian Bockermann <chris@jwall.org>

Constructor Summary
AuditEventQueue()
           
AuditEventQueue(java.util.Collection<AuditEvent> evts)
           
 
Method Summary
 long bytesAvailable()
           
 long bytesRead()
           
 void close()
           
 void eventArrived(AuditEvent evt)
          This method will add the event evt to the queue.
 boolean hasNext()
          This method returns true, iff the queue is non-empty.
 AuditEvent nextEvent()
          This method will return the head of the queue, i.e. the events that has been in the queue for the longest term.
 AuditEvent readNext()
          This method will return the next event (head) of the queue.
 void setFilter(AuditEventFilter filter)
          This method sets a filter for the queue instance.
 int size()
          This returns the number of events currently in the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuditEventQueue

public AuditEventQueue()

AuditEventQueue

public AuditEventQueue(java.util.Collection<AuditEvent> evts)
Method Detail

hasNext

public boolean hasNext()
This method returns true, iff the queue is non-empty. A return-value of true does not guarantee that the next call to nextEvent will not block, as a different thread might have emptied the list in the meantime.

Specified by:
hasNext in interface AuditEventSource
Returns:
true, iff queue is not empty.

nextEvent

public AuditEvent nextEvent()
This method will return the head of the queue, i.e. the events that has been in the queue for the longest term. Calling this method will block in case of an empty queue.

Specified by:
nextEvent in interface AuditEventSource
Returns:
The first (head) audit-event of the queue.

setFilter

public void setFilter(AuditEventFilter filter)
This method sets a filter for the queue instance. The filter will be matched against every event arriving at the queue, thus a filtered queue will only contain events that match the filter.

Specified by:
setFilter in interface AuditEventSource
Parameters:
filter - The filter used to match arriving events.

eventArrived

public void eventArrived(AuditEvent evt)
This method will add the event evt to the queue. If a filter has been set beforehand, the event will only be added if it matches the filter.

Specified by:
eventArrived in interface AuditEventListener
See Also:
AuditEventListener.eventArrived(org.jwall.web.audit.AuditEvent)

readNext

public AuditEvent readNext()
                    throws java.io.IOException,
                           ParseException
This method will return the next event (head) of the queue. The method is equivalent to nextEvent() and will thus block when called on an empty queue.

Specified by:
readNext in interface AuditEventReader
Returns:
The (head) event of the queue.
Throws:
java.io.IOException
ParseException

size

public int size()
This returns the number of events currently in the queue. Please not that the real number might differ if other threads concurrently added or removed events from the queue.

Returns:
The number of events in the queue.

close

public void close()
Specified by:
close in interface AuditEventReader

bytesAvailable

public long bytesAvailable()
Specified by:
bytesAvailable in interface AuditEventReader

bytesRead

public long bytesRead()
Specified by:
bytesRead in interface AuditEventReader