Package org.apache.druid.rpc
Interface ServiceClient
- All Known Implementing Classes:
ServiceClientImpl
public interface ServiceClient
Mid-level client that provides an API similar to low-level
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.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescription<IntermediateType,FinalType>
com.google.common.util.concurrent.ListenableFuture<FinalType>asyncRequest(RequestBuilder requestBuilder, HttpResponseHandler<IntermediateType, FinalType> handler) Perform a request asynchronously.default <IntermediateType,FinalType>
FinalTyperequest(RequestBuilder requestBuilder, HttpResponseHandler<IntermediateType, FinalType> handler) Perform a request synchronously.withRetryPolicy(ServiceRetryPolicy retryPolicy) Returns a copy of this client with a differentServiceRetryPolicy.
-
Field Details
-
MAX_REDIRECTS
static final long MAX_REDIRECTS- See Also:
-
-
Method Details
-
asyncRequest
<IntermediateType,FinalType> com.google.common.util.concurrent.ListenableFuture<FinalType> asyncRequest(RequestBuilder requestBuilder, HttpResponseHandler<IntermediateType, FinalType> handler) Perform a request asynchronously. UnlikeHttpClient.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'sServiceRetryPolicy. If attempts are exhausted, the future will fail withRpcExceptioncontaining the most recently encountered error. Redirects from 3xx responses are followed up to a chain length ofMAX_REDIRECTSand do not consume attempts. Redirects are validated against the targets returned byServiceLocator: the client will only follow redirects to targets that appear inServiceLocations. 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 onServiceRetryPolicy.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 returnsServiceNotAvailableException. 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 providedServiceRetryPolicy. 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 toHttpResponseExceptionif the final attempt failed due to a non-OK HTTP server response. Resolves toServiceNotAvailableExceptionif the final attempt failed because the service was not available (i.e. if the locator returned an empty set of locations). Resolves toServiceClosedExceptionif 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. -
request
default <IntermediateType,FinalType> FinalType request(RequestBuilder requestBuilder, HttpResponseHandler<IntermediateType, FinalType> handler) throws InterruptedException, ExecutionExceptionPerform a request synchronously. Same behavior asasyncRequest(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. -
withRetryPolicy
Returns a copy of this client with a differentServiceRetryPolicy.
-