T - the element typepublic class AsyncSubject<T> extends java.lang.Object implements Subject<T,T>
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
done
Indicator that the source finished.
|
protected java.lang.Throwable |
error
The exception produced.
|
protected boolean |
hasValue
Indication that a value was produced.
|
protected java.util.concurrent.locks.Lock |
lock
The lock.
|
protected java.util.Map<java.io.Closeable,Observer<? super T>> |
observers
The map of registered observers.
|
protected T |
value
The last value produced.
|
| Constructor and Description |
|---|
AsyncSubject()
Creates an AsyncSubject with a fair reentrant lock.
|
AsyncSubject(java.util.concurrent.locks.Lock lock)
Creates an AsyncSubject with the supplied lock.
|
| Modifier and Type | Method and Description |
|---|---|
void |
error(java.lang.Throwable ex)
An exception is received.
|
void |
finish()
No more values to expect.
|
T |
get()
Returns the result of the asynchronous operation, throws
a RuntimeException if the operation had errors, or throws NoSuchElementException if no result
was produced, waiting indefinitely if necessary.
|
T |
get(long time,
java.util.concurrent.TimeUnit unit)
Returns the result of the asynchronous operation, throws
its exception, throws NoSuchElementException if no result
was produced or throws TimeoutException in case of timeout, waiting at most the specified time.
|
Option<T> |
getOption()
Returns the results of the asynchronous operation in the form
of an option, blocking and waiting indefinitely if necessary.
|
Option<T> |
getOption(long time,
java.util.concurrent.TimeUnit unit)
Returns the results of the asynchronous operation in the form
of an option, waiting at most the supplied amount of time,
returning null if timeout occurred.
|
boolean |
isDone() |
void |
next(T value)
The next value is received.
|
java.io.Closeable |
register(Observer<? super T> observer)
Registers an observer for the notification of Ts.
|
protected void |
unregister(java.io.Closeable c)
Remove the registration of the observable identified by the closeable.
|
@Nonnull protected final java.util.concurrent.locks.Lock lock
protected boolean hasValue
@Nullable protected T value
@Nullable protected java.lang.Throwable error
protected boolean done
public AsyncSubject()
public AsyncSubject(java.util.concurrent.locks.Lock lock)
lock - the lock to usepublic void error(@Nonnull
java.lang.Throwable ex)
BaseObservererror in interface BaseObserverex - the exceptionpublic void finish()
BaseObserverfinish in interface BaseObserverpublic void next(T value)
Observer@Nonnull
public java.io.Closeable register(@Nonnull
Observer<? super T> observer)
Observableregister in interface Observable<T>observer - the observer of Ts or any supertype of itprotected void unregister(@Nonnull
java.io.Closeable c)
c - the registration token to removepublic boolean isDone()
@Nonnull public Option<T> getOption() throws java.lang.InterruptedException
java.lang.InterruptedException - in case the wait was interrupted@Nullable public Option<T> getOption(long time, @Nonnull java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
time - the time valueunit - the time unitjava.lang.InterruptedException - in case the wait was interruptedpublic T get() throws java.lang.InterruptedException
java.lang.InterruptedException - in case the wait was interruptedpublic T get(long time, @Nonnull java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
time - the time to waitunit - the time unitjava.lang.InterruptedException - in case the wait was interruptedjava.util.concurrent.TimeoutException - in case the wait timed out