public abstract class AbstractEvent extends Observable implements Event, Comparable<AbstractEvent>
Event#addEventObserver(EventObserver)
,
Event#removeEventObserver(EventObserver)
,
Event.getEventType()
.
In addition, it provides the method fireEvent()
which calls
EventObserver.notifyEventOccurred(String,Event,Object)
for all listeners. To create an Event
, create a subclass of AbstractEvent
and implement Event.isRecurring()
and Event.start()
. A good
example of this can be seen in TimeEvent
.Modifier and Type | Field and Description |
---|---|
protected PolicyAgentInterface |
agent
The agent that this event is to be queued to when it's
Event.start() ed. |
protected boolean |
fired
Initialized to false and set to true when
fireEvent()
is called. |
(package private) int |
id
The unique ID of this event.
|
private TreeMap<String,String> |
params
A map of key/value pairs to be used by users to help identify this event
|
(package private) int |
priority |
(package private) long |
queueTime
The time the event was placed on the
EventQueue |
private String |
type
The type of this event.
|
private static int |
uniqueID |
DEFAULT_PRIORITY, FIRE_EVENT, HIGHEST_PRIORITY
Constructor and Description |
---|
AbstractEvent(String newType,
PolicyAgentInterface agent)
Creates a new AbstractEvent class with the specified type.
|
Modifier and Type | Method and Description |
---|---|
AbstractEvent |
clone() |
int |
compareTo(AbstractEvent o) |
void |
delete()
Removes this element from the
#allEvents . |
void |
fireEvent()
This method calls
EventObserver.notifyEventOccurred(String, Event, Object) for all
observers that have been registered via Observable.addObserver(Observer) . |
String |
getEventType()
This method returns the type of this event.
|
int |
getID() |
String |
getOwnerConversationID()
conversationID getter
|
String |
getParameter(String key)
Retrieves a parameter of this object.
|
int |
getPriority()
Indicates the priority of the event
|
long |
getQueueTime()
Used by the EventQueue to set the time this event was queued
|
boolean |
hasFired()
Subclasses should be sure to either call
fireEvent() ,
or specifically set fired to true if they don't call fireEvent() . |
Set<String> |
keySet() |
void |
setOwnerConversationID(String id)
conversationID setter
|
void |
setParameter(String key,
String value)
Add the key/value pair to the parameters associated with this event.
|
void |
setParameters(Map<String,String> list)
Add the key/value pairs in list to the parameters associated with this event.
|
int |
setPriority(int priority)
Sets the priority of the event
|
void |
setQueueTime(long time)
Used by the EventQueue to sort events
|
String |
toString() |
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addObserver, countObservers, deleteObserver, isRecurring, start
private String type
long queueTime
EventQueue
private static int uniqueID
int priority
int id
protected PolicyAgentInterface agent
Event.start()
ed.protected boolean fired
fireEvent()
is called.public AbstractEvent(String newType, PolicyAgentInterface agent)
newType
- The type (from the agent ontology) of the new event.agent
- The agent that will receive the event.public int compareTo(AbstractEvent o)
compareTo
in interface Comparable<AbstractEvent>
public void delete()
#allEvents
.public final String getEventType()
Event
getEventType
in interface Event
public boolean hasFired()
fireEvent()
,
or specifically set fired
to true if they don't call fireEvent()
.fireEvent()
method called.public void fireEvent()
EventObserver.notifyEventOccurred(String, Event, Object)
for all
observers that have been registered via Observable.addObserver(Observer)
.
This method should only be
called by the agent. To indicate that an event has occurred, the event
should be enqueued in the agent's queue using
PolicyAgentInterface.queueEvent(Event)
.public int getPriority()
Event
getPriority
in interface Event
public int setPriority(int priority)
Event
setPriority
in interface Event
public long getQueueTime()
Event
getQueueTime
in interface Event
public void setQueueTime(long time)
Event
setQueueTime
in interface Event
time
- public String getOwnerConversationID()
getOwnerConversationID
in interface Event
public void setOwnerConversationID(String id) throws IllegalOperationException
setOwnerConversationID
in interface Event
id
- IllegalOperationException
public int getID()
public void setParameters(Map<String,String> list)
setParameters
in interface Event
list
- key/value pairspublic void setParameter(String key, String value)
setParameter
in interface Event
setParameter
in interface Describable
key
- the key name.value
- the value associated with the key.public String getParameter(String key)
Describable
getParameter
in interface Event
getParameter
in interface Describable
key
- the key namepublic Set<String> keySet()
keySet
in interface Describable
public AbstractEvent clone()
clone
in interface Describable
clone
in class Object