de.infinityloop.util.log
Class LogEventCollector

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<LogEvent>
              extended by de.infinityloop.util.log.LogEventCollector
All Implemented Interfaces:
LogBroadcaster, LogListener, java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<LogEvent>, java.util.Collection<LogEvent>, java.util.List<LogEvent>, java.util.RandomAccess
Direct Known Subclasses:
LogEventAggregator

public class LogEventCollector
extends java.util.ArrayList<LogEvent>
implements LogListener, LogBroadcaster

A NotificationCollector is used for globally collecting notifications, errors, warnings over the app's run to be able to identify them later in some collected form for evaluation.

Author:
chris
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
LogEventCollector(java.lang.String name, LogBroadcaster lb, de.infinityloop.util.log.helpers.LogEventFilter f)
           
LogEventCollector(java.lang.String name, de.infinityloop.util.log.helpers.LogEventFilter f)
          Constructors
 
Method Summary
 void addedTo(LogBroadcaster le)
          Called when this object is successfully attached to a LogPublisher.
 void addLogListener(LogListener ls)
          Call to attach a Listener for log events received by the LogBroadcaster.
 LogEvent broadcast(LogEvent le)
          Method to dispatch the specified log event to all registered listeners on this broadcaster.
 void clear()
          Clears all collected notifications.
 int countType(int type)
          Counts the number of messages in this collection of the respective type
 boolean equals(java.lang.Object o)
          We MUST override equals() since the behaviour of the inherited method of ArrayList is not what we require.
 LogEventCollector extractSignificantEntries(int[] types, int[] including, int[] excluding)
          This method tells whether this exception contains a LogEvent that is significant for you.
 LogEventCollector extractSignificantEntries(de.infinityloop.util.log.helpers.LogEventFilter f)
          Return the entries that are matched by the specified LogEventFilter.
 java.lang.String getAsString()
          human readable representation of the collected notifications
 int getCode(int i)
           
 java.lang.Throwable getEmbeddedException(int i)
           
 LogEventCollector getEntriesByType(int type)
          Returns an ArrayList object that holds all those LogEntry objects that are of the specified type.
 LogEvent getEntryByCode(int code)
          Returns the (first) entry with the specified code or null if that message is not contained in this exception.
 de.infinityloop.util.log.helpers.LogEventFilter getFilter()
          Returns the incoming filter instance active for this LogEventCollector.
 LogEvent getLogEvent(int i)
          Retrieve the ith collected LogEvent.
 java.lang.String getMessage(int i)
           
 java.util.ArrayList getNotifications()
          Returns the collected notifications
 java.lang.Object[] getParameters(int i)
          retrieves the parameter objects for the respective error message
 int hashCode()
          We MUST override the default hash function as that changes with changing the list entries, which we do not want!
 boolean receiveLogEvent(LogEvent le)
          Receive a LogEvent from a publisher we are registered to.
 void removeAllSubscribers()
          This method unregisters all LogSubscriber from this LogPublisher.
 void removedFrom(LogBroadcaster le)
          Called when we get removed from a LogPublisher.
 void removeLogListener(LogListener ls)
          Call to detach a Listener for log events received by the LogBroadcaster.
 void setFilter(de.infinityloop.util.log.helpers.LogEventFilter f)
          Sets a new LogEventFilter instance for this collector.
 void setLevel(int filterLevel)
           
 java.lang.String toString()
           
 void unregisterFromAll()
          This method unregisters this LogSubscriber from all LogPublishers it is registered with.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

LogEventCollector

public LogEventCollector(java.lang.String name,
                         de.infinityloop.util.log.helpers.LogEventFilter f)
Constructors

Parameters:
name - TODO

LogEventCollector

public LogEventCollector(java.lang.String name,
                         LogBroadcaster lb,
                         de.infinityloop.util.log.helpers.LogEventFilter f)
Method Detail

getFilter

public de.infinityloop.util.log.helpers.LogEventFilter getFilter()
Returns the incoming filter instance active for this LogEventCollector.

Returns:

setFilter

public void setFilter(de.infinityloop.util.log.helpers.LogEventFilter f)
Sets a new LogEventFilter instance for this collector.


equals

public boolean equals(java.lang.Object o)
We MUST override equals() since the behaviour of the inherited method of ArrayList is not what we require. Comparisons on types of LogEventCollector must always compare on object identity!

Specified by:
equals in interface java.util.Collection<LogEvent>
Specified by:
equals in interface java.util.List<LogEvent>
Overrides:
equals in class java.util.AbstractList<LogEvent>
Parameters:
o -
Returns:
See Also:
AbstractList.equals(java.lang.Object)

hashCode

public int hashCode()
We MUST override the default hash function as that changes with changing the list entries, which we do not want!

Specified by:
hashCode in interface java.util.Collection<LogEvent>
Specified by:
hashCode in interface java.util.List<LogEvent>
Overrides:
hashCode in class java.util.AbstractList<LogEvent>
Returns:
See Also:
AbstractList.hashCode()

receiveLogEvent

public boolean receiveLogEvent(LogEvent le)
Receive a LogEvent from a publisher we are registered to.

Specified by:
receiveLogEvent in interface LogListener
Parameters:
le -
Returns:
See Also:
LogListener.receiveLogEvent(de.infinityloop.util.log.LogEvent)

getNotifications

public java.util.ArrayList getNotifications()
Returns the collected notifications

Returns:
the ArrayList of collected notifications

clear

public void clear()
Clears all collected notifications.

Specified by:
clear in interface java.util.Collection<LogEvent>
Specified by:
clear in interface java.util.List<LogEvent>
Overrides:
clear in class java.util.ArrayList<LogEvent>

countType

public int countType(int type)
Counts the number of messages in this collection of the respective type

Parameters:
type - one of the types
Returns:
the numebr of entries of this type

getLogEvent

public LogEvent getLogEvent(int i)
                     throws java.lang.ArrayIndexOutOfBoundsException
Retrieve the ith collected LogEvent.

Parameters:
i -
Returns:
Throws:
java.lang.ArrayIndexOutOfBoundsException

getAsString

public java.lang.String getAsString()
human readable representation of the collected notifications


addedTo

public void addedTo(LogBroadcaster le)
Called when this object is successfully attached to a LogPublisher.

Specified by:
addedTo in interface LogListener
Parameters:
le -
See Also:
LogListener.addedTo(de.infinityloop.util.log.LogBroadcaster)

removedFrom

public void removedFrom(LogBroadcaster le)
Called when we get removed from a LogPublisher.

Specified by:
removedFrom in interface LogListener
Parameters:
le -
See Also:
LogListener.removedFrom(de.infinityloop.util.log.LogBroadcaster)

unregisterFromAll

public void unregisterFromAll()
This method unregisters this LogSubscriber from all LogPublishers it is registered with. Use this to break any links and make this object disposable to the GC.


extractSignificantEntries

public LogEventCollector extractSignificantEntries(int[] types,
                                                   int[] including,
                                                   int[] excluding)
This method tells whether this exception contains a LogEvent that is significant for you. What is significant can be specified using three parameters. The processing model is as follows:
  1. If types is null, all entries are examined. Otherwise, only those that match any of the contained types are observed.
  2. From the set of remaining entries after step 1, only those are kept that are contained in including. If including is null, all entries pass this step.
  3. From the set of remaining entries after step 2, only those are kept that are not in excluding. If excluding is null, all entries pass this step.
  4. All entries left after performing step 3 are returned in form of an ArrayList containing exactly those remaining LogEvent objects.

Parameters:
types - a variable length array of integers containing the type of LogEvent objects you are interested in. E.g. passing new int[] { LogEvent.ERROR } will only report entries of type ERROR. If you pass null, all entries are respected.
including - Again in form of a variable size integer array, you can specify which error codes are interesting for you. If you pass null, all error codes are observed.
excluding - Same as for including, but lists the error codes you are not interested in.
Returns:
a LogEventCollector object containing the LogEvent objects left after performing the filtering. If none of the source items match, an empty LogEventCollector is returned (not null!)

extractSignificantEntries

public LogEventCollector extractSignificantEntries(de.infinityloop.util.log.helpers.LogEventFilter f)
Return the entries that are matched by the specified LogEventFilter.

Parameters:
f - the filter
Returns:

getEntryByCode

public LogEvent getEntryByCode(int code)
Returns the (first) entry with the specified code or null if that message is not contained in this exception.

Parameters:
code - the code to look for
Returns:
the first LogEntry with the specified code or null if not found

getEntriesByType

public LogEventCollector getEntriesByType(int type)
Returns an ArrayList object that holds all those LogEntry objects that are of the specified type.

Parameters:
type - the type of the entries to retrieve
Returns:
a LogEventCollector containing all LogEntry()s matching the specified type

getEmbeddedException

public java.lang.Throwable getEmbeddedException(int i)
                                         throws java.lang.ArrayIndexOutOfBoundsException
Parameters:
i - index in list of entries
Returns:
the embedded exception at index i or null if none was specified
Throws:
java.lang.ArrayIndexOutOfBoundsException - when the index is out of bounds

getParameters

public java.lang.Object[] getParameters(int i)
                                 throws java.lang.ArrayIndexOutOfBoundsException
retrieves the parameter objects for the respective error message

Parameters:
i - index in list of entries
Returns:
the parameter Object[] array or null if none was specified
Throws:
java.lang.ArrayIndexOutOfBoundsException - when the index is out of bounds

getCode

public int getCode(int i)
            throws java.lang.ArrayIndexOutOfBoundsException
Parameters:
i - index in list of entries
Returns:
the code at index i
Throws:
java.lang.ArrayIndexOutOfBoundsException - when the index is out of bounds

getMessage

public java.lang.String getMessage(int i)
                            throws java.lang.ArrayIndexOutOfBoundsException
Parameters:
i - index in list of entries
Returns:
the message at index i
Throws:
java.lang.ArrayIndexOutOfBoundsException - when the index is out of bounds

setLevel

public final void setLevel(int filterLevel)
Parameters:
filterLevel - The filterLevel to set.

addLogListener

public void addLogListener(LogListener ls)
Description copied from interface: LogBroadcaster
Call to attach a Listener for log events received by the LogBroadcaster.

Specified by:
addLogListener in interface LogBroadcaster
Parameters:
ls -
See Also:
LogBroadcaster.addLogListener(de.infinityloop.util.log.LogListener)

broadcast

public LogEvent broadcast(LogEvent le)
Description copied from interface: LogBroadcaster
Method to dispatch the specified log event to all registered listeners on this broadcaster. A Broadcaster is always the source of a logging event coming in from external.

Specified by:
broadcast in interface LogBroadcaster
Parameters:
le -
Returns:
See Also:
LogBroadcaster.broadcast(de.infinityloop.util.log.LogEvent)

removeLogListener

public void removeLogListener(LogListener ls)
Description copied from interface: LogBroadcaster
Call to detach a Listener for log events received by the LogBroadcaster.

Specified by:
removeLogListener in interface LogBroadcaster
Parameters:
ls -
See Also:
LogBroadcaster.removeLogListener(de.infinityloop.util.log.LogListener)

removeAllSubscribers

public void removeAllSubscribers()
This method unregisters all LogSubscriber from this LogPublisher. Use this to break any links and make this object disposable to the GC.


toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection<LogEvent>
Returns:
See Also:
AbstractCollection.toString()