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 java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ScatterGatherHelper.Builder<H,P extends ResourcePath<K>,K,R,HTTP_REQUEST extends BasicRequest,HTTP_RESPONSE,HTTP_RESPONSE_STATUS>
-
Constructor Summary
Constructors Modifier Constructor Description protected
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, java.util.Optional<ResponseAggregatorFactory<BASIC_HTTP_REQUEST,HTTP_RESPONSE>> responseAggregatorFactory, java.util.function.Function<Headers,java.lang.Long> requestTimeout, LongTailRetrySupplier<P,K> longTailRetrySupplier, java.util.function.Function<BasicRequest,Metrics> metricsProvider, java.util.function.BiFunction<Headers,Metrics,Headers> metricsDecorator, java.util.function.Function<Headers,Metrics> responseMetrics, java.util.function.Function<P,ScatterGatherStats> scatterGatherStatsProvider, long defaultTimeoutMillis, long dispatchMinimumMillis, long longTailMinimumMillis, java.util.List<Pair<java.lang.String,java.util.function.Supplier<?>>> beforeHttpServerCodec, java.util.List<Pair<java.lang.String,java.util.function.Supplier<?>>> beforeChunkAggregator, java.util.List<Pair<java.lang.String,java.util.function.Supplier<?>>> beforeIdleStateHandler, java.util.List<Pair<java.lang.String,java.util.function.Supplier<?>>> beforeHttpRequestHandler, java.util.function.IntPredicate successCodePredicate, RequestRetriableChecker<P,R,HTTP_RESPONSE_STATUS> requestRetriableChecker, boolean enableStackTraceResponseForException, java.util.function.BooleanSupplier enableRetryRequestAlwaysUseADifferentHost, java.util.function.BooleanSupplier disableRetryOnTimeout, java.util.function.BooleanSupplier isReqRedirectionAllowedForQuery)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description HTTP_RESPONSE
aggregateResponse(BASIC_HTTP_REQUEST request, Metrics metrics, java.util.List<HTTP_RESPONSE> responses, ResponseAggregatorFactory<BASIC_HTTP_REQUEST,HTTP_RESPONSE> defaultAggregator)
static ScatterGatherHelper.Builder<?,?,?,?,?,?,?>
builder()
void
decorateResponse(Headers responseHeaders, Headers requestHeaders, Metrics metrics)
boolean
disableRetryOnTimeout()
void
dispatch(Scatter<H,P,K> scatter, ScatterGatherRequest<H,K> part, P path, BASIC_HTTP_REQUEST request, AsyncPromise<H> hostSelected, AsyncPromise<java.util.List<HTTP_RESPONSE>> responseFuture, AsyncPromise<HTTP_RESPONSE_STATUS> retryFuture, AsyncFuture<java.lang.Void> timeoutFuture, java.util.concurrent.Executor contextExecutor)
Netty
dispatcherNettyVersion()
java.util.concurrent.CompletionStage<java.lang.String>
findPartitionName(java.lang.String resourceName, K key)
void
forEachBeforeChunkAggregator(java.util.function.Consumer<Pair<java.lang.String,?>> consumer)
void
forEachBeforeHttpRequestHandler(java.util.function.Consumer<Pair<java.lang.String,?>> consumer)
void
forEachBeforeHttpServerCodec(java.util.function.Consumer<Pair<java.lang.String,?>> consumer)
void
forEachBeforeIdleStateHandler(java.util.function.Consumer<Pair<java.lang.String,?>> consumer)
long
getDefaultTimeoutMillis()
long
getDispatchMinimumMillis()
long
getLongTailMinimumMillis()
AsyncFuture<java.util.function.LongSupplier>
getLongTailRetryMilliseconds(P path, BasicRequest request)
AsyncFuture<java.util.function.LongSupplier>
getLongTailRetryMilliseconds(P path, java.lang.String methodName)
long
getRequestTimeout(Headers headers)
ScatterGatherStats
getScatterGatherStatsByPath(P path)
Metrics
initializeMetrics(BasicRequest request)
boolean
isEnableRetryRequestAlwaysUseADifferentHost()
boolean
isEnableStackTraceResponseForException()
boolean
isHostHealthy(H hostName, java.lang.String partitionName)
To check if a host is healthy/responsive.boolean
isReqRedirectionAllowedForQuery()
boolean
isRequestRetriable(P path, R role, HTTP_RESPONSE_STATUS status)
boolean
isSuccessStatus(int code)
P
parseResourceUri(java.lang.String uri, BASIC_HTTP_REQUEST request)
R
parseRoles(java.lang.String requestMethod, Headers headers)
Metrics
responseMetrics(Headers headers)
java.util.concurrent.CompletionStage<Scatter<H,P,K>>
scatter(java.lang.String requestMethod, P path, Headers headers, HostHealthMonitor<H> hostHealthMonitor, Metrics metrics, java.lang.String initialHost)
void
setDefaultTimeoutMillis(long timeoutMillis)
void
setDispatchMinimumMillis(long value)
void
setLongTailMinimumMillis(long value)
-
-
-
Constructor Detail
-
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 java.util.Optional<ResponseAggregatorFactory<BASIC_HTTP_REQUEST,HTTP_RESPONSE>> responseAggregatorFactory, @Nonnull java.util.function.Function<Headers,java.lang.Long> requestTimeout, @Nonnull LongTailRetrySupplier<P,K> longTailRetrySupplier, @Nonnull java.util.function.Function<BasicRequest,Metrics> metricsProvider, @Nonnull java.util.function.BiFunction<Headers,Metrics,Headers> metricsDecorator, @Nonnull java.util.function.Function<Headers,Metrics> responseMetrics, @Nonnull java.util.function.Function<P,ScatterGatherStats> scatterGatherStatsProvider, long defaultTimeoutMillis, long dispatchMinimumMillis, long longTailMinimumMillis, @Nonnull java.util.List<Pair<java.lang.String,java.util.function.Supplier<?>>> beforeHttpServerCodec, @Nonnull java.util.List<Pair<java.lang.String,java.util.function.Supplier<?>>> beforeChunkAggregator, @Nonnull java.util.List<Pair<java.lang.String,java.util.function.Supplier<?>>> beforeIdleStateHandler, @Nonnull java.util.List<Pair<java.lang.String,java.util.function.Supplier<?>>> beforeHttpRequestHandler, @Nonnull java.util.function.IntPredicate successCodePredicate, @Nonnull RequestRetriableChecker<P,R,HTTP_RESPONSE_STATUS> requestRetriableChecker, boolean enableStackTraceResponseForException, @Nonnull java.util.function.BooleanSupplier enableRetryRequestAlwaysUseADifferentHost, @Nonnull java.util.function.BooleanSupplier disableRetryOnTimeout, @Nonnull java.util.function.BooleanSupplier isReqRedirectionAllowedForQuery)
-
-
Method Detail
-
forEachBeforeHttpServerCodec
public void forEachBeforeHttpServerCodec(@Nonnull java.util.function.Consumer<Pair<java.lang.String,?>> consumer)
-
forEachBeforeChunkAggregator
public void forEachBeforeChunkAggregator(@Nonnull java.util.function.Consumer<Pair<java.lang.String,?>> consumer)
-
forEachBeforeIdleStateHandler
public void forEachBeforeIdleStateHandler(@Nonnull java.util.function.Consumer<Pair<java.lang.String,?>> consumer)
-
forEachBeforeHttpRequestHandler
public void forEachBeforeHttpRequestHandler(@Nonnull java.util.function.Consumer<Pair<java.lang.String,?>> consumer)
-
parseResourceUri
@Nonnull public final P parseResourceUri(@Nonnull java.lang.String uri, @Nonnull BASIC_HTTP_REQUEST request) throws RouterException
- Throws:
RouterException
-
isHostHealthy
public final boolean isHostHealthy(@Nonnull H hostName, @Nonnull java.lang.String partitionName)
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
public final AsyncFuture<java.util.function.LongSupplier> getLongTailRetryMilliseconds(P path, java.lang.String methodName)
-
getLongTailRetryMilliseconds
public final AsyncFuture<java.util.function.LongSupplier> getLongTailRetryMilliseconds(P path, BasicRequest request)
-
dispatch
public final void dispatch(@Nonnull Scatter<H,P,K> scatter, @Nonnull ScatterGatherRequest<H,K> part, @Nonnull P path, @Nonnull BASIC_HTTP_REQUEST request, @Nonnull AsyncPromise<H> hostSelected, @Nonnull AsyncPromise<java.util.List<HTTP_RESPONSE>> responseFuture, @Nonnull AsyncPromise<HTTP_RESPONSE_STATUS> retryFuture, @Nonnull AsyncFuture<java.lang.Void> timeoutFuture, @Nonnull java.util.concurrent.Executor contextExecutor) throws RouterException
- Throws:
RouterException
-
dispatcherNettyVersion
public Netty dispatcherNettyVersion()
-
scatter
@Nonnull public java.util.concurrent.CompletionStage<Scatter<H,P,K>> scatter(@Nonnull java.lang.String requestMethod, @Nonnull P path, @Nonnull Headers headers, @Nonnull HostHealthMonitor<H> hostHealthMonitor, Metrics metrics, java.lang.String initialHost) throws RouterException
- Throws:
RouterException
-
aggregateResponse
@Nonnull public HTTP_RESPONSE aggregateResponse(@Nonnull BASIC_HTTP_REQUEST request, Metrics metrics, @Nonnull java.util.List<HTTP_RESPONSE> responses, @Nonnull ResponseAggregatorFactory<BASIC_HTTP_REQUEST,HTTP_RESPONSE> defaultAggregator)
-
findPartitionName
public java.util.concurrent.CompletionStage<java.lang.String> findPartitionName(java.lang.String resourceName, K key)
-
getRequestTimeout
public long getRequestTimeout(@Nonnull Headers headers)
-
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
public void decorateResponse(@Nonnull Headers responseHeaders, @Nonnull Headers requestHeaders, Metrics metrics)
-
initializeMetrics
public Metrics initializeMetrics(@Nonnull BasicRequest request)
-
getScatterGatherStatsByPath
@Nonnull public ScatterGatherStats getScatterGatherStatsByPath(P path)
-
builder
public static ScatterGatherHelper.Builder<?,?,?,?,?,?,?> builder()
-
isSuccessStatus
public boolean isSuccessStatus(int code)
-
isRequestRetriable
public boolean isRequestRetriable(@Nonnull P path, @Nonnull R role, @Nonnull HTTP_RESPONSE_STATUS status)
-
-