edu.uci.isr.yancees.dispatcher
Class EventDispatcher

java.lang.Object
  extended by edu.uci.isr.yancees.dispatcher.EventDispatcher
All Implemented Interfaces:
EventDispatcherInterface

public class EventDispatcher
extends java.lang.Object
implements EventDispatcherInterface

This class works as a wrapper around an event dispatcher implementation, It allows the registration of different adapters for to handle the content-based subscriptions of the system.


Constructor Summary
protected EventDispatcher()
          This constructor, as protected, prevents the direct instantiation of this object, and guarantees the singleton characteristic of this class.
 
Method Summary
 void addAdapter(EventDispatcherAdapterInterface adp)
          Configures the event dispatcher with the proper adapter.
 void connect()
          Starts the connection with the notification servers that the adapter wrapps.
 void connect(java.lang.String address)
          Connects and initializes the registered dispatchers This method is used by the server-specific adapters
 java.util.Vector getAdapterList()
           
static EventDispatcher getInstance()
          The only way to access the unique instance of EventDispatcher is by using this access method
 void publish(EventInterface evnt)
          Multithreaded publish implementation.
 void removeAdapter(EventDispatcherAdapterInterface adp)
           
 void resumeDispatcher(EventDispatcherListenerInterface li)
          resumes the delivery of notifications to the given subscriber n.
 void shutdownDispatcher()
          closes this Dispatcher service access point.
 void subscribe(java.lang.String adapterName, SubscriptionInterface sub, EventDispatcherListenerInterface li)
          This is a specific subscriber, that sends a message to the specfific adapter installed in the system
 void subscribe(SubscriptionInterface sub, EventDispatcherListenerInterface li)
          subscribes for sequences of events matching pattern p.
 void suspendDispatcher(EventDispatcherListenerInterface li)
          suspends the delivery of notifications to the given subscriber li.
 void unsubscribe(EventDispatcherListenerInterface li)
          cancels all the subscriptions posted by n.
 void unsubscribe(java.lang.String adapterName, EventDispatcherListenerInterface li)
           
 void unsubscribe(java.lang.String adapterName, SubscriptionInterface sub, EventDispatcherListenerInterface li)
           
 void unsubscribe(SubscriptionInterface sub, EventDispatcherListenerInterface li)
          cancels the subscriptions, posted by li, whose subscripton sub' is covered by subscripiton p.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventDispatcher

protected EventDispatcher()
This constructor, as protected, prevents the direct instantiation of this object, and guarantees the singleton characteristic of this class. The protected modifyer allows this class to be subclassed, permiting the over- load of the constructor.

Method Detail

getInstance

public static EventDispatcher getInstance()
The only way to access the unique instance of EventDispatcher is by using this access method


addAdapter

public void addAdapter(EventDispatcherAdapterInterface adp)
Configures the event dispatcher with the proper adapter. The dispatcher is a façade to the implementation-specific adapter. The use of this façade allows the runtime change of the adapter. Otherwise a simple inheritance would be enough.


removeAdapter

public void removeAdapter(EventDispatcherAdapterInterface adp)

connect

public void connect()
Starts the connection with the notification servers that the adapter wrapps.


connect

public void connect(java.lang.String address)
Description copied from interface: EventDispatcherInterface
Connects and initializes the registered dispatchers This method is used by the server-specific adapters

Specified by:
connect in interface EventDispatcherInterface
Parameters:
address - is the address of the server.

getAdapterList

public java.util.Vector getAdapterList()
Returns:
the list of adapters that is being currently used.

publish

public void publish(EventInterface evnt)
             throws DispatcherException
Multithreaded publish implementation. We need to deliver events to more than one dispatcher here. If we do not use threads, the slower dispatcher will be the bottleneck of the whole system, making fast dispatchers inneficient. Hence, we add threads to have "parallel" publishing, preventing one dispathcher's delay to interfere with another one.

Specified by:
publish in interface EventDispatcherInterface
Throws:
DispatcherException
See Also:
Event

subscribe

public void subscribe(SubscriptionInterface sub,
                      EventDispatcherListenerInterface li)
               throws DispatcherException
Description copied from interface: EventDispatcherInterface
subscribes for sequences of events matching pattern p.

Notice that given the distributed nature of some implementations of Dispatcher interface, there exist race conditions that might affect the semantics of subscriptions. A subscriber might miss some notifications published before or while the subscription is processed by Dispatcher.

Also, keep in mind that the current implementation of Dispatcher does not enforce any temporal order for the delivery of notifications. This limitation might affect the recognition of patterns. For example, two notifications x and y, generated at time tx and ty respectively, with tx < ty, in that order matching a pattern P=(fx fy), might in fact reach the subscriber at times Tx and Ty, with Tx > Ty, in which case pattern P would not be matched.

Specified by:
subscribe in interface EventDispatcherInterface
Parameters:
sub - is the subscription pattern
li - is the subscriber
Throws:
DispatcherException
See Also:
EventDispatcherInterface.unsubscribe(edu.uci.isr.yancees.SubscriptionInterface, edu.uci.isr.yancees.dispatcher.EventDispatcherListenerInterface)

unsubscribe

public void unsubscribe(SubscriptionInterface sub,
                        EventDispatcherListenerInterface li)
                 throws DispatcherException
Description copied from interface: EventDispatcherInterface
cancels the subscriptions, posted by li, whose subscripton sub' is covered by subscripiton p.

Unsubscriptions might incurr in the same kind of race conditions as subscriptions. Dispatcher will stop sending notifications to the subscriber only after it has completed the processing of the unsubscription. Due to the distributed nature of some implementations of Dispatcher, this might result in some additional ``unsolicited'' notifications.

Specified by:
unsubscribe in interface EventDispatcherInterface
li - is the subscriber interface
Throws:
DispatcherException
See Also:
EventDispatcherInterface.subscribe(edu.uci.isr.yancees.SubscriptionInterface, edu.uci.isr.yancees.dispatcher.EventDispatcherListenerInterface)

unsubscribe

public void unsubscribe(EventDispatcherListenerInterface li)
                 throws DispatcherException
Description copied from interface: EventDispatcherInterface
cancels all the subscriptions posted by n.

Specified by:
unsubscribe in interface EventDispatcherInterface
Parameters:
li - is the subscriber
Throws:
DispatcherException
See Also:
EventDispatcherInterface.subscribe(edu.uci.isr.yancees.SubscriptionInterface, edu.uci.isr.yancees.dispatcher.EventDispatcherListenerInterface)

suspendDispatcher

public void suspendDispatcher(EventDispatcherListenerInterface li)
                       throws DispatcherException
Description copied from interface: EventDispatcherInterface
suspends the delivery of notifications to the given subscriber li.

Specified by:
suspendDispatcher in interface EventDispatcherInterface
Parameters:
li - subscriber to be suspended
Throws:
DispatcherException

resumeDispatcher

public void resumeDispatcher(EventDispatcherListenerInterface li)
                      throws DispatcherException
Description copied from interface: EventDispatcherInterface
resumes the delivery of notifications to the given subscriber n.

Specified by:
resumeDispatcher in interface EventDispatcherInterface
Throws:
DispatcherException

shutdownDispatcher

public void shutdownDispatcher()
                        throws DispatcherException
Description copied from interface: EventDispatcherInterface
closes this Dispatcher service access point. This method releases any system resources associated with the access point. In case this access point is connected to other Dispatcher servers, this method will properly disconnect it.

Specified by:
shutdownDispatcher in interface EventDispatcherInterface
Throws:
DispatcherException

subscribe

public void subscribe(java.lang.String adapterName,
                      SubscriptionInterface sub,
                      EventDispatcherListenerInterface li)
               throws DispatcherException
Description copied from interface: EventDispatcherInterface
This is a specific subscriber, that sends a message to the specfific adapter installed in the system

Specified by:
subscribe in interface EventDispatcherInterface
Parameters:
adapterName - is the name of the adapter to specifically subscribe to
sub - is the subscription
li - is the listener interface
Throws:
DispatcherException

unsubscribe

public void unsubscribe(java.lang.String adapterName,
                        SubscriptionInterface sub,
                        EventDispatcherListenerInterface li)
                 throws DispatcherException
Specified by:
unsubscribe in interface EventDispatcherInterface
Throws:
DispatcherException

unsubscribe

public void unsubscribe(java.lang.String adapterName,
                        EventDispatcherListenerInterface li)
                 throws DispatcherException
Specified by:
unsubscribe in interface EventDispatcherInterface
Throws:
DispatcherException