Package org.jivesoftware.smack.util
Class EventManger<K,R,E extends Exception>
- java.lang.Object
-
- org.jivesoftware.smack.util.EventManger<K,R,E>
-
- Type Parameters:
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
The event manager class is used to perform actions and wait for an event, which is usually caused by the action (or maybe never occurs).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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
EventManger.Callback<E extends Exception>
-
Constructor Summary
Constructors Constructor Description EventManger()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Constructor Detail
-
EventManger
public EventManger()
-
-
Method Detail
-
performActionAndWaitForEvent
public R performActionAndWaitForEvent(K eventKey, long timeout, EventManger.Callback<E> action) throws InterruptedException, E extends Exception
Perform an action and wait for an event.The event is signaled with
signalEvent(Object, Object)
.- Parameters:
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.- Returns:
- the event value, may be null.
- Throws:
InterruptedException
- if interrupted while waiting for the event.E
- depending on the concrete use case.E extends Exception
-
signalEvent
public boolean signalEvent(K eventKey, R eventResult)
Signal an event and the event result.This method will return
false
if the event was not created withperformActionAndWaitForEvent(Object, long, Callback)
.- Parameters:
eventKey
- the event key, must not be null.eventResult
- the event result, may be null.- Returns:
- true if the event was found and signaled, false otherwise.
-
-