public final class BeforeFinallyOnHttpResponseOperator extends java.lang.Object implements SingleOperator<StreamingHttpResponse,StreamingHttpResponse>
StreamingHttpRequest
and StreamingHttpResponse
are nested sources (Single
of meta-data
containing a payload Publisher
), which makes it non-trivial to get a single signal at the end of this
Request/Response cycle. One needs to consider and coordinate between the multitude of outcomes: cancel/success/error
across both sources.
This operator ensures that the provided callback is triggered just once whenever the sources reach a terminal state across both sources.
Example usage tracking the begin and end of a request:
// coarse grained, any terminal signal calls the provided `Runnable`
return requester.request(strategy, request)
.beforeOnSubscribe(__ -> tracker.requestStarted())
.liftSync(new BeforeFinallyOnHttpResponseOperator(tracker::requestFinished));
// fine grained, `tracker` implements `TerminalSignalConsumer`, terminal signal indicated by the callback method
return requester.request(strategy, request)
.beforeOnSubscribe(__ -> tracker.requestStarted())
.liftSync(new BeforeFinallyOnHttpResponseOperator(tracker));
Constructor and Description |
---|
BeforeFinallyOnHttpResponseOperator(java.lang.Runnable beforeFinally)
Create a new instance.
|
BeforeFinallyOnHttpResponseOperator(TerminalSignalConsumer beforeFinally)
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
SingleSource.Subscriber<? super StreamingHttpResponse> |
apply(SingleSource.Subscriber<? super StreamingHttpResponse> subscriber)
Implementation of this operator.
|
public BeforeFinallyOnHttpResponseOperator(TerminalSignalConsumer beforeFinally)
beforeFinally
- the callback which is executed just once whenever the sources reach a terminal state
across both sources.public BeforeFinallyOnHttpResponseOperator(java.lang.Runnable beforeFinally)
beforeFinally
- the callback which is executed just once whenever the sources reach a terminal state
across both sources.public SingleSource.Subscriber<? super StreamingHttpResponse> apply(SingleSource.Subscriber<? super StreamingHttpResponse> subscriber)
SingleOperator
SingleOperator
for definition of an operator.apply
in interface SingleOperator<StreamingHttpResponse,StreamingHttpResponse>
apply
in interface java.util.function.Function<SingleSource.Subscriber<? super StreamingHttpResponse>,SingleSource.Subscriber<? super StreamingHttpResponse>>
subscriber
- SingleSource.Subscriber
that subscribed to this operator.SingleSource.Subscriber
that is used to subscribe to the Single
that this operator is applied to.