|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.schmizz.concurrent.Event<T>
public class Event<T extends Throwable>
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
.
Promise
under the hood.
Constructor Summary | |
---|---|
Event(String name,
ExceptionChainer<T> chainer)
Creates this event with given name and exception chainer . |
|
Event(String name,
ExceptionChainer<T> chainer,
ReentrantLock lock)
Creates this event with given name , exception chainer , and associated lock . |
Method Summary | |
---|---|
void |
await()
Await this event to have a definite true or false value. |
void |
await(long timeout,
TimeUnit unit)
Await this event to have a definite true or false value, for timeout duration. |
void |
clear()
Clear this event. |
void |
deliverError(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 . |
String |
toString()
|
boolean |
tryAwait(long timeout,
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 |
---|
public Event(String name, ExceptionChainer<T> chainer)
name
and exception chainer
. Allocates a new Lock
object for this event.
name
- name of this eventchainer
- ExceptionChainer
that will be used for chaining exceptionspublic Event(String name, ExceptionChainer<T> chainer, ReentrantLock lock)
name
, exception chainer
, and associated lock
.
name
- name of this eventchainer
- ExceptionChainer
that will be used for chaining exceptionslock
- lock to useMethod Detail |
---|
public void set()
true
. Short for set(true)
.
public void clear()
!isSet()
.
public void deliverError(Throwable t)
t
(after chaining) to any present or future waiters.
public boolean isSet()
set()
or deliverError(java.lang.Throwable)
public void await() throws T extends Throwable
true
or false
value.
T
- if another thread meanwhile informs this event of an error
T extends Throwable
public void await(long timeout, TimeUnit unit) throws T extends Throwable
true
or false
value, for timeout
duration.
timeout
- timeoutunit
- the time unit for the timeout
T
- if another thread meanwhile informs this event of an error, or timeout expires
T extends Throwable
public boolean tryAwait(long timeout, TimeUnit unit) throws T extends Throwable
true
or false
value, for timeout
duration.
If the definite value is not available when the timeout expires, returns false
.
timeout
- timeoutunit
- the time unit for the timeout
T
- if another thread meanwhile informs this event of an error
T extends Throwable
public boolean hasWaiters()
public boolean inError()
public void lock()
public void unlock()
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |