Class HandlerSelector

  • All Implemented Interfaces:
    Serializable, 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$ $Revision$
    Author:
    Giovanni Caire - TILab Torino
    See Also:
    Serialized Form
    • 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,
                               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 Object getSelectionKey​(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​(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