|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcmsc433.p1.Listenable<E>
public class Listenable<E>
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 |
|---|
public Listenable(java.lang.Object target)
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 |
|---|
public void register(Listener<E> listener)
listener - The listener to register.public void unregister(Listener<E> listener)
listener - The listener to remove. If this listener is
not present, then unregister behaves as a no-op.public void update(E event)
event - Event to notify listeners of.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||