Class EventManger<K,​R,​E extends java.lang.Exception>

  • 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 java.lang.Exception>
    extends java.lang.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 java.lang.Exception>  
    • Constructor Summary

      Constructors 
      Constructor Description
      EventManger()  
    • Method Detail

      • performActionAndWaitForEvent

        public R performActionAndWaitForEvent​(K eventKey,
                                              long timeout,
                                              EventManger.Callback<E> action)
                                       throws java.lang.InterruptedException,
                                              E extends java.lang.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:
        java.lang.InterruptedException - if interrupted while waiting for the event.
        E - depending on the concrete use case.
        E extends java.lang.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 with performActionAndWaitForEvent(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.