com.netflix.loadbalancer
Class LoadBalancerExecutor

java.lang.Object
  extended by com.netflix.loadbalancer.LoadBalancerContext
      extended by com.netflix.loadbalancer.LoadBalancerExecutor
All Implemented Interfaces:
com.netflix.client.IClientConfigAware
Direct Known Subclasses:
AbstractLoadBalancerAwareClient

public class LoadBalancerExecutor
extends LoadBalancerContext

Provides APIs to execute and retry tasks on a server chosen by the associated load balancer. With appropriate RetryHandler, it will also retry on one or more different servers.


Field Summary
 
Fields inherited from class com.netflix.loadbalancer.LoadBalancerContext
clientName, defaultRetryHandler, maxAutoRetries, maxAutoRetriesNextServer, okToRetryOnAllOperations, vipAddresses
 
Constructor Summary
LoadBalancerExecutor(ILoadBalancer lb)
           
LoadBalancerExecutor(ILoadBalancer lb, com.netflix.client.config.IClientConfig clientConfig)
           
LoadBalancerExecutor(ILoadBalancer lb, com.netflix.client.config.IClientConfig clientConfig, com.netflix.client.RetryHandler defaultRetryHandler)
           
 
Method Summary
protected
<T> T
create(LoadBalancerCommand<T> command, java.net.URI loadBalancerURI, com.netflix.client.RetryHandler retryHandler, java.lang.Object loadBalancerKey)
          Execute a task on a server chosen by load balancer with possible retries.
<T> rx.Observable<T>
create(LoadBalancerObservableCommand<T> observableCommand)
          Create an Observable that once subscribed execute network call asynchronously with a server chosen by load balancer.
<T> rx.Observable<T>
create(LoadBalancerObservableCommand<T> observableCommand, com.netflix.client.RetryHandler retryHandler)
          Create an Observable that once subscribed execute network call asynchronously with a server chosen by load balancer.
protected
<T> rx.Observable<T>
create(LoadBalancerObservableCommand<T> observableCommand, java.net.URI loadBalancerURI, com.netflix.client.RetryHandler retryHandler, java.lang.Object loadBalancerKey)
          Create an Observable that once subscribed execute network call asynchronously with a server chosen by load balancer.
<T> T
execute(LoadBalancerCommand<T> command)
          Execute a task on a server chosen by load balancer with possible retries.
<T> T
execute(LoadBalancerCommand<T> command, com.netflix.client.RetryHandler retryHandler)
          Execute a task on a server chosen by load balancer with possible retries.
<T> rx.Observable<T>
retryWithSameServer(Server server, rx.Observable<T> forServer, com.netflix.client.RetryHandler errorHandler)
          Gets the Observable that represents the result of executing on a server, after possible retries as dictated by RetryHandler.
 
Methods inherited from class com.netflix.loadbalancer.LoadBalancerContext
deriveHostAndPortFromVipAddress, deriveSchemeAndPortFromPartialUri, generateNIWSException, getClientName, getDeepestCause, getDefaultPortFromScheme, getExecuteTracer, getLoadBalancer, getMaxAutoRetries, getMaxAutoRetriesNextServer, getNumberRetriesOnSameServer, getRetriesNextServer, getRetryHandler, getServerFromLoadBalancer, getServerStats, handleSameServerRetry, initWithNiwsConfig, isOkToRetryOnAllOperations, noteError, noteOpenConnection, noteRequestCompletion, noteRequestCompletion, noteResponse, reconstructURIWithServer, setLoadBalancer, setMaxAutoRetries, setMaxAutoRetriesNextServer, setOkToRetryOnAllOperations, setRetryHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoadBalancerExecutor

public LoadBalancerExecutor(ILoadBalancer lb)

LoadBalancerExecutor

public LoadBalancerExecutor(ILoadBalancer lb,
                            com.netflix.client.config.IClientConfig clientConfig)

LoadBalancerExecutor

public LoadBalancerExecutor(ILoadBalancer lb,
                            com.netflix.client.config.IClientConfig clientConfig,
                            com.netflix.client.RetryHandler defaultRetryHandler)
Method Detail

execute

public <T> T execute(LoadBalancerCommand<T> command,
                     com.netflix.client.RetryHandler retryHandler)
          throws java.lang.Exception
Execute a task on a server chosen by load balancer with possible retries. If there are any errors that are indicated as retriable by the RetryHandler, they will be consumed internally. If number of retries has exceeds the maximal allowed, a final error will be thrown. Otherwise, the first successful result during execution and retries will be returned.

Parameters:
command - interface that provides the logic to execute network call synchronously with a given Server
Throws:
java.lang.Exception - If any exception happens in the exception

execute

public <T> T execute(LoadBalancerCommand<T> command)
          throws java.lang.Exception
Execute a task on a server chosen by load balancer with possible retries. If there are any errors that are indicated as retriable by the RetryHandler, they will be consumed internally. If number of retries has exceeds the maximal allowed, a final error will be thrown. Otherwise, the first successful result during execution and retries will be returned.

Parameters:
command - interface that provides the logic to execute network call synchronously with a given Server
Throws:
java.lang.Exception - If any exception happens in the exception

create

protected <T> T create(LoadBalancerCommand<T> command,
                       @Nullable
                       java.net.URI loadBalancerURI,
                       @Nullable
                       com.netflix.client.RetryHandler retryHandler,
                       @Nullable
                       java.lang.Object loadBalancerKey)
            throws java.lang.Exception
Execute a task on a server chosen by load balancer with possible retries. If there are any errors that are indicated as retriable by the RetryHandler, they will be consumed internally. If number of retries has exceeds the maximal allowed, a final error will be thrown. Otherwise, the first successful result during execution and retries will be returned.

Parameters:
command - interface that provides the logic to execute network call synchronously with a given Server
loadBalancerURI - An optional URI that may contain a real host name and port to use as a fallback to the LoadBalancerExecutor if it does not have a load balancer or cannot find a server from its server list. For example, the URI contains "www.google.com:80" will force the LoadBalancerExecutor to use www.google.com:80 as the actual server to carry out the retry execution. See LoadBalancerContext.getServerFromLoadBalancer(URI, Object)
retryHandler - an optional handler to determine the retry logic of the LoadBalancerExecutor. If null, the default RetryHandler of this LoadBalancerExecutor will be used.
loadBalancerKey - An optional key passed to the load balancer to determine which server to return.
Throws:
java.lang.Exception - If any exception happens in the exception

create

public <T> rx.Observable<T> create(LoadBalancerObservableCommand<T> observableCommand,
                                   @Nullable
                                   com.netflix.client.RetryHandler retryHandler)
Create an Observable that once subscribed execute network call asynchronously with a server chosen by load balancer. If there are any errors that are indicated as retriable by the RetryHandler, they will be consumed internally by the function and will not be observed by the Observer subscribed to the returned Observable. If number of retries has exceeds the maximal allowed, a final error will be emitted by the returned Observable. Otherwise, the first successful result during execution and retries will be emitted.

Parameters:
observableCommand - interface that provides the logic to execute network call asynchronously with a given Server
retryHandler - an optional handler to determine the retry logic of the LoadBalancerExecutor. If null, the default RetryHandler of this LoadBalancerExecutor will be used.

create

public <T> rx.Observable<T> create(LoadBalancerObservableCommand<T> observableCommand)
Create an Observable that once subscribed execute network call asynchronously with a server chosen by load balancer. If there are any errors that are indicated as retriable by the RetryHandler, they will be consumed internally by the function and will not be observed by the Observer subscribed to the returned Observable. If number of retries has exceeds the maximal allowed, a final error will be emitted by the returned Observable. Otherwise, the first successful result during execution and retries will be emitted.

Parameters:
observableCommand - interface that provides the logic to execute network call synchronously with a given Server

create

protected <T> rx.Observable<T> create(LoadBalancerObservableCommand<T> observableCommand,
                                      @Nullable
                                      java.net.URI loadBalancerURI,
                                      @Nullable
                                      com.netflix.client.RetryHandler retryHandler,
                                      @Nullable
                                      java.lang.Object loadBalancerKey)
Create an Observable that once subscribed execute network call asynchronously with a server chosen by load balancer. If there are any errors that are indicated as retriable by the RetryHandler, they will be consumed internally by the function and will not be observed by the Observer subscribed to the returned Observable. If number of retries has exceeds the maximal allowed, a final error will be emitted by the returned Observable. Otherwise, the first successful result during execution and retries will be emitted.

Parameters:
observableCommand - interface that provides the logic to execute network call asynchronously with a given Server
loadBalancerURI - An optional URI that may contain a real host name and port to be used by LoadBalancerExecutor if it does not have a load balancer or cannot find a server from its server list. For example, the URI contains "www.google.com:80" will force the LoadBalancerExecutor to use www.google.com:80 as the actual server to carry out the retry execution. See LoadBalancerContext.getServerFromLoadBalancer(URI, Object)
retryHandler - an optional handler to determine the retry logic of the LoadBalancerExecutor. If null, the default RetryHandler of this LoadBalancerExecutor will be used.
loadBalancerKey - An optional key passed to the load balancer to determine which server to return.

retryWithSameServer

public <T> rx.Observable<T> retryWithSameServer(Server server,
                                                rx.Observable<T> forServer,
                                                com.netflix.client.RetryHandler errorHandler)
Gets the Observable that represents the result of executing on a server, after possible retries as dictated by RetryHandler. During retry, any errors that are retriable are consumed by the function and will not be observed by the external Observer. If number of retries exceeds the maximal retries allowed on one server, a final error will be emitted by the returned Observable.

Parameters:
forServer - A lazy Observable that does not start execution until it is subscribed to