cmsc433.p1
Class SplitLog

java.lang.Object
  extended by cmsc433.p1.SplitLog
All Implemented Interfaces:
Log

public class SplitLog
extends java.lang.Object
implements Log

A SplitLog operates on two child logs. This class should be thread-safe.


Constructor Summary
SplitLog(Log log1, Log log2)
          Creates a new SplitLog.
 
Method Summary
 void add(LogRecord record)
          Adds a record to both child logs.
 java.util.List<LogRecord> flush()
          Calls flush on both child logs, returning a combined result.
 java.util.List<LogRecord> getAll(long windowMS)
          Calls getAll on both child logs, returning a combined result.
 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 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

SplitLog

public SplitLog(Log log1,
                Log log2)
Creates a new SplitLog. Whenever a record is added to this log, it will also be atomically added to both log1 and log2.

Parameters:
log1 - The first log to copy events to.
log2 - The second log to copy events to.
Method Detail

add

public void add(LogRecord record)
Adds a record to both child logs.

Specified by:
add in interface Log
Parameters:
record - record to be added to both child logs

getAll

public java.util.List<LogRecord> getAll(long windowMS)
Calls getAll on both child logs, returning a combined result. Result should maintain any duplicates. May or may not contain all events from external modifications of child logs. Your design document should discuss your implementation with regard to this functionality.

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

flush

public java.util.List<LogRecord> flush()
Calls flush on both child logs, returning a combined result. Result should maintain any duplicates. May or may not contain all events from external modifications of child logs. Your design document should discuss your implementation with regard to this functionality.

Specified by:
flush in interface Log

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.