jade.proto.states
Class HandlerSelector

java.lang.Object
  |
  +--jade.core.behaviours.Behaviour
        |
        +--jade.core.behaviours.CompositeBehaviour
              |
              +--jade.core.behaviours.SerialBehaviour
                    |
                    +--jade.core.behaviours.FSMBehaviour
                          |
                          +--jade.proto.states.HandlerSelector
All Implemented Interfaces:
Serializable, java.io.Serializable

public abstract class HandlerSelector
extends FSMBehaviour

This class implements a selector of handler (i.e. jade.core.behaviours.Behaviour) A number of handlers can be registered with this HandlerSelector, each handler bound to a different key. The abstract method getSelectionKey is then called that must return the key to select one of the registered handlers. The selected handler is finally scheduled for execution.

Version:
$Date: 2005-09-16 15:54:46 +0200 (ven, 16 set 2005) $ $Revision: 5780 $
Author:
Giovanni Caire - TILab Torino
See Also:
Serialized Form

Field Summary
static int SELECTION_NOK
          Value returned by onEnd method if no handler was found mapped to the key
static int SELECTION_OK
          Value returned by onEnd method if an handler was found mapped to the key
 
Fields inherited from class jade.core.behaviours.FSMBehaviour
currentName, lastStates
 
Fields inherited from class jade.core.behaviours.Behaviour
myAgent
 
Constructor Summary
HandlerSelector(Agent a, DataStore s, java.lang.Object accessKey)
          Constructor for this HandlerSelector.
 
Method Summary
protected abstract  java.lang.Object getSelectionKey(java.lang.Object selectionVar)
          Subclasses must provide a concrete implementation for this method.
 void registerHandler(java.lang.Object key, Behaviour h)
          Register the bounding between an handler and a key.
 
Methods inherited from class jade.core.behaviours.FSMBehaviour
checkTermination, deregisterState, forceTransitionTo, getChildren, getCurrent, getLastExitValue, getName, getPrevious, getState, handleInconsistentFSM, handleStateEntered, onEnd, registerDefaultTransition, registerDefaultTransition, registerFirstState, registerLastState, registerState, registerTransition, registerTransition, reset, resetStates, scheduleFirst, scheduleNext
 
Methods inherited from class jade.core.behaviours.CompositeBehaviour
action, block, done, resetChildren, restart, setAgent
 
Methods inherited from class jade.core.behaviours.Behaviour
block, getBehaviourName, getDataStore, getParent, isRunnable, onStart, root, setBehaviourName, setDataStore
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SELECTION_OK

public static final int SELECTION_OK
Value returned by onEnd method if an handler was found mapped to the key

See Also:
Constant Field Values

SELECTION_NOK

public static final int SELECTION_NOK
Value returned by onEnd method if no handler was found mapped to the key

See Also:
Constant Field Values
Constructor Detail

HandlerSelector

public HandlerSelector(Agent a,
                       DataStore s,
                       java.lang.Object accessKey)
Constructor for this HandlerSelector.

Parameters:
a - is a reference to the Agent object
s - is the DataStore where the object can be retrieved from
accessKey - is the key to get the proper object from the DataStore, this is the object that will be later passed as argument to the method getSelectionKey
See Also:
getSelectionKey(Object)
Method Detail

getSelectionKey

protected abstract java.lang.Object getSelectionKey(java.lang.Object selectionVar)
Subclasses must provide a concrete implementation for this method. It must return the key to which the handler was bound.

Parameters:
selectionVar - the object retrieved from the datastore at the accessKey passed in the constructor
Returns:
the key to which the handler was bound

registerHandler

public void registerHandler(java.lang.Object key,
                            Behaviour h)
Register the bounding between an handler and a key.

Parameters:
key - this is the key that must be later returned by the method getSelectionKey when the passed Behaviour must be selected
h - the handler for this key


JADE