|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.schmizz.concurrent.Promise<V,T>
public class Promise<V,T extends Throwable>
Represents promised data of the parameterized type V
and allows waiting on it. An exception may also be
delivered to a waiter, and will be of the parameterized type T
.
Constructor Summary | |
---|---|
Promise(String name,
ExceptionChainer<T> chainer)
Creates this promise with given name and exception chainer . |
|
Promise(String name,
ExceptionChainer<T> chainer,
ReentrantLock lock)
Creates this promise with given name , exception chainer , and associated lock . |
Method Summary | |
---|---|
void |
clear()
Clears this promise by setting its value and queued exception to null . |
void |
deliver(V val)
Set this promise's value to val . |
void |
deliverError(Throwable e)
Queues error that will be thrown in any waiting thread or any thread that attempts to wait on this promise hereafter. |
boolean |
hasWaiters()
|
boolean |
inError()
|
boolean |
isDelivered()
|
void |
lock()
Acquire the lock associated with this promise. |
V |
retrieve()
Wait indefinitely for this promise's value to be deliver. |
V |
retrieve(long timeout,
TimeUnit unit)
Wait for timeout duration for this promise's value to be deliver. |
String |
toString()
|
V |
tryRetrieve(long timeout,
TimeUnit unit)
Wait for timeout duration for this promise's value to be deliver. |
void |
unlock()
Release the lock associated with this promise. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Promise(String name, ExceptionChainer<T> chainer)
name
and exception chainer
. Allocates a new lock
object for this promise.
name
- name of this promisechainer
- ExceptionChainer
that will be used for chaining exceptionspublic Promise(String name, ExceptionChainer<T> chainer, ReentrantLock lock)
name
, exception chainer
, and associated lock
.
name
- name of this promisechainer
- ExceptionChainer
that will be used for chaining exceptionslock
- lock to useMethod Detail |
---|
public void deliver(V val)
val
. Any waiters will be delivered this value.
val
- the valuepublic void deliverError(Throwable e)
e
- the errorpublic void clear()
null
.
public V retrieve() throws T extends Throwable
T
- in case another thread informs the promise of an error meanwhile
T extends Throwable
public V retrieve(long timeout, TimeUnit unit) throws T extends Throwable
timeout
duration for this promise's value to be deliver.
timeout
- the timeoutunit
- time unit for the timeout
T
- in case another thread informs the promise of an error meanwhile, or the timeout expires
T extends Throwable
public V tryRetrieve(long timeout, TimeUnit unit) throws T extends Throwable
timeout
duration for this promise's value to be deliver.
If the value is not deliver by the time the timeout expires, returns null
.
timeout
- the timeoutunit
- time unit for the timeout
null
T
- in case another thread informs the promise of an error meanwhile
T extends Throwable
public boolean isDelivered()
public boolean inError()
public boolean hasWaiters()
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 |