Package com.linkedin.alpini.router.api
Class ScatterGatherHelper<H,P extends ResourcePath<K>,K,R,BASIC_HTTP_REQUEST extends BasicRequest,HTTP_RESPONSE,HTTP_RESPONSE_STATUS>
java.lang.Object
com.linkedin.alpini.router.api.ScatterGatherHelper<H,P,K,R,BASIC_HTTP_REQUEST,HTTP_RESPONSE,HTTP_RESPONSE_STATUS>
public class ScatterGatherHelper<H,P extends ResourcePath<K>,K,R,BASIC_HTTP_REQUEST extends BasicRequest,HTTP_RESPONSE,HTTP_RESPONSE_STATUS>
extends Object
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
ScatterGatherHelper.Builder<H,
P extends ResourcePath<K>, K, R, HTTP_REQUEST extends BasicRequest, HTTP_RESPONSE, HTTP_RESPONSE_STATUS> -
Constructor Summary
ModifierConstructorDescriptionprotected
ScatterGatherHelper
(ExtendedResourcePathParser<P, K, BASIC_HTTP_REQUEST> pathParser, AsyncPartitionFinder<K> partitionFinder, HostFinder<H, R> hostFinder, HostHealthMonitor<H> hostHealthMonitor, RoleFinder<R> roleFinder, ScatterGatherMode broadcastMode, ScatterGatherMode scatterMode, PartitionDispatchHandler<H, P, K, BASIC_HTTP_REQUEST, HTTP_RESPONSE, HTTP_RESPONSE_STATUS> dispatchHandler, Optional<ResponseAggregatorFactory<BASIC_HTTP_REQUEST, HTTP_RESPONSE>> responseAggregatorFactory, Function<Headers, Long> requestTimeout, LongTailRetrySupplier<P, K> longTailRetrySupplier, Function<BasicRequest, Metrics> metricsProvider, BiFunction<Headers, Metrics, Headers> metricsDecorator, Function<Headers, Metrics> responseMetrics, Function<P, ScatterGatherStats> scatterGatherStatsProvider, long defaultTimeoutMillis, long dispatchMinimumMillis, long longTailMinimumMillis, List<Pair<String, Supplier<?>>> beforeHttpServerCodec, List<Pair<String, Supplier<?>>> beforeChunkAggregator, List<Pair<String, Supplier<?>>> beforeIdleStateHandler, List<Pair<String, Supplier<?>>> beforeHttpRequestHandler, IntPredicate successCodePredicate, RequestRetriableChecker<P, R, HTTP_RESPONSE_STATUS> requestRetriableChecker, boolean enableStackTraceResponseForException, BooleanSupplier enableRetryRequestAlwaysUseADifferentHost, BooleanSupplier disableRetryOnTimeout, BooleanSupplier isReqRedirectionAllowedForQuery) -
Method Summary
Modifier and TypeMethodDescriptionaggregateResponse
(BASIC_HTTP_REQUEST request, Metrics metrics, List<HTTP_RESPONSE> responses, ResponseAggregatorFactory<BASIC_HTTP_REQUEST, HTTP_RESPONSE> defaultAggregator) static ScatterGatherHelper.Builder<?,
?, ?, ?, ?, ?, ?> builder()
void
decorateResponse
(Headers responseHeaders, Headers requestHeaders, Metrics metrics) boolean
final void
dispatch
(Scatter<H, P, K> scatter, ScatterGatherRequest<H, K> part, P path, BASIC_HTTP_REQUEST request, AsyncPromise<H> hostSelected, AsyncPromise<List<HTTP_RESPONSE>> responseFuture, AsyncPromise<HTTP_RESPONSE_STATUS> retryFuture, AsyncFuture<Void> timeoutFuture, Executor contextExecutor) findPartitionName
(String resourceName, K key) void
forEachBeforeChunkAggregator
(Consumer<Pair<String, ?>> consumer) void
forEachBeforeHttpRequestHandler
(Consumer<Pair<String, ?>> consumer) void
forEachBeforeHttpServerCodec
(Consumer<Pair<String, ?>> consumer) void
forEachBeforeIdleStateHandler
(Consumer<Pair<String, ?>> consumer) long
long
long
final AsyncFuture<LongSupplier>
getLongTailRetryMilliseconds
(P path, BasicRequest request) final AsyncFuture<LongSupplier>
getLongTailRetryMilliseconds
(P path, String methodName) long
getRequestTimeout
(Headers headers) getScatterGatherStatsByPath
(P path) initializeMetrics
(BasicRequest request) boolean
boolean
final boolean
isHostHealthy
(H hostName, String partitionName) To check if a host is healthy/responsive.boolean
boolean
isRequestRetriable
(P path, R role, HTTP_RESPONSE_STATUS status) boolean
isSuccessStatus
(int code) final P
parseResourceUri
(String uri, BASIC_HTTP_REQUEST request) parseRoles
(String requestMethod, Headers headers) responseMetrics
(Headers headers) scatter
(String requestMethod, P path, Headers headers, HostHealthMonitor<H> hostHealthMonitor, Metrics metrics, String initialHost) void
setDefaultTimeoutMillis
(long timeoutMillis) void
setDispatchMinimumMillis
(long value) void
setLongTailMinimumMillis
(long value)
-
Constructor Details
-
ScatterGatherHelper
protected ScatterGatherHelper(@Nonnull ExtendedResourcePathParser<P, K, BASIC_HTTP_REQUEST> pathParser, @Nonnull AsyncPartitionFinder<K> partitionFinder, @Nonnull HostFinder<H, R> hostFinder, @Nonnull HostHealthMonitor<H> hostHealthMonitor, @Nonnull RoleFinder<R> roleFinder, @Nonnull ScatterGatherMode broadcastMode, @Nonnull ScatterGatherMode scatterMode, @Nonnull PartitionDispatchHandler<H, P, K, BASIC_HTTP_REQUEST, HTTP_RESPONSE, HTTP_RESPONSE_STATUS> dispatchHandler, @Nonnull Optional<ResponseAggregatorFactory<BASIC_HTTP_REQUEST, HTTP_RESPONSE>> responseAggregatorFactory, @Nonnull Function<Headers, Long> requestTimeout, @Nonnull LongTailRetrySupplier<P, K> longTailRetrySupplier, @Nonnull Function<BasicRequest, Metrics> metricsProvider, @Nonnull BiFunction<Headers, Metrics, Headers> metricsDecorator, @Nonnull Function<Headers, Metrics> responseMetrics, @Nonnull Function<P, ScatterGatherStats> scatterGatherStatsProvider, long defaultTimeoutMillis, long dispatchMinimumMillis, long longTailMinimumMillis, @Nonnull List<Pair<String, Supplier<?>>> beforeHttpServerCodec, @Nonnull List<Pair<String, Supplier<?>>> beforeChunkAggregator, @Nonnull List<Pair<String, Supplier<?>>> beforeIdleStateHandler, @Nonnull List<Pair<String, Supplier<?>>> beforeHttpRequestHandler, @Nonnull IntPredicate successCodePredicate, @Nonnull RequestRetriableChecker<P, R, HTTP_RESPONSE_STATUS> requestRetriableChecker, boolean enableStackTraceResponseForException, @Nonnull BooleanSupplier enableRetryRequestAlwaysUseADifferentHost, @Nonnull BooleanSupplier disableRetryOnTimeout, @Nonnull BooleanSupplier isReqRedirectionAllowedForQuery)
-
-
Method Details
-
forEachBeforeHttpServerCodec
-
forEachBeforeChunkAggregator
-
forEachBeforeIdleStateHandler
-
forEachBeforeHttpRequestHandler
-
parseResourceUri
@Nonnull public final P parseResourceUri(@Nonnull String uri, @Nonnull BASIC_HTTP_REQUEST request) throws RouterException - Throws:
RouterException
-
isHostHealthy
To check if a host is healthy/responsive.- Parameters:
hostName
- the host name, including the service port- Returns:
- the host is healthy or not
-
getLongTailRetryMilliseconds
-
getLongTailRetryMilliseconds
-
dispatch
public final void dispatch(@Nonnull Scatter<H, P, throws RouterExceptionK> scatter, @Nonnull ScatterGatherRequest<H, K> part, @Nonnull P path, @Nonnull BASIC_HTTP_REQUEST request, @Nonnull AsyncPromise<H> hostSelected, @Nonnull AsyncPromise<List<HTTP_RESPONSE>> responseFuture, @Nonnull AsyncPromise<HTTP_RESPONSE_STATUS> retryFuture, @Nonnull AsyncFuture<Void> timeoutFuture, @Nonnull Executor contextExecutor) - Throws:
RouterException
-
dispatcherNettyVersion
-
scatter
@Nonnull public CompletionStage<Scatter<H,P, scatterK>> (@Nonnull String requestMethod, @Nonnull P path, @Nonnull Headers headers, @Nonnull HostHealthMonitor<H> hostHealthMonitor, Metrics metrics, String initialHost) throws RouterException - Throws:
RouterException
-
aggregateResponse
@Nonnull public HTTP_RESPONSE aggregateResponse(@Nonnull BASIC_HTTP_REQUEST request, Metrics metrics, @Nonnull List<HTTP_RESPONSE> responses, @Nonnull ResponseAggregatorFactory<BASIC_HTTP_REQUEST, HTTP_RESPONSE> defaultAggregator) -
findPartitionName
-
getRequestTimeout
-
getDefaultTimeoutMillis
public long getDefaultTimeoutMillis() -
setDefaultTimeoutMillis
public void setDefaultTimeoutMillis(long timeoutMillis) -
getDispatchMinimumMillis
public long getDispatchMinimumMillis() -
setDispatchMinimumMillis
public void setDispatchMinimumMillis(long value) -
getLongTailMinimumMillis
public long getLongTailMinimumMillis() -
setLongTailMinimumMillis
public void setLongTailMinimumMillis(long value) -
isEnableStackTraceResponseForException
public boolean isEnableStackTraceResponseForException() -
isEnableRetryRequestAlwaysUseADifferentHost
public boolean isEnableRetryRequestAlwaysUseADifferentHost() -
disableRetryOnTimeout
public boolean disableRetryOnTimeout() -
isReqRedirectionAllowedForQuery
public boolean isReqRedirectionAllowedForQuery() -
decorateResponse
-
initializeMetrics
-
responseMetrics
-
getScatterGatherStatsByPath
-
builder
-
isSuccessStatus
public boolean isSuccessStatus(int code) -
isRequestRetriable
public boolean isRequestRetriable(@Nonnull P path, @Nonnull R role, @Nonnull HTTP_RESPONSE_STATUS status) -
parseRoles
-