|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.gjt.universe.notification.NotificationCenter
The instances of this class implement a detached rendezvous system between objects which post notifications and objects which are interested in them. This approach has the following benefits over a scheme where notification events are passed directly between the poster and the observer: - each notification generating object need not manage the list of observers itself, thus eliminating duplication of code when it is a subclass of a library class without this support. - observers can register for notifications of a certain type, notifications from a certain sender, or a combination as desired. - observers need not know about specific instances of senders, merely the types of notifications that might be sent. - weak references are utilized to ensure that observers do not reside permanently in memory simply because they are still registered as a observer. - observers can block as long as they wish while processing a notification without affecting the handling of GUI events. Most code will simply use the single default instance of this class provided by the defaultCenter class method. However, applications which have a large number of notifications which can be logically segmented, may wish to create individual NotificationCenters known to the relevant parties in order to improve dispatch performance. EXAMPLE OF REGISTERING NotificationCenter aCenter = NotirficationCenter.defaultCenter(); aCenter.addObserver( obs1, "On Fire" ) - obs1 wants its handleNotification() method called whenever anything posts an "On Fire" notification. aCenter.addObserver( obs2, "On Fire", myHouse ) - obs2 only cares about when my house is on fire. aCenter.addObserver( obs3, myHouse ) - obs3 wants its handleNotification() method called whenever anything happens to the my house.
Notification
Field Summary | |
private java.util.Hashtable |
myByBothTable
|
private java.util.Hashtable |
myByNameTable
|
private java.util.Hashtable |
myBySenderTable
|
private static NotificationCenter |
ourDefaultCenter
|
Constructor Summary | |
NotificationCenter()
This is the designated constructor which should be used to create new instances of this class. |
Method Summary | |
void |
addObserver(NotificationObserver anObserver,
java.lang.Object aSender)
This method adds the given object as an observer for events posted by the given sending object regardless of the notification name name. |
void |
addObserver(NotificationObserver anObserver,
java.lang.String notificationName)
This method adds the given object as an observer for events posted by any object, but having the given notification name. |
void |
addObserver(NotificationObserver anObserver,
java.lang.String notificationName,
java.lang.Object aSender)
This method adds the given object as an observer for events posted by the given sending object and having the given name. |
static NotificationCenter |
defaultCenter()
This method returns the default notification center for the application, creating it if necessary. |
void |
postNotification(Notification aNotification)
This method posts the given notification through the notification center. |
void |
removeObserver(NotificationObserver anObserver,
java.lang.Object aSender)
This method removes the given object as an observer for events posted by the given sending object regardless of the notification name name. |
void |
removeObserver(NotificationObserver anObserver,
java.lang.String notificationName)
This method removes the given object as an observer for events posted by any object, but having the given notification name. |
void |
removeObserver(NotificationObserver anObserver,
java.lang.String notificationName,
java.lang.Object aSender)
This method removes the given object as an observer for events posted by the given sending object and having the given name. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static NotificationCenter ourDefaultCenter
private java.util.Hashtable myByNameTable
private java.util.Hashtable myBySenderTable
private java.util.Hashtable myByBothTable
Constructor Detail |
public NotificationCenter()
Method Detail |
public static NotificationCenter defaultCenter()
public void addObserver(NotificationObserver anObserver, java.lang.String notificationName, java.lang.Object aSender)
anObserver
- The object that wishes to be notified.notificationName
- The name of the notification expected to be posted.aSender
- The object expected to post the notification.public void addObserver(NotificationObserver anObserver, java.lang.String notificationName)
anObserver
- The object that wishes to be notified.notificationName
- The name of the notification expected to be posted.public void addObserver(NotificationObserver anObserver, java.lang.Object aSender)
anObserver
- The object that wishes to be notified.aSender
- The object expected to post the notification.public void removeObserver(NotificationObserver anObserver, java.lang.String notificationName, java.lang.Object aSender)
anObserver
- The object that wishes to resign from being be notified.notificationName
- The name of the notifications which were to be detected.aSender
- The object being observed.addObserver
public void removeObserver(NotificationObserver anObserver, java.lang.String notificationName)
anObserver
- The object that wishes to resign from being be notified.notificationName
- The name of the notification that was being observerd.addObserver
public void removeObserver(NotificationObserver anObserver, java.lang.Object aSender)
anObserver
- The object that wishes to resign from being be notified.aSender
- The object that was being observed.public void postNotification(Notification aNotification)
aNotification
- The notification to be posted.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |