K
- the event key.R
- the event result.E
- the exception which could be thrown by the action.public class EventManger<K,R,E extends Exception> extends Object
Events are distinguished by an unique event key. They can produce an event result, which can simply be null.
The action is able to throw an exception.
Modifier and Type | Class and Description |
---|---|
static interface |
EventManger.Callback<E extends Exception> |
Constructor and Description |
---|
EventManger() |
Modifier and Type | Method and Description |
---|---|
R |
performActionAndWaitForEvent(K eventKey,
long timeout,
EventManger.Callback<E> action)
Perform an action and wait for an event.
|
boolean |
signalEvent(K eventKey,
R eventResult)
Signal an event and the event result.
|
public EventManger()
public R performActionAndWaitForEvent(K eventKey, long timeout, EventManger.Callback<E> action) throws InterruptedException, E extends Exception
The event is signaled with signalEvent(Object, Object)
.
eventKey
- the event key, must not be null.timeout
- the timeout to wait for the event in milliseconds.action
- the action to perform prior waiting for the event, must not be null.InterruptedException
- if interrupted while waiting for the event.E
E extends Exception
public boolean signalEvent(K eventKey, R eventResult)
This method will return false
if the event was not created with
performActionAndWaitForEvent(Object, long, Callback)
.
eventKey
- the event key, must not be null.eventResult
- the event result, may be null.