Skip to content

Commit

Permalink
Load Balancing policies
Browse files Browse the repository at this point in the history
  • Loading branch information
bryce-anderson committed Dec 11, 2024
1 parent 8024d67 commit 2d1db2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class DefaultLoadBalancerBuilder<ResolvedAddress, C extends LoadBalancedCo
private Executor backgroundExecutor;
@Nullable
private LoadBalancerObserverFactory loadBalancerObserverFactory;
private LoadBalancingPolicy<ResolvedAddress, C> loadBalancingPolicy = defaultLoadBalancingPolicy();
private LoadBalancingPolicy<ResolvedAddress, C> loadBalancingPolicy = LoadBalancingPolicies.defaultPolicy();
private ConnectionPoolPolicy<C> connectionPoolPolicy = ConnectionPoolPolicies.defaultPolicy();;
private OutlierDetectorConfig outlierDetectorConfig = OutlierDetectorConfig.DEFAULT_CONFIG;

Expand Down Expand Up @@ -181,9 +181,4 @@ private Executor getExecutor() {
return backgroundExecutor ==
null ? RoundRobinLoadBalancerFactory.SharedExecutor.getInstance() : backgroundExecutor;
}

private static <ResolvedAddress, C extends LoadBalancedConnection>
LoadBalancingPolicy<ResolvedAddress, C> defaultLoadBalancingPolicy() {
return LoadBalancingPolicies.roundRobin().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.servicetalk.loadbalancer;

import io.servicetalk.client.api.LoadBalancedConnection;

/**
* A collections of factories for constructing a {@link LoadBalancingPolicy}.
*/
Expand All @@ -24,6 +26,15 @@ private LoadBalancingPolicies() {
// no instances.
}

/**
* Get the recommended default {@link LoadBalancingPolicy}.
* @return the recommended default {@link LoadBalancingPolicy}.
*/
public static <ResolvedAddress, C extends LoadBalancedConnection>
LoadBalancingPolicy<ResolvedAddress, C> defaultPolicy() {
return LoadBalancingPolicies.roundRobin().build();
}

/**
* Builder for the round-robin {@link LoadBalancingPolicy}.
* Round-robin load balancing is a strategy that maximizes fairness of the request distribution. This comes at the
Expand Down

0 comments on commit 2d1db2a

Please sign in to comment.