Skip to content

Commit

Permalink
give a chance to the derived class of AbstractLoadBalancerAwareClient to
Browse files Browse the repository at this point in the history
customize the LoadBalancerCommand object
  • Loading branch information
lowzj committed May 22, 2017
1 parent ff4b5fe commit a48df1c
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ public T executeWithLoadBalancer(S request) throws ClientException {
* URI which does not contain the host name or the protocol.
*/
public T executeWithLoadBalancer(final S request, final IClientConfig requestConfig) throws ClientException {
RequestSpecificRetryHandler handler = getRequestSpecificRetryHandler(request, requestConfig);
LoadBalancerCommand<T> command = LoadBalancerCommand.<T>builder()
.withLoadBalancerContext(this)
.withRetryHandler(handler)
.withLoadBalancerURI(request.getUri())
.build();
LoadBalancerCommand<T> command = buildLoadBalancerCommand(request, requestConfig);

try {
return command.submit(
Expand Down Expand Up @@ -128,6 +123,21 @@ public Observable<T> call(Server server) {

public abstract RequestSpecificRetryHandler getRequestSpecificRetryHandler(S request, IClientConfig requestConfig);

protected LoadBalancerCommand<T> buildLoadBalancerCommand(final S request, final IClientConfig config) {
RequestSpecificRetryHandler handler = getRequestSpecificRetryHandler(request, config);
LoadBalancerCommand.Builder<T> builder = LoadBalancerCommand.<T>builder()
.withLoadBalancerContext(this)
.withRetryHandler(handler)
.withLoadBalancerURI(request.getUri());
customizeLoadBalancerCommandBuilder(request, config, builder);
return builder.build();
}

protected void customizeLoadBalancerCommandBuilder(final S request, final IClientConfig config,
final LoadBalancerCommand.Builder<T> builder) {
// do nothing by default, give a chance to its derived class to customize the builder
}

@Deprecated
protected boolean isRetriable(S request) {
if (request.isRetriable()) {
Expand Down

0 comments on commit a48df1c

Please sign in to comment.