|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.umd.cs.piccolox.event.PNotificationCenter
public class PNotificationCenter
PNotificationCenter provides a way for objects that don't know about each other to communicate. It receives PNotification objects and broadcasts them to all interested listeners. Unlike standard Java events, the event listeners don't need to know about the event source, and the event source doesn't need to maintain the list of listeners.
Listeners of the notifications center are held by weak references. So the notification center will not create garbage collection problems as standard java event listeners do.
Nested Class Summary | |
---|---|
protected static class |
PNotificationCenter.NotificationKey
Represents a notification type from a particular object. |
protected static class |
PNotificationCenter.NotificationTarget
A NotificationTarget is a method on a particular object that can be invoked. |
Field Summary | |
---|---|
protected static PNotificationCenter |
DEFAULT_CENTER
Singleton instance of the notification center. |
protected ReferenceQueue |
keyQueue
A queue of NotificationKeys that are available to be garbage collected. |
protected HashMap |
listenersMap
A map of listeners keyed by NotificationKey objects. |
static Object |
NULL_MARKER
Used as a place holder for null names or objects. |
Method Summary | |
---|---|
boolean |
addListener(Object listener,
String callbackMethodName,
String notificationName,
Object object)
Registers the 'listener' to receive notifications with the name 'notificationName' and/or containing 'object'. |
static PNotificationCenter |
defaultCenter()
Singleton accessor for the PNotificationCenter. |
protected List |
matchingKeys(String name,
Object object)
Returns a list of keys with the given name and object. |
void |
postNotification(PNotification notification)
Post the notification to this notification center. |
void |
postNotification(String notificationName,
Object object)
Post a new notification with notificationName and object. |
void |
postNotification(String notificationName,
Object object,
Map properties)
Creates a notification with the name notificationName, associates it with the object, and posts it to this notification center. |
protected void |
processKeyQueue()
Iterates over available keys in the key queue and removes the queue from the listener map. |
void |
removeListener(Object listener)
Removes the listener so that it no longer receives notfications from this notification center. |
protected void |
removeListener(Object listener,
Object key)
Removes the given listener from receiving notifications with the given key. |
void |
removeListener(Object listener,
String notificationName,
Object object)
Unregisters the listener as a listener for the specified kind of notification. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Object NULL_MARKER
protected static volatile PNotificationCenter DEFAULT_CENTER
protected HashMap listenersMap
protected ReferenceQueue keyQueue
Method Detail |
---|
public static PNotificationCenter defaultCenter()
public boolean addListener(Object listener, String callbackMethodName, String notificationName, Object object)
listener
- object to be notified of notificationscallbackMethodName
- method to be invoked on the listenernotificationName
- name of notifications to filter onobject
- source of notification messages that this listener is
interested in
public void removeListener(Object listener)
listener
- listener to be removed from this notification centerpublic void removeListener(Object listener, String notificationName, Object object)
listener
- listener to be removednotificationName
- name of notifications or null for allobject
- notification source or null for allpublic void postNotification(String notificationName, Object object)
notificationName
- name of notification to postobject
- source of the notification, null signifies unknownpublic void postNotification(String notificationName, Object object, Map properties)
notificationName
- name of notification being postedobject
- source of the notification, may be nullproperties
- properties associated with the notificationpublic void postNotification(PNotification notification)
notification
- notification to be dispatched to appropriate
listenersprotected List matchingKeys(String name, Object object)
name
- name of keyobject
- key associated with the object
protected void removeListener(Object listener, Object key)
listener
- the listener being unregisteredkey
- the key that identifies the listenerprotected void processKeyQueue()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |