public class EventProcessor extends Object
EventHandler
.handleEvent() method, with the event as an argument. An event handler needs to be registered
into the processor to receive the events.
The event is sent to all event handlers registered with the EventProcessor, if its recipient is
null
and it is sent to the particular event handler otherwise.
The event-queue cycle can be paused/un-paused by the setRunning() method. By the default, the
cycle is started running.
The time of currently processed events can be obtained by the getCurrentTime() method.Modifier and Type | Field and Description |
---|---|
protected Queue<Event> |
eventQueue |
Constructor and Description |
---|
EventProcessor() |
Modifier and Type | Method and Description |
---|---|
void |
addEvent(EventHandler eventHandler)
Add an immediate event into the queue of the event processor.
|
void |
addEvent(EventHandler eventHandler,
long deltaTime)
Add an event into the queue of the event processor.
|
void |
addEvent(EventType type,
EventHandler recipient,
String owner,
Object content)
Add an immediate event into the queue of the event processor.
|
void |
addEvent(EventType type,
EventHandler recipient,
String owner,
Object content,
long deltaTime)
Add an event into the queue of the event processor.
|
void |
addEventHandler(EventHandler eventHandler)
Adds an EventHandler to list of all event handlers of this processor.
|
protected void |
breforeRunningTest(Event event) |
void |
clearQueue()
Ends the the event processor by clearing the event queue.
|
protected void |
fireEvent(Event event) |
protected void |
fireEvent(EventType type,
EventHandler recipient,
String owner,
Object content) |
int |
getCurrentQueueLength()
The method can be called from other threads (than the run() method was called).
|
long |
getCurrentTime()
The method can be called from other threads (than the run() method was called).
|
boolean |
isFinished()
The method can be called from other threads (than the run() method was called).
|
boolean |
isRunning()
The method can be called from other threads (than the run() method was called).
|
void |
run() |
void |
setRunning(boolean running)
Method pauses and un-pauses the processing of the events.
|
public void run()
public void clearQueue()
public void addEvent(EventType type, EventHandler recipient, String owner, Object content)
type
- the type of the event (see EventType
)recipient
- the target of the event (use null
for all registered event handlers)owner
- a "deprecated" version of the recipientcontent
- the payload of the event (by the user specified data)public void addEvent(EventType type, EventHandler recipient, String owner, Object content, long deltaTime)
type
- the type of the event (see EventType
)recipient
- the target of the event (use null
for all registered event handlers)owner
- a "deprecated" version of the recipientcontent
- the payload of the event (by the user specified data)deltaTime
- the duration (in milliseconds) from now till the time when the event should take
place (be send to its recipients)public void addEvent(EventHandler eventHandler)
eventHandler
- - through its callback method is informed about end of event.public void addEvent(EventHandler eventHandler, long deltaTime)
eventHandler
- - through its callback method is informed about end of event.deltaTime
- the duration (in milliseconds) from now till the time when the event should take
place (be send to its recipients)public void addEventHandler(EventHandler eventHandler)
eventHandler
- public void setRunning(boolean running)
running
- public boolean isRunning()
public boolean isFinished()
public long getCurrentTime()
public int getCurrentQueueLength()
protected void breforeRunningTest(Event event)
protected void fireEvent(EventType type, EventHandler recipient, String owner, Object content)
protected void fireEvent(Event event)
Copyright © 2017 Agent Technology Center (ATG). All rights reserved.