cmsc433.p1
Class BasicFilterLog

java.lang.Object
  extended by cmsc433.p1.BasicFilterLog
All Implemented Interfaces:
FilterLog, Log

public class BasicFilterLog
extends java.lang.Object
implements FilterLog

A basic implementation of FilterLog. Wraps an underlying log, applying the current filter. Functions flush and getAll apply to the underlying log as a whole, not just records added through the BasicFilterLog add method. This class should be thread-safe.


Constructor Summary
BasicFilterLog()
          Empty constructor creates a new BasicLog of unlimited size as the underlying Log for this object.
BasicFilterLog(Log log)
          Constructor takes one argument, a log to be filtered.
 
Method Summary
 void add(LogRecord record)
          Stores a LogRecord in the Log.
 java.util.List<LogRecord> flush()
          Returns all LogRecords kept in the log, emptying the log.
 java.util.List<LogRecord> getAll(long windowMS)
          Returns all LogRecords whose timestamps are within a window of time.
 void register(Listener<LogRecord> listener)
          Registers a listener that whose notify() method will be called whenever a record is added to this log; the first argument of notify() is the log itself, and the second is the LogRecord that was added.
 void setFilter(java.lang.String strPat)
          Sets a regular-expression filter that governs which events are stored.
 void unregister(Listener<LogRecord> listener)
          Removes a previously-registered listener.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicFilterLog

public BasicFilterLog(Log log)
Constructor takes one argument, a log to be filtered. Note that the given Log can be modified outside of this object as well.

Parameters:
log -

BasicFilterLog

public BasicFilterLog()
Empty constructor creates a new BasicLog of unlimited size as the underlying Log for this object.

Method Detail

add

public void add(LogRecord record)
Description copied from interface: Log
Stores a LogRecord in the Log. Implementations may choose to only add some logs (e.g. logs matching a given pattern).

Specified by:
add in interface Log

getAll

public java.util.List<LogRecord> getAll(long windowMS)
Description copied from interface: Log
Returns all LogRecords whose timestamps are within a window of time. Note that inclusion is based on the timestamp of the LogRecord, not the time at which the record was stored in the Log. This is non-destructive; all records remain in the Log.

Specified by:
getAll in interface Log
Parameters:
windowMS - return all records from the last [windowMS] milliseconds.

flush

public java.util.List<LogRecord> flush()
Description copied from interface: Log
Returns all LogRecords kept in the log, emptying the log.

Specified by:
flush in interface Log

setFilter

public void setFilter(java.lang.String strPat)
Description copied from interface: FilterLog
Sets a regular-expression filter that governs which events are stored.

Specified by:
setFilter in interface FilterLog
Parameters:
strPat - is a regular expression to match against; if a LogRecord is added with an event portion matching this expression, then the LogRecord is retained. Otherwise, the LogRecord is ignored.

register

public void register(Listener<LogRecord> listener)
Description copied from interface: Log
Registers a listener that whose notify() method will be called whenever a record is added to this log; the first argument of notify() is the log itself, and the second is the LogRecord that was added.

Specified by:
register in interface Log
Parameters:
listener - The listener to register.

unregister

public void unregister(Listener<LogRecord> listener)
Description copied from interface: Log
Removes a previously-registered listener.

Specified by:
unregister in interface Log
Parameters:
listener - The listener to remove. If this listener is not present, then unregister behaves as a no-op.