Class HttpLifecycleObserverServiceFilter
- All Implemented Interfaces:
HttpExecutionStrategyInfluencer,StreamingHttpServiceFilterFactory,ExecutionStrategyInfluencer<HttpExecutionStrategy>
- Direct Known Subclasses:
GrpcLifecycleObserverServiceFilter
The result of the observed behavior will depend on the position of this filter in the execution chain.
This filter is recommended to be appended as one of the first filters using
HttpServerBuilder.appendNonOffloadingServiceFilter(StreamingHttpServiceFilterFactory) method to account for
all work done by other filters and offloading of the requests processing. It can be appended at another position,
considering the following:
- After a tracing filter or any other filter that populates
request context,AsyncContext,MDC, or altersHttpRequestMetaDataif that information has to be available forHttpLifecycleObserver.HttpExchangeObserver. - After
TimeoutHttpRequesterFilterif the timeout event should be observed ascancellationinstead of anerror. - After any filter that can reject requests, like
BasicAuthHttpServiceFilter, if only allowed requests should be observed. - Before any filter that can reject requests, like
BasicAuthHttpServiceFilter, if all incoming requests have to be observed. - Before any filter that populates
response contextor altersHttpResponseMetaDataif that information has to be available forHttpLifecycleObserver.HttpExchangeObserver. - Before any filter that maps/translates
HttpResponseMetaDatainto anexceptionor throws an exception duringresponse payload body transformationif that exception has to be observed byHttpLifecycleObserver.HttpExchangeObserver. - Before any exception mapping filter that maps an
exceptioninto a valid response, likeHttpExceptionMapperServiceFilter, if theHttpLifecycleObserver.HttpExchangeObservershould see what status code is returned to the client. - Using
HttpServerBuilder.appendServiceFilter(StreamingHttpServiceFilterFactory)if an exchange should be observed after it's offloaded from anIoExecutor(if offloading is enabled). - Using
HttpServerBuilder.appendNonOffloadingServiceFilter(Predicate, StreamingHttpServiceFilterFactory)orHttpServerBuilder.appendServiceFilter(Predicate, StreamingHttpServiceFilterFactory)if the observer should be applied conditionally. - As the last
HttpServerBuilder.appendServiceFilter(StreamingHttpServiceFilterFactory)if only service business logic should be observed without accounting for work of any other filters.
HttpLifecycleObserver is to use
HttpServerBuilder.lifecycleObserver(HttpLifecycleObserver).-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance. -
Method Summary
Modifier and TypeMethodDescriptioncreate(StreamingHttpService service) Create aStreamingHttpServiceFilterusing the providedStreamingHttpService.List<? extends HttpLifecycleObserver>Returns theHttpLifecycleObservers used by this filter.final HttpExecutionStrategyReturn anExecutionStrategythat describes the offloads required by the influencer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.servicetalk.http.api.HttpExecutionStrategyInfluencer
influenceStrategy, requiredOffloads
-
Constructor Details
-
HttpLifecycleObserverServiceFilter
Create a new instance.- Parameters:
observer- Theobserverimplementation that consumes HTTP lifecycle events.
-
-
Method Details
-
create
Description copied from interface:StreamingHttpServiceFilterFactoryCreate aStreamingHttpServiceFilterusing the providedStreamingHttpService.- Specified by:
createin interfaceStreamingHttpServiceFilterFactory- Parameters:
service-StreamingHttpServiceto filter- Returns:
StreamingHttpServiceFilterusing the providedStreamingHttpService.
-
lifecycleObservers
Returns theHttpLifecycleObservers used by this filter.- Returns:
- a
ListofHttpLifecycleObservers used by this filter
-
requiredOffloads
Description copied from interface:HttpExecutionStrategyInfluencerReturn anExecutionStrategythat describes the offloads required by the influencer.The provided default implementation requests offloading of all operations. Implementations that require no offloading should be careful to return
HttpExecutionStrategies.offloadNone()rather thanHttpExecutionStrategies.offloadNever(). Implementations should avoid returningHttpExecutionStrategies.defaultStrategy(), instead returning the strategy they require orHttpExecutionStrategies.offloadAll()if offloading for all paths is required (safe default).- Specified by:
requiredOffloadsin interfaceExecutionStrategyInfluencer<HttpExecutionStrategy>- Specified by:
requiredOffloadsin interfaceHttpExecutionStrategyInfluencer- Returns:
- the
ExecutionStrategyrequired by the influencer.
-