Class BeforeFinallyHttpOperator
- All Implemented Interfaces:
SingleOperator<StreamingHttpResponse,
,StreamingHttpResponse> Function<SingleSource.Subscriber<? super StreamingHttpResponse>,
SingleSource.Subscriber<? super 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. An important question is when the ownership of the callback is transferred from the
Single
source and the payload Publisher
. In this case ownership is transferred the first time the
payload is subscribed to. This means that if a cancellation of the response Single
occurs after the response
has been emitted but before the message body has been subscribed to, the callback will observe a cancel. However, if
the message payload has been subscribed to, the cancellation of the Single
will have no effect and the result
is dictated by the terminal event of the payload body. If the body is subscribed to multiple times, only the first
subscribe will receive ownership of the terminal events.
// coarse grained, any terminal signal calls the provided `Runnable`
return requester.request(strategy, request)
.beforeOnSubscribe(__ -> tracker.requestStarted())
.liftSync(new BeforeFinallyHttpOperator(tracker::requestFinished));
// fine grained, `tracker` implements `TerminalSignalConsumer`, terminal signal indicated by the callback method
return requester.request(strategy, request)
.beforeOnSubscribe(__ -> tracker.requestStarted())
.liftSync(new BeforeFinallyHttpOperator(tracker));
-
Constructor Summary
ConstructorsConstructorDescriptionBeforeFinallyHttpOperator
(TerminalSignalConsumer beforeFinally) Create a new instance.BeforeFinallyHttpOperator
(TerminalSignalConsumer beforeFinally, boolean discardEventsAfterCancel) Create a new instance.BeforeFinallyHttpOperator
(Runnable beforeFinally) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionapply
(SingleSource.Subscriber<? super StreamingHttpResponse> subscriber) Implementation of this operator.
-
Constructor Details
-
BeforeFinallyHttpOperator
Create a new instance.- Parameters:
beforeFinally
- the callback which is executed just once whenever the sources reach a terminal state across both sources.
-
BeforeFinallyHttpOperator
Create a new instance.- Parameters:
beforeFinally
- the callback which is executed just once whenever the sources reach a terminal state across both sources.
-
BeforeFinallyHttpOperator
public BeforeFinallyHttpOperator(TerminalSignalConsumer beforeFinally, boolean discardEventsAfterCancel) Create a new instance.- Parameters:
beforeFinally
- the callback which is executed just once whenever the sources reach a terminal state across both sources.discardEventsAfterCancel
- iftrue
further events will be discarded if those arrive afterTerminalSignalConsumer.cancel()
is invoked. Otherwise, events may still be delivered if they race with cancellation.
-
-
Method Details
-
apply
public SingleSource.Subscriber<? super StreamingHttpResponse> apply(SingleSource.Subscriber<? super StreamingHttpResponse> subscriber) Description copied from interface:SingleOperator
Implementation of this operator. SeeSingleOperator
for definition of an operator.- Specified by:
apply
in interfaceFunction<SingleSource.Subscriber<? super StreamingHttpResponse>,
SingleSource.Subscriber<? super StreamingHttpResponse>> - Specified by:
apply
in interfaceSingleOperator<StreamingHttpResponse,
StreamingHttpResponse> - Parameters:
subscriber
-SingleSource.Subscriber
that subscribed to this operator.- Returns:
SingleSource.Subscriber
that is used to subscribe to theSingle
that this operator is applied to.
-