org.jwall.web.audit
Class AuditEventQueue

java.lang.Object
  extended by org.jwall.web.audit.AuditEventQueue
All Implemented Interfaces:
Iterable<AuditEvent>, EventListener<AuditEvent>, AuditEventListener, AuditEventReader, AuditEventSource

public class AuditEventQueue
extends Object
implements AuditEventSource, AuditEventReader, AuditEventListener

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()
          This creates new empty queue for holding audit events.
AuditEventQueue(Collection<AuditEvent> evts)
          This creates a new queue which is initially filled with the given set of events.
 
Method Summary
 boolean atEOF()
           
 long bytesAvailable()
           
 long bytesRead()
           
 void close()
           
 void eventArrived(AuditEvent evt)
          This method will add the event evt to the queue.
 void eventsArrived(Collection<AuditEvent> events)
          This method is called for notifying the listener of arrival of several events in a block.
 boolean hasNext()
          This method returns true, iff the queue is non-empty.
 Iterator<AuditEvent> iterator()
           
 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 tries to read the next event that is available.
 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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuditEventQueue

public AuditEventQueue()
This creates new empty queue for holding audit events.


AuditEventQueue

public AuditEventQueue(Collection<AuditEvent> evts)
This creates a new queue which is initially filled with the given set of events.

Parameters:
evts - The initial set of events.
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 EventListener<AuditEvent>
Specified by:
eventArrived in interface AuditEventListener
Parameters:
evt - The event which arrived.
See Also:
AuditEventListener.eventArrived(org.jwall.web.audit.AuditEvent)

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.

bytesAvailable

public long bytesAvailable()
Specified by:
bytesAvailable in interface AuditEventReader
See Also:
AuditEventReader.bytesAvailable()

bytesRead

public long bytesRead()
Specified by:
bytesRead in interface AuditEventReader
See Also:
AuditEventReader.bytesRead()

close

public void close()
           throws IOException
Specified by:
close in interface AuditEventReader
Throws:
IOException
See Also:
AuditEventReader.close()

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.

readNext

public AuditEvent readNext()
                    throws IOException,
                           ParseException
Description copied from interface: AuditEventReader
This method tries to read the next event that is available.

Specified by:
readNext in interface AuditEventReader
Returns:
The next audit-event from or NULL if no event is available.
Throws:
IOException
ParseException
See Also:
AuditEventReader.readNext()

atEOF

public boolean atEOF()
Specified by:
atEOF in interface AuditEventReader

iterator

public Iterator<AuditEvent> iterator()
Specified by:
iterator in interface Iterable<AuditEvent>


Copyright © 2012 jwall.org. All Rights Reserved.