Class Event<T extends java.lang.Throwable>


  • public class Event<T extends java.lang.Throwable>
    extends java.lang.Object
    An event can be set, cleared, or awaited, similar to Python's threading.event. The key difference is that a waiter may be delivered an exception of parameterized type T.

    Uses Promise under the hood.

    • Constructor Summary

      Constructors 
      Constructor Description
      Event​(java.lang.String name, ExceptionChainer<T> chainer, java.util.concurrent.locks.ReentrantLock lock, LoggerFactory loggerFactory)
      Creates this event with given name, exception chainer, and associated lock.
      Event​(java.lang.String name, ExceptionChainer<T> chainer, LoggerFactory loggerFactory)
      Creates this event with given name and exception chainer.
    • Method Summary

      Modifier and Type Method Description
      void await()
      Await this event to have a definite true or false value.
      void await​(long timeout, java.util.concurrent.TimeUnit unit)
      Await this event to have a definite true or false value, for timeout duration.
      void clear()
      Clear this event.
      void deliverError​(java.lang.Throwable t)
      Deliver the error t (after chaining) to any present or future waiters.
      boolean hasWaiters()  
      boolean inError()  
      boolean isSet()  
      void lock()
      Acquire the lock associated with this event.
      void set()
      Sets this event to be true.
      java.lang.String toString()  
      boolean tryAwait​(long timeout, java.util.concurrent.TimeUnit unit)
      Await this event to have a definite true or false value, for timeout duration.
      void unlock()
      Release the lock associated with this event.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Event

        public Event​(java.lang.String name,
                     ExceptionChainer<T> chainer,
                     LoggerFactory loggerFactory)
        Creates this event with given name and exception chainer. Allocates a new Lock object for this event.
        Parameters:
        name - name of this event
        chainer - ExceptionChainer that will be used for chaining exceptions
      • Event

        public Event​(java.lang.String name,
                     ExceptionChainer<T> chainer,
                     java.util.concurrent.locks.ReentrantLock lock,
                     LoggerFactory loggerFactory)
        Creates this event with given name, exception chainer, and associated lock.
        Parameters:
        name - name of this event
        chainer - ExceptionChainer that will be used for chaining exceptions
        lock - lock to use
    • Method Detail

      • set

        public void set()
        Sets this event to be true. Short for set(true).
      • clear

        public void clear()
        Clear this event. A cleared event !isSet().
      • deliverError

        public void deliverError​(java.lang.Throwable t)
        Deliver the error t (after chaining) to any present or future waiters.
      • await

        public void await()
                   throws T extends java.lang.Throwable
        Await this event to have a definite true or false value.
        Throws:
        T - if another thread meanwhile informs this event of an error
        T extends java.lang.Throwable
      • await

        public void await​(long timeout,
                          java.util.concurrent.TimeUnit unit)
                   throws T extends java.lang.Throwable
        Await this event to have a definite true or false value, for timeout duration.
        Parameters:
        timeout - timeout
        unit - the time unit for the timeout
        Throws:
        T - if another thread meanwhile informs this event of an error, or timeout expires
        T extends java.lang.Throwable
      • tryAwait

        public boolean tryAwait​(long timeout,
                                java.util.concurrent.TimeUnit unit)
                         throws T extends java.lang.Throwable
        Await this event to have a definite true or false value, for timeout duration.

        If the definite value is not available when the timeout expires, returns false.

        Parameters:
        timeout - timeout
        unit - the time unit for the timeout
        Throws:
        T - if another thread meanwhile informs this event of an error
        T extends java.lang.Throwable
      • hasWaiters

        public boolean hasWaiters()
        Returns:
        whether there are any threads waiting on this event to be set.
      • inError

        public boolean inError()
        Returns:
        whether this event is in an error state i.e. has been delivered an error.
      • lock

        public void lock()
        Acquire the lock associated with this event.
      • unlock

        public void unlock()
        Release the lock associated with this event.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object