public interface ServiceClient
HttpClient, but accepts RequestBuilder
instead of Request, and internally handles service location
and retries.
In most cases, this client is further wrapped in a high-level client like
OverlordClient.| Modifier and Type | Field and Description |
|---|---|
static long |
MAX_REDIRECTS |
| Modifier and Type | Method and Description |
|---|---|
<IntermediateType,FinalType> |
asyncRequest(RequestBuilder requestBuilder,
HttpResponseHandler<IntermediateType,FinalType> handler)
Perform a request asynchronously.
|
default <IntermediateType,FinalType> |
request(RequestBuilder requestBuilder,
HttpResponseHandler<IntermediateType,FinalType> handler)
Perform a request synchronously.
|
ServiceClient |
withRetryPolicy(ServiceRetryPolicy retryPolicy)
Returns a copy of this client with a different
ServiceRetryPolicy. |
static final long MAX_REDIRECTS
<IntermediateType,FinalType> com.google.common.util.concurrent.ListenableFuture<FinalType> asyncRequest(RequestBuilder requestBuilder, HttpResponseHandler<IntermediateType,FinalType> handler)
HttpClient.go(org.apache.druid.java.util.http.client.Request, org.apache.druid.java.util.http.client.response.HttpResponseHandler<Intermediate, Final>), the provided "handler" is only used for 2xx responses.
Response codes 1xx, 4xx, and 5xx are retried with backoff according to the client's ServiceRetryPolicy.
If attempts are exhausted, the future will fail with RpcException containing the most recently
encountered error.
Redirects from 3xx responses are followed up to a chain length of MAX_REDIRECTS and do not consume
attempts. Redirects are validated against the targets returned by ServiceLocator: the client will only
follow redirects to targets that appear in ServiceLocations. If the client encounters a redirect to an
unknown target, or if a redirect loop or self-redirect is detected, it is treated as an unavailable service and
an attempt is consumed.
If the service is unavailable at the time an attempt is made, the client will automatically retry based on
ServiceRetryPolicy.retryNotAvailable(). If true, an attempt is consumed and the client will try to locate
the service again on the next attempt. If false, the call immediately returns ServiceNotAvailableException.
If an exception occurs midstream after an OK HTTP response (2xx) then the behavior depends on the handler. If
the handler has not yet returned a finished object, the service client will automatically retry based on the
provided ServiceRetryPolicy. On the other hand, if the handler has returned a finished object, the
service client will not retry. Behavior in this case is up to the caller, who will have already received the
finished object as the future's resolved value.
Resolves to HttpResponseException if the final attempt failed due to a non-OK HTTP server response.
Resolves to ServiceNotAvailableException if the final attempt failed because the service was not
available (i.e. if the locator returned an empty set of locations).
Resolves to ServiceClosedException if the final attempt failed because the service was closed. This is
different from not available: generally, "not available" is a temporary condition whereas "closed" is a
permanent condition.default <IntermediateType,FinalType> FinalType request(RequestBuilder requestBuilder, HttpResponseHandler<IntermediateType,FinalType> handler) throws InterruptedException, ExecutionException
asyncRequest(org.apache.druid.rpc.RequestBuilder, org.apache.druid.java.util.http.client.response.HttpResponseHandler<IntermediateType, FinalType>), except the result is returned synchronously. Any exceptions from the
underlying service call are wrapped in an ExecutionException.ServiceClient withRetryPolicy(ServiceRetryPolicy retryPolicy)
ServiceRetryPolicy.Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.