context.arch.enactor
Class EnactorSubscriptionManager

java.lang.Object
  extended bycontext.arch.enactor.EnactorSubscriptionManager
All Implemented Interfaces:
Handler

public class EnactorSubscriptionManager
extends java.lang.Object
implements Handler

This class manages CTK subscriptions on behalf of enactors. It generates discovery queries out of enactor references, and notifies enactors of any new widgets that match those references. If multiple enactors utilize one subscription manager, it tries to minimize the number of actual CTK subscriptions used for all enactors.

Author:
alann

Field Summary
static int DEFAULT_PORT
           
 
Constructor Summary
EnactorSubscriptionManager()
           
EnactorSubscriptionManager(int port)
           
 
Method Summary
 boolean addEnactor(Enactor r)
          Adds an enactor to the ESM.
protected  void addEnactorReference(EnactorReference rwr)
          This method registers an EnactorReference with the ESM.
 DataObject executeWidgetService(java.lang.String subscriptionId, java.lang.String serviceName, java.lang.String functionName, Attributes input)
           
protected  void fireAddEventsForAll(Enactor e, EnactorListener sml)
           
protected  BaseObject getBaseObject()
           
 DataObject handle(java.lang.String subscriptionId, DataObject data)
          This abstract method is used to generically handle any callbacks that a widget may support.
 void handleIndependentReply(IndependentCommunication independentCommunication)
          This method is used to forward the result of an independent communication
protected  void handleNewComponent(ComponentDescription cd)
          We see if any registered enactors (through references) are interested in this component.
protected  void init()
          subscribes to the CTK Discover with a query that retrieves information about all new widgets.
 boolean removeEnactor(Enactor r)
          Removes an enactor from the ESM, and removes all of its subscriptions.
protected  void removeEnactorReference(EnactorReference rwr)
          removed EnactorReference from manager.
protected  java.util.Collection sendDiscovererAttributeQuery(AbstractQueryItem q)
           
protected  void subscribe(ComponentDescription cd, EnactorReference rwr)
          Subscribes to the widget described by the component description, and binds it to the enactor reference.
protected  void unsubscribe(java.lang.String subscriptionId)
          Unsubscribes to the widget with the given subscription id, and notifies all bound enactor references.
protected  void updateWidgetSubscriptionCondition(java.lang.String subscriptionId)
          resubscribe to a currently subscribed widget with new conditions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
See Also:
Constant Field Values
Constructor Detail

EnactorSubscriptionManager

public EnactorSubscriptionManager()

EnactorSubscriptionManager

public EnactorSubscriptionManager(int port)
Method Detail

addEnactor

public boolean addEnactor(Enactor r)
                   throws EnactorException
Adds an enactor to the ESM. If a new enactor, its references will be processed for subscriptions.

Parameters:
r - enactor to be added.
Returns:
true if rule was not already contained in the SM.
Throws:
EnactorException

removeEnactor

public boolean removeEnactor(Enactor r)
                      throws EnactorException
Removes an enactor from the ESM, and removes all of its subscriptions.

Parameters:
r - enactor to be removed.
Returns:
true if enactor in the SM.
Throws:
EnactorException

addEnactorReference

protected void addEnactorReference(EnactorReference rwr)
                            throws EnactorException
This method registers an EnactorReference with the ESM. The reference must be part of a registered Enactor. Enactors can call this method if they add new references to themselves at runtime.

Parameters:
rwr - the EnactorReference to add.
Throws:
SituationException - if the Enactor is not registered with the ESM.
EnactorException

removeEnactorReference

protected void removeEnactorReference(EnactorReference rwr)
                               throws EnactorException
removed EnactorReference from manager. This can be called at runtime by Enactors when they change their internal structure to notify the manager, but the Enactor must be part of the manager first by calling addRule.

Parameters:
rwr - the EnactorReference to be removed.
Throws:
EnactorException

fireAddEventsForAll

protected void fireAddEventsForAll(Enactor e,
                                   EnactorListener sml)
Parameters:
sml -

getBaseObject

protected BaseObject getBaseObject()

executeWidgetService

public DataObject executeWidgetService(java.lang.String subscriptionId,
                                       java.lang.String serviceName,
                                       java.lang.String functionName,
                                       Attributes input)

handleIndependentReply

public void handleIndependentReply(IndependentCommunication independentCommunication)
Description copied from interface: Handler
This method is used to forward the result of an independent communication

Specified by:
handleIndependentReply in interface Handler

handle

public DataObject handle(java.lang.String subscriptionId,
                         DataObject data)
                  throws InvalidMethodException,
                         MethodException
Description copied from interface: Handler
This abstract method is used to generically handle any callbacks that a widget may support. A context widget will call handle when a callback is triggered in the widget and the handler has subscribed to that callback.

Specified by:
handle in interface Handler
Parameters:
data - DataObject containing the data for the widget callback
Returns:
DataObject containing any directives to the widget that created the callback
Throws:
InvalidMethodException - if the specified callback can't be found
MethodException - is thrown if the specified callback can not be executed successfully

init

protected void init()
subscribes to the CTK Discover with a query that retrieves information about all new widgets.


handleNewComponent

protected void handleNewComponent(ComponentDescription cd)
We see if any registered enactors (through references) are interested in this component. If not we do nothing. If some enactor at a later date wants it, we'll get it again as a result of a query.

Parameters:
cd - description of component to be registered

subscribe

protected void subscribe(ComponentDescription cd,
                         EnactorReference rwr)
Subscribes to the widget described by the component description, and binds it to the enactor reference. We use the registry to bind the reference to an existing subscription if possible, before making a new CTK subscription.


unsubscribe

protected void unsubscribe(java.lang.String subscriptionId)
Unsubscribes to the widget with the given subscription id, and notifies all bound enactor references.


updateWidgetSubscriptionCondition

protected void updateWidgetSubscriptionCondition(java.lang.String subscriptionId)
resubscribe to a currently subscribed widget with new conditions.


sendDiscovererAttributeQuery

protected java.util.Collection sendDiscovererAttributeQuery(AbstractQueryItem q)