diff --git a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/ConnectionPoolPolicies.java b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/ConnectionPoolPolicies.java index c27dfe8430..a1306a4a76 100644 --- a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/ConnectionPoolPolicies.java +++ b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/ConnectionPoolPolicies.java @@ -25,6 +25,15 @@ private ConnectionPoolPolicies() { // no instances } + /** + * Get the recommended default {@link ConnectionPoolPolicy}. + * @param the concrete type of the {@link LoadBalancedConnection} + * @return the recommended default {@link ConnectionPoolPolicy}. + */ + public static ConnectionPoolPolicy defaultPolicy() { + return linearSearch(); + } + /** * A connection selection policy that prioritizes a configurable "core" pool. *

@@ -44,8 +53,8 @@ private ConnectionPoolPolicies() { * @param the concrete type of the {@link LoadBalancedConnection} * @return the configured {@link ConnectionPoolPolicy}. */ - public static ConnectionPoolPolicy - corePool(final int corePoolSize, final boolean forceCorePool) { + public static + ConnectionPoolPolicy corePool(final int corePoolSize, final boolean forceCorePool) { return CorePoolConnectionSelector.factory(corePoolSize, forceCorePool); } @@ -94,8 +103,8 @@ public static ConnectionPoolPolicy linearS * @param the concrete type of the {@link LoadBalancedConnection} * @return the configured {@link ConnectionPoolPolicy}. */ - public static ConnectionPoolPolicy - p2c(int corePoolSize, boolean forceCorePool) { + public static + ConnectionPoolPolicy p2c(int corePoolSize, boolean forceCorePool) { return p2c(DEFAULT_MAX_EFFORT, corePoolSize, forceCorePool); } diff --git a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultLoadBalancerBuilder.java b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultLoadBalancerBuilder.java index 6a141a7e66..3d17fe8fd5 100644 --- a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultLoadBalancerBuilder.java +++ b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultLoadBalancerBuilder.java @@ -39,8 +39,8 @@ final class DefaultLoadBalancerBuilder loadBalancingPolicy = defaultLoadBalancingPolicy(); - private ConnectionPoolPolicy connectionPoolPolicy = defaultConnectionSelectorFactory(); + private LoadBalancingPolicy loadBalancingPolicy = LoadBalancingPolicies.defaultPolicy(); + private ConnectionPoolPolicy connectionPoolPolicy = ConnectionPoolPolicies.defaultPolicy(); private OutlierDetectorConfig outlierDetectorConfig = OutlierDetectorConfig.DEFAULT_CONFIG; // package private constructor so users must funnel through providers in `LoadBalancers` @@ -181,14 +181,4 @@ private Executor getExecutor() { return backgroundExecutor == null ? RoundRobinLoadBalancerFactory.SharedExecutor.getInstance() : backgroundExecutor; } - - private static - LoadBalancingPolicy defaultLoadBalancingPolicy() { - return LoadBalancingPolicies.roundRobin().build(); - } - - private static ConnectionPoolPolicy - defaultConnectionSelectorFactory() { - return ConnectionPoolPolicies.linearSearch(); - } } diff --git a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/LoadBalancingPolicies.java b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/LoadBalancingPolicies.java index 260e8008d0..bdcd410853 100644 --- a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/LoadBalancingPolicies.java +++ b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/LoadBalancingPolicies.java @@ -15,6 +15,8 @@ */ package io.servicetalk.loadbalancer; +import io.servicetalk.client.api.LoadBalancedConnection; + /** * A collections of factories for constructing a {@link LoadBalancingPolicy}. */ @@ -24,6 +26,15 @@ private LoadBalancingPolicies() { // no instances. } + /** + * Get the recommended default {@link LoadBalancingPolicy}. + * @return the recommended default {@link LoadBalancingPolicy}. + */ + public static + LoadBalancingPolicy 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