Package jade.util

Class Event

  • All Implemented Interfaces:
    Serializable
    Direct Known Subclasses:
    JADEEvent

    public class Event
    extends EventObject
    This class represents a generic event carrying some information (accessible in the form of Object parameters) and provides support for synchronous processing through the waitUntilProcessed() and notifyProcessed() methods. This class can be effectively used in combination with the InputQueue class to support a synchronization between an external therad (posting events in the InputQueue) and the Agent thread (processing the events).
    Author:
    Giovanni Caire - TILab
    See Also:
    InputQueue, Serialized Form
    • Field Detail

      • type

        protected int type
        The type of this event.
    • Constructor Detail

      • Event

        public Event​(int type,
                     Object source)
        Construct an Event of a given type produced by the indicated source
        Parameters:
        type - The type of the event
        source - The source that generated the event
      • Event

        public Event​(int type,
                     Object source,
                     Object info)
        Construct an Event of a given type produced by the indicated source and carrying a given information.
        Parameters:
        type - The type of the event
        source - The source that generated the event
        info - The information associated to the event. This value is handled as the first parameter of the event and can be accessed using the getParameter(0) method
    • Method Detail

      • getType

        public int getType()
        Retrieve the type of this event.
        Returns:
        the type of this Event object
      • addParameter

        public void addParameter​(Object obj)
        Add a parameter to this Event object
        Parameters:
        obj - The parameter to be added
      • getParameter

        public Object getParameter​(int index)
        Retrieve an element of the event parameter list.
        Parameters:
        index - The index of the parameter to retrieve.
        Returns:
        the index-th parameter of this Event object.
      • waitUntilProcessed

        public Object waitUntilProcessed()
                                  throws InterruptedException
        Blocks the calling thread until the notifyProcessed() method is called.
        Returns:
        the result of the processing of this Event object as set by the notifyProcessed() method.
        Throws:
        InterruptedException
      • waitUntilProcessed

        public Object waitUntilProcessed​(long timeout)
                                  throws InterruptedException
        Blocks the calling thread until the notifyProcessed() method is called.
        Returns:
        the result of the processing of this Event object as set by the notifyProcessed() method.
        Throws:
        InterruptedException - if the timeout expires or the Thread executing this method is interrupted.
      • notifyProcessed

        public void notifyProcessed​(Object result)
        Wakes up threads waiting for the processing of this Event object within the waitUntilProcessed() method.
        Parameters:
        result - The result of the processing. This value is passed to the waked threads as the result of the waitUntilProcessed() method.
      • reset

        public void reset()
        Reset the status of this Event
      • resetProcessed

        public void resetProcessed()
        Deprecated.
        Use reset() instead
        Reset the status of this Event