Package org.apache.druid.rpc
Class ServiceClientImpl
- java.lang.Object
-
- org.apache.druid.rpc.ServiceClientImpl
-
- All Implemented Interfaces:
ServiceClient
public class ServiceClientImpl extends Object implements ServiceClient
Production implementation ofServiceClient.
-
-
Field Summary
-
Fields inherited from interface org.apache.druid.rpc.ServiceClient
MAX_REDIRECTS
-
-
Constructor Summary
Constructors Constructor Description ServiceClientImpl(String serviceName, org.apache.druid.java.util.http.client.HttpClient httpClient, ServiceLocator serviceLocator, ServiceRetryPolicy retryPolicy, ScheduledExecutorService connectExec)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <IntermediateType,FinalType>
com.google.common.util.concurrent.ListenableFuture<FinalType>asyncRequest(RequestBuilder requestBuilder, org.apache.druid.java.util.http.client.response.HttpResponseHandler<IntermediateType,FinalType> handler)Perform a request asynchronously.ServiceClientImplwithRetryPolicy(ServiceRetryPolicy newRetryPolicy)Returns a copy of this client with a differentServiceRetryPolicy.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.druid.rpc.ServiceClient
request
-
-
-
-
Constructor Detail
-
ServiceClientImpl
public ServiceClientImpl(String serviceName, org.apache.druid.java.util.http.client.HttpClient httpClient, ServiceLocator serviceLocator, ServiceRetryPolicy retryPolicy, ScheduledExecutorService connectExec)
-
-
Method Detail
-
asyncRequest
public <IntermediateType,FinalType> com.google.common.util.concurrent.ListenableFuture<FinalType> asyncRequest(RequestBuilder requestBuilder, org.apache.druid.java.util.http.client.response.HttpResponseHandler<IntermediateType,FinalType> handler)
Description copied from interface:ServiceClientPerform 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 ofServiceClient.MAX_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.- Specified by:
asyncRequestin interfaceServiceClient
-
withRetryPolicy
public ServiceClientImpl withRetryPolicy(ServiceRetryPolicy newRetryPolicy)
Description copied from interface:ServiceClientReturns a copy of this client with a differentServiceRetryPolicy.- Specified by:
withRetryPolicyin interfaceServiceClient
-
-