edu.umd.cs.piccolox.event
Class PNotificationCenter

java.lang.Object
  extended by edu.umd.cs.piccolox.event.PNotificationCenter

public class PNotificationCenter
extends java.lang.Object

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 notfications center are held by weak references. So the notfication center will not create garbage collection problems as standard java event listeners do.

Author:
Jesse Grosjean

Nested Class Summary
protected static class PNotificationCenter.CompoundKey
           
protected static class PNotificationCenter.CompoundValue
           
 
Field Summary
protected static PNotificationCenter DEFAULT_CENTER
           
protected  java.lang.ref.ReferenceQueue keyQueue
           
protected  java.util.HashMap listenersMap
           
static java.lang.Object NULL_MARKER
           
 
Method Summary
 void addListener(java.lang.Object listener, java.lang.String callbackMethodName, java.lang.String notificationName, java.lang.Object object)
          Registers the 'listener' to receive notifications with the name 'notificationName' and/or containing 'object'.
static PNotificationCenter defaultCenter()
           
protected  java.util.List matchingKeys(java.lang.String name, java.lang.Object object)
           
 void postNotification(PNotification aNotification)
          Post the notification to this notification center.
 void postNotification(java.lang.String notificationName, java.lang.Object object)
          Post a new notfication with notificationName and object.
 void postNotification(java.lang.String notificationName, java.lang.Object object, java.util.Map userInfo)
          Creates a notification with the name notificationName, associates it with the object, and posts it to this notification center.
protected  void processKeyQueue()
           
 void removeListener(java.lang.Object listener)
          Removes the listener so that it no longer recives notfications from this notfication center.
protected  void removeListener(java.lang.Object listener, java.lang.Object key)
           
 void removeListener(java.lang.Object listener, java.lang.String notificationName, java.lang.Object object)
          Removes the listeners as the listener of notifications matching notificationName and object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_MARKER

public static final java.lang.Object NULL_MARKER

DEFAULT_CENTER

protected static PNotificationCenter DEFAULT_CENTER

listenersMap

protected java.util.HashMap listenersMap

keyQueue

protected java.lang.ref.ReferenceQueue keyQueue
Method Detail

defaultCenter

public static PNotificationCenter defaultCenter()

addListener

public void addListener(java.lang.Object listener,
                        java.lang.String callbackMethodName,
                        java.lang.String notificationName,
                        java.lang.Object object)
Registers the 'listener' to receive notifications with the name 'notificationName' and/or containing 'object'. When a matching notification is posted the callBackMethodName message will be sent to the listener with a single PNotification argument. If notificationName is null then the listener will receive all notifications with an object matching 'object'. If 'object' is null the listener will receive all notifications with the name 'notificationName'.


removeListener

public void removeListener(java.lang.Object listener)
Removes the listener so that it no longer recives notfications from this notfication center.


removeListener

public void removeListener(java.lang.Object listener,
                           java.lang.String notificationName,
                           java.lang.Object object)
Removes the listeners as the listener of notifications matching notificationName and object. If listener is null all listeners matching notificationName and object are removed. If notificationName is null the listener will be removed from all notifications containing the object. If the object is null then the listener will be removed from all notifications matching notficationName.


postNotification

public void postNotification(java.lang.String notificationName,
                             java.lang.Object object)
Post a new notfication with notificationName and object. The object is typically the object posting the notification. The object may be null.


postNotification

public void postNotification(java.lang.String notificationName,
                             java.lang.Object object,
                             java.util.Map userInfo)
Creates a notification with the name notificationName, associates it with the object, and posts it to this notification center. The object is typically the object posting the notification. It may be nil.


postNotification

public void postNotification(PNotification aNotification)
Post the notification to this notification center. Most often clients will instead use one of this classes convenience postNotifcations methods.


matchingKeys

protected java.util.List matchingKeys(java.lang.String name,
                                      java.lang.Object object)

removeListener

protected void removeListener(java.lang.Object listener,
                              java.lang.Object key)

processKeyQueue

protected void processKeyQueue()


Copyright 2005 by University of Maryland, College Park, MD 20742, USA All rights reserved.

Web Accessibility