Output, InitialResponse, NextResponse>
- All Implemented Interfaces:
Subscription.request(long) the handler will keep
track of the outstanding count and invoke either
sendInitialCommand(Object, int) or
sendNextCommand(Object, int) depending upon if it is the first request or subsequent.
This handler guarantees that there is only one outstanding request and that if the request amount is larger than the
batch, it will continue to send new commands one at a time until the request amount has been satisfied.
The handler processes each target via the provided
Supplier one by one, exhausting all values from the
target, until there are no more targets left or the publishing has been cancelled by the subscriber.
When a command returns successfully either the
handleInitialResponse(Object, Object) or
handleNextResponse(Object, Object) will be invoked with the response object. The returned entries can then
be emitted by invoking the
onNext(Object) method for each value. Note that the return of
should be checked in case if the
Subscriber has cancelled the publishing of values in the middle.
A command may also encounter a Throwable and it is possible to customize what happens by implementing the
handleThrowableInResponse(Throwable, Object) method. For example you may want to skip the given
Each request is provided a
batchSize argument and the underlying resource should adhere to this,
failure to do so may cause an
OutOfMemoryError, since entries are only emitted to the Subscriber based on the
requested amount, and any additional are enqueued.
This handler also supports
Subscription.cancel() by extending the
sendCancel(Object) command and
the underlying service must be cancelled in an asynchronous and non blocking fashion. Once cancelled this Publisher
will not publish additional values or requests.
Note this handler only supports a single Subscriber for the returned Publisher from
to do so can cause multiple requests and unexpected problems.
Method SummaryModifier and TypeMethodDescription
(long count)This method is invoked every time a new request is sent to the underlying publisher.
protected booleanThis method returns whether this subscription has been cancelled
protected abstract long
protected abstract long
protected voidAllows any implementor to handle what happens when a Throwable is encountered.
protected booleanMethod that should be called for each emitted output value.
run()This is invoked when the Subscription is cancelled
protected abstract void
protected voidMethod to invoke when a given target is found to have been completed and the next target should be used
logprotected static final org.infinispan.commons.logging.Log log
batchSizeprotected final int batchSize
startPublisherpublic org.reactivestreams.Publisher<Output> startPublisher()
runpublic void run()This is invoked when the Subscription is cancelled
- Specified by:
sendCancelprotected abstract void sendCancel
handleThrowableInResponseAllows any implementor to handle what happens when a Throwable is encountered. By default the returned publisher invokes
Subscriber.onError(Throwable)and stops processing. It is possible to ignore the throwable and continue processing by invoking
accept(long)with a value of 0. It may also be required to reset the
currentTargetso it is initialized to the next supplied value.
t- throwable that was encountered
target- the target which was invoked that caused the throwable
acceptpublic void accept
(long count)This method is invoked every time a new request is sent to the underlying publisher. We need to submit a request if there is not a pending one. Whenever requestedAmount is a number greater than 0, that means we must submit or there is a pending one.
- Specified by:
count- request count
onNextprotected boolean onNext
(Output value)Method that should be called for each emitted output value. The returned boolean is whether the handler should continue publishing values or not.
value- value emit to the publisher
- whether to continue emitting values
targetCompleteprotected void targetComplete()Method to invoke when a given target is found to have been completed and the next target should be used
checkCancelledprotected boolean checkCancelled()This method returns whether this subscription has been cancelled