hypercast
Class NotificationHandler

java.lang.Object
  |
  +--hypercast.NotificationHandler
Direct Known Subclasses:
SecurityProcessor

public class NotificationHandler
extends java.lang.Object

This class implements a notification mechanism for applications so that applications can capture asynchronous events that happen in the system. To receive notification of events the application extends the NotificationHandler class. When an interesting event occurs, the application is notified. As events occur they are placed into a queue and sent to the application in FIFO order. Applications may block a thread on an event. Each event type has a lock object for this purpose. Application may also choose to extend the default asynchronous handler for an event type. If an application does both, it will receive an event twice. When blocking a thread on an event type, a boolean value can be specified that determines whether or not an event that occurred before the blocking call took place will cause the blocking thread to unblock. For example if a node generates an NODE_ISSTABLE event only once, but the application calls waitUntil_NODE_ISSTABLE *after* this event occurs, it will never see the event unless it asks to see any prior, unconsumed event. Note that only one prior event is accessible, in general events do not queue if nobody is listening for them. A third way in which applications may receive notification of event is by overriding the method of this class that dispatches individual event handlers: handler. To add a new event search this file for TEMPLATE and copy and paste templates doing a query/replace for the event type name. Also, update the HyperCastAppl.java file. Although this class is designed to be extended, it is not abstract. This is because certain mechanisms, such as the naming system, need to use the notification mechanism even when the application does not.


Constructor Summary
NotificationHandler()
          Construction of NotificationHandler causes a new thread to be created and started.
NotificationHandler(java.lang.String threadName)
           
 
Method Summary
 void addNotificationHandler(hypercast.NotificationHandler nh)
          Add notification handler to share the event source.
 void eventOccurred(hypercast.events.NOTIFICATION_EVENT event)
          Called by the components which support notification function, method is final so that user cannot extend this method and write code that blocks indefinitely when an event occurs.
 void handle_E2EACK_RECEIVED(hypercast.events.E2EACK_RECEIVED event)
           
 void handle_E2EPARTIALACK_RECEIVED(hypercast.events.E2EPARTIALACK_RECEIVED event)
           
 void handle_MSG_WITH_E2EACK_SENT(hypercast.events.MSG_WITH_E2EACK_SENT event)
           
 void handle_NAMING_EVENT(hypercast.events.NAMING_EVENT event)
           
 void handle_NEWSTREAM_ARRIVED_EVENT(hypercast.events.NEWSTREAM_ARRIVED_EVENT event)
           
 void handle_NODE_ISSTABLE(hypercast.events.NODE_ISSTABLE event)
           
 void handle_NODE_LEAVEGROUP(hypercast.events.NODE_LEAVEOVERLAY event)
           
 void handle_NODE_LEAVEOVERLAY(hypercast.events.NODE_LEAVEOVERLAY event)
           
 void handle_NODE_LOGICALADDRESSCHANGED(hypercast.events.NODE_LOGICALADDRESSCHANGED event)
           
 void handle_NODE_NEIGHBORHOODCHANGED(hypercast.events.NODE_NEIGHBORHOODCHANGED event)
           
 void handler(hypercast.events.NOTIFICATION_EVENT event)
          Determines the type of notification and dispatches the proper handler.
 void removeNotificationHandler(hypercast.NotificationHandler nh)
          Remove a handler from the chain
 void stop()
          This stops the notification handler.
 hypercast.events.E2EACK_RECEIVED waitUntil_E2EACK_RECEIVED()
           
 hypercast.events.E2EACK_RECEIVED waitUntil_E2EACK_RECEIVED(long timeout)
           
 hypercast.events.E2EPARTIALACK_RECEIVED waitUntil_E2EPARTIALACK_RECEIVED()
           
 hypercast.events.E2EPARTIALACK_RECEIVED waitUntil_E2EPARTIALACK_RECEIVED(long timeout)
           
 hypercast.events.MSG_WITH_E2EACK_SENT waitUntil_MSG_WITH_E2EACK_SENT()
           
 hypercast.events.MSG_WITH_E2EACK_SENT waitUntil_MSG_WITH_E2EACK_SENT(long timeout)
           
 hypercast.events.NAMING_EVENT waitUntil_NAMING_EVENT()
           
 hypercast.events.NAMING_EVENT waitUntil_NAMING_EVENT(long timeout)
           
 hypercast.events.NEWSTREAM_ARRIVED_EVENT waitUntil_NEWSTREAM_ARRIVED_EVENT()
           
 hypercast.events.NEWSTREAM_ARRIVED_EVENT waitUntil_NEWSTREAM_ARRIVED_EVENT(long timeout)
           
 hypercast.events.NODE_ISSTABLE waitUntil_NODE_ISSTABLE()
           
 hypercast.events.NODE_ISSTABLE waitUntil_NODE_ISSTABLE(long timeout)
           
 hypercast.events.NODE_LEAVEOVERLAY waitUntil_NODE_LEAVEGROUP()
           
 hypercast.events.NODE_LEAVEOVERLAY waitUntil_NODE_LEAVEGROUP(long timeout)
           
 hypercast.events.NODE_LEAVEOVERLAY waitUntil_NODE_LEAVEOVERLAY()
           
 hypercast.events.NODE_LEAVEOVERLAY waitUntil_NODE_LEAVEOVERLAY(long timeout)
           
 hypercast.events.NODE_LOGICALADDRESSCHANGED waitUntil_NODE_LOGICALADDRESSCHANGED()
           
 hypercast.events.NODE_LOGICALADDRESSCHANGED waitUntil_NODE_LOGICALADDRESSCHANGED(long timeout)
           
 hypercast.events.NODE_NEIGHBORHOODCHANGED waitUntil_NODE_NEIGHBORHOODCHANGED()
           
 hypercast.events.NODE_NEIGHBORHOODCHANGED waitUntil_NODE_NEIGHBORHOODCHANGED(long timeout)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NotificationHandler

public NotificationHandler()
Construction of NotificationHandler causes a new thread to be created and started. This thread serves notification events that appear in the eventQueue. Having a separate thread ensures that the "internal" HyperCast threads (i.e. the adapter threads) will not block due to application code.


NotificationHandler

public NotificationHandler(java.lang.String threadName)
Method Detail

stop

public void stop()
This stops the notification handler. This causes the internal thread to permanently exit. This should only be called when closing the socket and no more notifications can be received.


addNotificationHandler

public final void addNotificationHandler(hypercast.NotificationHandler nh)
Add notification handler to share the event source. Be careful not to make a loop of handlers, otherwise the program will run into deadlock when some event happens. A check is made here to make sure a handler is not added more than twice.

Parameters:
nh -

removeNotificationHandler

public final void removeNotificationHandler(hypercast.NotificationHandler nh)
Remove a handler from the chain

Parameters:
nh -
See Also:
addNotificationHandler(NotificationHandler)

eventOccurred

public final void eventOccurred(hypercast.events.NOTIFICATION_EVENT event)
Called by the components which support notification function, method is final so that user cannot extend this method and write code that blocks indefinitely when an event occurs.


handler

public void handler(hypercast.events.NOTIFICATION_EVENT event)
Determines the type of notification and dispatches the proper handler. Note that each type of event could have a method called "handle" and it could be called here as in: public void handler (final NOTIFICATION_EVENT event) { event.handle (this); } Each event could then call the appropriate method of the notification handler from within its handle method. For example for event type FOO: public void handle (NotificationHandler notificationHandler) { notificationHandler.handle_FOO (this); } In this way, Java's virtual method dispatch would do the dispatching. This method is designed to be overriden by application code that wants to have more control over event handling.


handle_NAMING_EVENT

public void handle_NAMING_EVENT(hypercast.events.NAMING_EVENT event)

waitUntil_NAMING_EVENT

public final hypercast.events.NAMING_EVENT waitUntil_NAMING_EVENT()

waitUntil_NAMING_EVENT

public final hypercast.events.NAMING_EVENT waitUntil_NAMING_EVENT(long timeout)

handle_NODE_ISSTABLE

public void handle_NODE_ISSTABLE(hypercast.events.NODE_ISSTABLE event)

waitUntil_NODE_ISSTABLE

public final hypercast.events.NODE_ISSTABLE waitUntil_NODE_ISSTABLE()

waitUntil_NODE_ISSTABLE

public final hypercast.events.NODE_ISSTABLE waitUntil_NODE_ISSTABLE(long timeout)

handle_E2EACK_RECEIVED

public void handle_E2EACK_RECEIVED(hypercast.events.E2EACK_RECEIVED event)

waitUntil_E2EACK_RECEIVED

public final hypercast.events.E2EACK_RECEIVED waitUntil_E2EACK_RECEIVED()

waitUntil_E2EACK_RECEIVED

public final hypercast.events.E2EACK_RECEIVED waitUntil_E2EACK_RECEIVED(long timeout)

handle_E2EPARTIALACK_RECEIVED

public void handle_E2EPARTIALACK_RECEIVED(hypercast.events.E2EPARTIALACK_RECEIVED event)

waitUntil_E2EPARTIALACK_RECEIVED

public final hypercast.events.E2EPARTIALACK_RECEIVED waitUntil_E2EPARTIALACK_RECEIVED()

waitUntil_E2EPARTIALACK_RECEIVED

public final hypercast.events.E2EPARTIALACK_RECEIVED waitUntil_E2EPARTIALACK_RECEIVED(long timeout)

handle_MSG_WITH_E2EACK_SENT

public void handle_MSG_WITH_E2EACK_SENT(hypercast.events.MSG_WITH_E2EACK_SENT event)

waitUntil_MSG_WITH_E2EACK_SENT

public final hypercast.events.MSG_WITH_E2EACK_SENT waitUntil_MSG_WITH_E2EACK_SENT()

waitUntil_MSG_WITH_E2EACK_SENT

public final hypercast.events.MSG_WITH_E2EACK_SENT waitUntil_MSG_WITH_E2EACK_SENT(long timeout)

handle_NEWSTREAM_ARRIVED_EVENT

public void handle_NEWSTREAM_ARRIVED_EVENT(hypercast.events.NEWSTREAM_ARRIVED_EVENT event)

waitUntil_NEWSTREAM_ARRIVED_EVENT

public final hypercast.events.NEWSTREAM_ARRIVED_EVENT waitUntil_NEWSTREAM_ARRIVED_EVENT()

waitUntil_NEWSTREAM_ARRIVED_EVENT

public final hypercast.events.NEWSTREAM_ARRIVED_EVENT waitUntil_NEWSTREAM_ARRIVED_EVENT(long timeout)

handle_NODE_LEAVEGROUP

public void handle_NODE_LEAVEGROUP(hypercast.events.NODE_LEAVEOVERLAY event)

waitUntil_NODE_LEAVEGROUP

public final hypercast.events.NODE_LEAVEOVERLAY waitUntil_NODE_LEAVEGROUP()

waitUntil_NODE_LEAVEGROUP

public final hypercast.events.NODE_LEAVEOVERLAY waitUntil_NODE_LEAVEGROUP(long timeout)

handle_NODE_LEAVEOVERLAY

public void handle_NODE_LEAVEOVERLAY(hypercast.events.NODE_LEAVEOVERLAY event)

waitUntil_NODE_LEAVEOVERLAY

public final hypercast.events.NODE_LEAVEOVERLAY waitUntil_NODE_LEAVEOVERLAY()

waitUntil_NODE_LEAVEOVERLAY

public final hypercast.events.NODE_LEAVEOVERLAY waitUntil_NODE_LEAVEOVERLAY(long timeout)

handle_NODE_LOGICALADDRESSCHANGED

public void handle_NODE_LOGICALADDRESSCHANGED(hypercast.events.NODE_LOGICALADDRESSCHANGED event)

waitUntil_NODE_LOGICALADDRESSCHANGED

public final hypercast.events.NODE_LOGICALADDRESSCHANGED waitUntil_NODE_LOGICALADDRESSCHANGED()

waitUntil_NODE_LOGICALADDRESSCHANGED

public final hypercast.events.NODE_LOGICALADDRESSCHANGED waitUntil_NODE_LOGICALADDRESSCHANGED(long timeout)

handle_NODE_NEIGHBORHOODCHANGED

public void handle_NODE_NEIGHBORHOODCHANGED(hypercast.events.NODE_NEIGHBORHOODCHANGED event)

waitUntil_NODE_NEIGHBORHOODCHANGED

public final hypercast.events.NODE_NEIGHBORHOODCHANGED waitUntil_NODE_NEIGHBORHOODCHANGED()

waitUntil_NODE_NEIGHBORHOODCHANGED

public final hypercast.events.NODE_NEIGHBORHOODCHANGED waitUntil_NODE_NEIGHBORHOODCHANGED(long timeout)