Package io.servicetalk.http.utils
Class BeforeFinallyHttpOperator
- java.lang.Object
-
- io.servicetalk.http.utils.BeforeFinallyHttpOperator
-
- All Implemented Interfaces:
SingleOperator<StreamingHttpResponse,StreamingHttpResponse>
,java.util.function.Function<SingleSource.Subscriber<? super StreamingHttpResponse>,SingleSource.Subscriber<? super StreamingHttpResponse>>
public final class BeforeFinallyHttpOperator extends java.lang.Object implements SingleOperator<StreamingHttpResponse,StreamingHttpResponse>
Helper operator for signaling the end of an HTTP Request/Response cycle.StreamingHttpRequest
andStreamingHttpResponse
are nested sources (Single
of meta-data containing a payloadPublisher
), 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 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
Constructors Constructor Description BeforeFinallyHttpOperator(TerminalSignalConsumer beforeFinally)
Create a new instance.BeforeFinallyHttpOperator(java.lang.Runnable beforeFinally)
Create a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SingleSource.Subscriber<? super StreamingHttpResponse>
apply(SingleSource.Subscriber<? super StreamingHttpResponse> subscriber)
Implementation of this operator.
-
-
-
Constructor Detail
-
BeforeFinallyHttpOperator
public BeforeFinallyHttpOperator(TerminalSignalConsumer beforeFinally)
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(java.lang.Runnable beforeFinally)
Create a new instance.- Parameters:
beforeFinally
- the callback which is executed just once whenever the sources reach a terminal state across both sources.
-
-
Method Detail
-
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 interfacejava.util.function.Function<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.
-
-