Class ConnectionSelectorPolicies
ConnectionSelectorPolicy
variants.-
Method Summary
Modifier and TypeMethodDescriptionstatic <C extends LoadBalancedConnection>
ConnectionSelectorPolicy<C>corePool
(int corePoolSize, boolean forceCorePool) A connection selection policy that prioritizes a configurable "core" pool.static <C extends LoadBalancedConnection>
ConnectionSelectorPolicy<C>A connection selection policy that prioritizes connection reuse.static <C extends LoadBalancedConnection>
ConnectionSelectorPolicy<C>linearSearch
(int linearSearchSpace) A connection selection policy that prioritizes connection reuse.static <C extends LoadBalancedConnection>
ConnectionSelectorPolicy<C>p2c
(int corePoolSize, boolean forceCorePool) AConnectionSelectorPolicy
that attempts to discern between the health of individual connections.static <C extends LoadBalancedConnection>
ConnectionSelectorPolicy<C>p2c
(int maxEffort, int corePoolSize, boolean forceCorePool) AConnectionSelectorPolicy
that attempts to discern between the health of individual connections.
-
Method Details
-
corePool
public static <C extends LoadBalancedConnection> ConnectionSelectorPolicy<C> corePool(int corePoolSize, boolean forceCorePool) A connection selection policy that prioritizes a configurable "core" pool.This
ConnectionSelectorPolicy
attempts to emulate the pooling behavior often seen in thread pools. Specifically it allows for the configuration of a "core pool" size which are intended to be long-lived. Iteration starts in the core pool at a random position and then iterates through the entire core pool before moving to an overflow pool. Because iteration of this core pool starts at a random position the core connections will get an even traffic load and, because they are equally selectable, will tend not to be removed due to idleness.If the core pool cannot satisfy the load traffic can spill over to extra connections which are selected in-order. This has the property of minimizing traffic to the latest elements added outside the core pool size, thus let them idle out of the pool once they're no longer necessary.
- Type Parameters:
C
- the concrete type of theLoadBalancedConnection
- Parameters:
corePoolSize
- the size of the core pool.forceCorePool
- whether to avoid selecting connections from the core pool until it has reached the configured core pool size.- Returns:
- the configured
ConnectionSelectorPolicy
.
-
linearSearch
A connection selection policy that prioritizes connection reuse.This
ConnectionSelectorPolicy
attempts to minimize the number of connections by attempting to direct traffic to connections in the order they were created in linear order up until a configured quantity. After this linear pool is exhausted the remaining connections will be selected from at random. Prioritizing traffic to the existing connections will let tailing connections be removed due to idleness.- Type Parameters:
C
- the concrete type of theLoadBalancedConnection
- Returns:
- the configured
ConnectionSelectorPolicy
.
-
linearSearch
public static <C extends LoadBalancedConnection> ConnectionSelectorPolicy<C> linearSearch(int linearSearchSpace) A connection selection policy that prioritizes connection reuse.This
ConnectionSelectorPolicy
attempts to minimize the number of connections by attempting to direct traffic to connections in the order they were created in linear order up until a configured quantity. After this linear pool is exhausted the remaining connections will be selected from at random. Prioritizing traffic to the existing connections will let tailing connections be removed due to idleness.- Type Parameters:
C
- the concrete type of theLoadBalancedConnection
- Parameters:
linearSearchSpace
- the space to search linearly before resorting to random selection for remaining connections.- Returns:
- the configured
ConnectionSelectorPolicy
.
-
p2c
public static <C extends LoadBalancedConnection> ConnectionSelectorPolicy<C> p2c(int corePoolSize, boolean forceCorePool) AConnectionSelectorPolicy
that attempts to discern between the health of individual connections. If individual connections have health data the P2C policy can be used to bias traffic toward the best connections. This has the following algorithm:- Randomly select two connections from the 'core pool' (pick-two).
- Try to select the 'best' of the two connections.
- If we fail to select the best connection, try the other connection.
- If both connections fail, repeat the pick-two operation for up to maxEffort attempts, begin linear iteration through the remaining connections searching for an acceptable connection.
- Type Parameters:
C
- the concrete type of theLoadBalancedConnection
- Parameters:
corePoolSize
- the size of the core pool.forceCorePool
- whether to avoid selecting connections from the core pool until it has reached the configured core pool size.- Returns:
- the configured
ConnectionSelectorPolicy
.
- Randomly select two connections from the 'core pool' (pick-two).
-
p2c
public static <C extends LoadBalancedConnection> ConnectionSelectorPolicy<C> p2c(int maxEffort, int corePoolSize, boolean forceCorePool) AConnectionSelectorPolicy
that attempts to discern between the health of individual connections. If individual connections have health data the P2C policy can be used to bias traffic toward the best connections. This has the following algorithm:- Randomly select two connections from the 'core pool' (pick-two).
- Try to select the 'best' of the two connections.
- If we fail to select the best connection, try the other connection.
- If both connections fail, repeat the pick-two operation for up to maxEffort attempts, begin linear iteration through the remaining connections searching for an acceptable connection.
- Type Parameters:
C
- the concrete type of theLoadBalancedConnection
- Parameters:
maxEffort
- the maximum number of attempts to pick a healthy connection from the core pool.corePoolSize
- the size of the core pool.forceCorePool
- whether to avoid selecting connections from the core pool until it has reached the configured core pool size.- Returns:
- the configured
ConnectionSelectorPolicy
.
- Randomly select two connections from the 'core pool' (pick-two).
-