jade.util
Class Event

java.lang.Object
  |
  +--java.util.EventObject
        |
        +--jade.util.Event
All Implemented Interfaces:
java.io.Serializable

public class Event
extends java.util.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 Summary
protected  int type
          The type of this event.
 
Fields inherited from class java.util.EventObject
source
 
Constructor Summary
Event(int type, java.lang.Object source)
          Construct an Event of a given type produced by the indicated source
Event(int type, java.lang.Object source, java.lang.Object info)
          Construct an Event of a given type produced by the indicated source and carrying a given information.
 
Method Summary
 void addParameter(java.lang.Object obj)
          Add a parameter to this Event object
 java.lang.Object getParameter(int index)
          Retrieve an element of the event parameter list.
 int getType()
          Retrieve the type of this event.
 void notifyProcessed(java.lang.Object result)
          Wakes up threads waiting for the processing of this Event object within the waitUntilProcessed() method.
 void resetProcessed()
          Reset the "processed" status of this Event
 java.lang.Object waitUntilProcessed()
          Blocks the calling thread until the notifyProcessed() method is called.
 
Methods inherited from class java.util.EventObject
getSource, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

protected int type
The type of this event.

Constructor Detail

Event

public Event(int type,
             java.lang.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,
             java.lang.Object source,
             java.lang.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(java.lang.Object obj)
Add a parameter to this Event object

Parameters:
obj - The parameter to be added

getParameter

public java.lang.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 java.lang.Object waitUntilProcessed()
                                    throws java.lang.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.
java.lang.InterruptedException

notifyProcessed

public void notifyProcessed(java.lang.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.

resetProcessed

public void resetProcessed()
Reset the "processed" status of this Event



JADE