cmsc433.p1
Class Listenable<E>

java.lang.Object
  extended by cmsc433.p1.Listenable<E>

public class Listenable<E>
extends java.lang.Object

A Listenable is an object of interest. Whenever this object is used in an interesting way, its update() method is called. This method then notifies each of the listeners that are registered with the object, via the register() and unregister() methods. Notification takes place by calling the notify() method on each of the registered Listeners. For this assignment, we expect this class to be a utility class used by implementations of Log and FilterLog; these implementations will invoke the update() method whenever a LogRecord is added via the add() method. May or may not be thread-safe depending on the design of the other classes.


Constructor Summary
Listenable(java.lang.Object target)
          Creates an initially-empty internal list of listeners for the target object.
 
Method Summary
 void register(Listener<E> listener)
          Registers a listener.
 void unregister(Listener<E> listener)
          Removes a previously-registered listener.
 void update(E event)
          Notifies all listeners registered with this object of the given event.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Listenable

public Listenable(java.lang.Object target)
Creates an initially-empty internal list of listeners for the target object.

Parameters:
target - The object with which this list of listeners is associated. For this assignment, this will be an implementation of the Log interface.
Method Detail

register

public void register(Listener<E> listener)
Registers a listener. For this assignment, listneners will be updated whenever a log record is added to a log with which this Listener is associated.

Parameters:
listener - The listener to register.

unregister

public void unregister(Listener<E> listener)
Removes a previously-registered listener.

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

update

public void update(E event)
Notifies all listeners registered with this object of the given event.

Parameters:
event - Event to notify listeners of.