Package net.schmizz.concurrent
Class Event<T extends java.lang.Throwable>
- java.lang.Object
-
- net.schmizz.concurrent.Event<T>
-
public class Event<T extends java.lang.Throwable> extends java.lang.ObjectAn event can be set, cleared, or awaited, similar to Python'sthreading.event. The key difference is that a waiter may be delivered an exception of parameterized typeT. UsesPromiseunder 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 givenname, exceptionchainer, and associatedlock.Event(java.lang.String name, ExceptionChainer<T> chainer, LoggerFactory loggerFactory)Creates this event with givennameand exceptionchainer.
-
Method Summary
Modifier and Type Method Description voidawait()Await this event to have a definitetrueorfalsevalue.voidawait(long timeout, java.util.concurrent.TimeUnit unit)Await this event to have a definitetrueorfalsevalue, fortimeoutduration.voidclear()Clear this event.voiddeliverError(java.lang.Throwable t)Deliver the errort(after chaining) to any present or future waiters.booleanhasWaiters()booleaninError()booleanisSet()voidlock()Acquire the lock associated with this event.voidset()Sets this event to betrue.java.lang.StringtoString()booleantryAwait(long timeout, java.util.concurrent.TimeUnit unit)Await this event to have a definitetrueorfalsevalue, fortimeoutduration.voidunlock()Release the lock associated with this event.
-
-
-
Constructor Detail
-
Event
public Event(java.lang.String name, ExceptionChainer<T> chainer, LoggerFactory loggerFactory)Creates this event with givennameand exceptionchainer. Allocates a newLockobject for this event.- Parameters:
name- name of this eventchainer-ExceptionChainerthat 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 givenname, exceptionchainer, and associatedlock.- Parameters:
name- name of this eventchainer-ExceptionChainerthat will be used for chaining exceptionslock- lock to use
-
-
Method Detail
-
set
public void set()
Sets this event to betrue. Short forset(true).
-
clear
public void clear()
Clear this event. A cleared event!isSet().
-
deliverError
public void deliverError(java.lang.Throwable t)
Deliver the errort(after chaining) to any present or future waiters.
-
isSet
public boolean isSet()
- Returns:
- whether this event is in a 'set' state. An event is set by a call to
set()ordeliverError(java.lang.Throwable)
-
await
public void await() throws T extends java.lang.ThrowableAwait this event to have a definitetrueorfalsevalue.
-
await
public void await(long timeout, java.util.concurrent.TimeUnit unit) throws T extends java.lang.ThrowableAwait this event to have a definitetrueorfalsevalue, fortimeoutduration.
-
tryAwait
public boolean tryAwait(long timeout, java.util.concurrent.TimeUnit unit) throws T extends java.lang.ThrowableAwait this event to have a definitetrueorfalsevalue, fortimeoutduration. If the definite value is not available when the timeout expires, returnsfalse.
-
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:
toStringin classjava.lang.Object
-
-