E - the element typepublic final class BlockingSink<E> extends Object implements Producer, Subscription, Trackable, Consumer<E>, Closeable
Subscriber or Processor.
The BlockingSink keeps track of the decorated Subscriber demand. Therefore any emission can be
safely sent to
the delegate
Subscriber by using submit(E) to block on backpressure (missing demand) or emit(E) to
never block and return instead an BlockingSink.Emission status.
The emitter is itself a Subscriber that will request an unbounded value if subscribed.| Modifier and Type | Class and Description |
|---|---|
static class |
BlockingSink.Emission
An acknowledgement signal returned by
emit(E). |
UNSPECIFIED| Modifier | Constructor and Description |
|---|---|
protected |
BlockingSink(Subscriber<? super E> actual) |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(E e) |
void |
cancel() |
void |
close() |
void |
complete() |
static <E> BlockingSink<E> |
create(Subscriber<? super E> subscriber)
|
static <E> BlockingSink<E> |
create(Subscriber<? super E> subscriber,
boolean autostart)
|
Subscriber<? super E> |
downstream()
Return the direct data receiver.
|
BlockingSink.Emission |
emit(E data)
A non-blocking
Subscriber.onNext(Object) that will return a status
BlockingSink.Emission. |
void |
error(Throwable error)
Try calling
Subscriber.onError(Throwable) on the delegate
Subscriber. |
BlockingSink.Emission |
finish()
Try emitting
complete() to the decorated Subscriber. |
long |
getCapacity()
Return defined element capacity
|
Throwable |
getError()
Current error if any, default to null
|
boolean |
hasFailed() |
boolean |
hasRequested() |
boolean |
isCancelled() |
void |
next(E t)
Try emitting, might throw an unchecked exception.
|
void |
request(long n) |
long |
requestedFromDownstream()
Return defined element capacity, used to drive new
Subscription request needs. |
void |
start()
Subscribe the decorated actual
Subscriber.onSubscribe(Subscription). |
void |
stop()
Marks the emitter as terminated without completing downstream
|
long |
submit(E data)
Blocking
Subscriber.onNext(Object) call with an infinite wait on backpressure. |
long |
submit(E data,
long timeout)
Blocking
Subscriber.onNext(Object) call with a timed wait on backpressure. |
long |
submit(E data,
long timeout,
Predicate<E> dropPredicate)
Blocking
Subscriber.onNext(Object) call with a timed wait on backpressure. |
long |
submit(E data,
long timeout,
TimeUnit unit)
Blocking
Subscriber.onNext(Object) call with a timed wait on backpressure. |
long |
submit(E data,
long timeout,
TimeUnit unit,
Predicate<E> dropPredicate)
Blocking
Subscriber.onNext(Object) call with a timed wait on backpressure. |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitexpectedFromUpstream, getPending, isStarted, isTerminated, limitprotected BlockingSink(Subscriber<? super E> actual)
public static <E> BlockingSink<E> create(Subscriber<? super E> subscriber, boolean autostart)
BlockingSink to safely signal a target Subscriber or Processor.
The subscriber will be immediately started only if the autostart property is true. via
Subscriber.onSubscribe(Subscription) as the
result of
this call.E - the reified Subscriber typesubscriber - the decorated Subscriberautostart - true if Subscriber.onSubscribe(Subscription) is invoked during this callBlockingSinkpublic static <E> BlockingSink<E> create(Subscriber<? super E> subscriber)
BlockingSink to safely signal a target Subscriber or Processor.
The actual will be immediately started via Subscriber.onSubscribe(Subscription) as the result of
this call.E - the reified Subscriber typesubscriber - the decorated SubscriberBlockingSinkpublic void cancel()
cancel in interface Subscriptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic Subscriber<? super E> downstream()
Producerdownstream in interface Producerpublic void next(E t)
t - the value to emit, not nullRuntimeException - the unchecked exception in case of error (eg.
IllegalStateException if emission has failed)Subscriber.onNext(Object)public BlockingSink.Emission emit(E data)
Subscriber.onNext(Object) that will return a status
BlockingSink.Emission. The status will
indicate if the decorated
actual is backpressuring this BlockingSink and if it has previously been terminated successfully or
not.data - the data to signalBlockingSink.Emission statuspublic void error(Throwable error)
Subscriber.onError(Throwable) on the delegate
Subscriber. This method might fail itself with an
unchecked exception if an error has already been recorded or it
has previously been terminated via cancel(), finish() or complete().error - the exception to signalpublic BlockingSink.Emission finish()
complete() to the decorated Subscriber. The completion might not return a
successful BlockingSink.Emission.isOk() if this BlockingSink was previously terminated or the delegate
failed consuming the signal.BlockingSink.Emission statuspublic long getCapacity()
TrackablegetCapacity in interface Trackablepublic Throwable getError()
Trackablepublic boolean hasFailed()
BlockingSink has observed any errorpublic boolean hasRequested()
Subscriber is actively demandingpublic boolean isCancelled()
isCancelled in interface Trackablepublic void complete()
Subscriber.onComplete()public void request(long n)
request in interface Subscriptionpublic long requestedFromDownstream()
TrackableSubscription request needs.
This is the maximum in-flight data allowed to transit to this elements.requestedFromDownstream in interface Trackablepublic void start()
Subscriber.onSubscribe(Subscription). If called twice, the current BlockingSink might be
cancelled as per Reactive Streams Specification enforce.public void stop()
public long submit(E data)
Subscriber.onNext(Object) call with an infinite wait on backpressure.data - the data to signalpublic long submit(E data, long timeout)
Subscriber.onNext(Object) call with a timed wait on backpressure.data - the data to signaltimeout - the maximum waiting time in milliseconds before giving uppublic long submit(E data, long timeout, Predicate<E> dropPredicate)
Subscriber.onNext(Object) call with a timed wait on backpressure. A retry predicate will
evaluate when a timeout occurs, returning true will re-schedule an emission while false will drop the signal.data - the data to signaltimeout - the maximum waiting time in milliseconds before giving updropPredicate - the dropped signal callback evaluating if retry should occur or notpublic long submit(E data, long timeout, TimeUnit unit)
Subscriber.onNext(Object) call with a timed wait on backpressure.data - the data to signaltimeout - the maximum waiting time in given unit before giving upunit - the waiting time unitpublic long submit(E data, long timeout, TimeUnit unit, Predicate<E> dropPredicate)
Subscriber.onNext(Object) call with a timed wait on backpressure. A retry predicate will
evaluate when a timeout occurs, returning true will re-schedule an emission while false will drop the signal.data - the data to signaltimeout - the maximum waiting time in given unit before giving upunit - the waiting time unitdropPredicate - the dropped signal callback evaluating if retry should occur or not