Package jade.util
Class Event
- java.lang.Object
-
- java.util.EventObject
-
- jade.util.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 ofObjectparameters) and provides support for synchronous processing through thewaitUntilProcessed()andnotifyProcessed()methods. This class can be effectively used in combination with theInputQueueclass to support a synchronization between an external therad (posting events in theInputQueue) and the Agent thread (processing the events).- Author:
- Giovanni Caire - TILab
- See Also:
InputQueue, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected inttypeThe type of this event.-
Fields inherited from class java.util.EventObject
source
-
-
Constructor Summary
Constructors Constructor Description Event(int type, Object source)Construct anEventof a given type produced by the indicated sourceEvent(int type, Object source, Object info)Construct anEventof a given type produced by the indicated source and carrying a given information.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddParameter(Object obj)Add a parameter to thisEventobjectObjectgetParameter(int index)Retrieve an element of the event parameter list.intgetType()Retrieve the type of this event.voidnotifyProcessed(Object result)Wakes up threads waiting for the processing of thisEventobject within thewaitUntilProcessed()method.voidreset()Reset the status of thisEventvoidresetProcessed()Deprecated.Usereset()insteadObjectwaitUntilProcessed()Blocks the calling thread until thenotifyProcessed()method is called.ObjectwaitUntilProcessed(long timeout)Blocks the calling thread until thenotifyProcessed()method is called.-
Methods inherited from class java.util.EventObject
getSource, toString
-
-
-
-
Constructor Detail
-
Event
public Event(int type, Object source)Construct anEventof a given type produced by the indicated source- Parameters:
type- The type of the eventsource- The source that generated the event
-
Event
public Event(int type, Object source, Object info)Construct anEventof a given type produced by the indicated source and carrying a given information.- Parameters:
type- The type of the eventsource- The source that generated the eventinfo- The information associated to the event. This value is handled as the first parameter of the event and can be accessed using thegetParameter(0)method
-
-
Method Detail
-
getType
public int getType()
Retrieve the type of this event.- Returns:
- the type of this
Eventobject
-
addParameter
public void addParameter(Object obj)
Add a parameter to thisEventobject- 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
Eventobject.
-
waitUntilProcessed
public Object waitUntilProcessed() throws InterruptedException
Blocks the calling thread until thenotifyProcessed()method is called.- Returns:
- the result of the processing of this
Eventobject as set by thenotifyProcessed()method. - Throws:
InterruptedException
-
waitUntilProcessed
public Object waitUntilProcessed(long timeout) throws InterruptedException
Blocks the calling thread until thenotifyProcessed()method is called.- Returns:
- the result of the processing of this
Eventobject as set by thenotifyProcessed()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 thisEventobject within thewaitUntilProcessed()method.- Parameters:
result- The result of the processing. This value is passed to the waked threads as the result of thewaitUntilProcessed()method.
-
reset
public void reset()
Reset the status of thisEvent
-
resetProcessed
public void resetProcessed()
Deprecated.Usereset()insteadReset the status of thisEvent
-
-