com.netflix.astyanax.connectionpool.impl
Class AbstractLatencyScoreStrategyImpl

java.lang.Object
  extended by com.netflix.astyanax.connectionpool.impl.AbstractLatencyScoreStrategyImpl
All Implemented Interfaces:
LatencyScoreStrategy
Direct Known Subclasses:
EmaLatencyScoreStrategyImpl, SmaLatencyScoreStrategyImpl

public abstract class AbstractLatencyScoreStrategyImpl
extends java.lang.Object
implements LatencyScoreStrategy


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.netflix.astyanax.connectionpool.LatencyScoreStrategy
LatencyScoreStrategy.Instance, LatencyScoreStrategy.Listener
 
Field Summary
static int DEFAULT_BLOCKED_THREAD_THRESHOLD
           
static double DEFAULT_KEEP_RATIO
           
static int DEFAULT_RESET_INTERVAL
           
static double DEFAULT_SCORE_THRESHOLD
           
static int DEFAULT_UPDATE_INTERVAL
           
 
Constructor Summary
AbstractLatencyScoreStrategyImpl(java.lang.String name)
           
AbstractLatencyScoreStrategyImpl(java.lang.String name, int updateInterval, int resetInterval)
           
AbstractLatencyScoreStrategyImpl(java.lang.String name, int updateInterval, int resetInterval, int blockedThreshold, double keepRatio, double scoreThreshold)
           
AbstractLatencyScoreStrategyImpl(java.lang.String name, int updateInterval, int resetInterval, int blockedThreshold, double keepRatio, double scoreThreshold, java.util.concurrent.ScheduledExecutorService executor)
           
 
Method Summary
 LatencyScoreStrategy.Instance createInstance()
          Create a new instance to associate with an endpoint
 int getBlockedThreshold()
           
 double getKeepRatio()
           
 int getResetInterval()
           
 double getScoreThreshold()
           
 int getUpdateInterval()
           
protected abstract  LatencyScoreStrategy.Instance newInstance()
          Template method for creating a new latency tracking instance for a host
 void removeInstance(LatencyScoreStrategy.Instance instance)
          Remove the instance for an endpoint that is no longer being tracked
 void reset()
          Reset all instance scores
 void shutdown()
          Shutdown the threads created by calling start()
<CL> java.util.List<HostConnectionPool<CL>>
sortAndfilterPartition(java.util.List<HostConnectionPool<CL>> srcPools, java.util.concurrent.atomic.AtomicBoolean prioritized)
          Sorts and filters a list of hosts by looking at their up state and score.
 void start(LatencyScoreStrategy.Listener listener)
          Start updating stats for instances created using createInstance.
 void update()
          Update all instance scores
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_UPDATE_INTERVAL

public static final int DEFAULT_UPDATE_INTERVAL
See Also:
Constant Field Values

DEFAULT_RESET_INTERVAL

public static final int DEFAULT_RESET_INTERVAL
See Also:
Constant Field Values

DEFAULT_BLOCKED_THREAD_THRESHOLD

public static final int DEFAULT_BLOCKED_THREAD_THRESHOLD
See Also:
Constant Field Values

DEFAULT_KEEP_RATIO

public static final double DEFAULT_KEEP_RATIO
See Also:
Constant Field Values

DEFAULT_SCORE_THRESHOLD

public static final double DEFAULT_SCORE_THRESHOLD
See Also:
Constant Field Values
Constructor Detail

AbstractLatencyScoreStrategyImpl

public AbstractLatencyScoreStrategyImpl(java.lang.String name,
                                        int updateInterval,
                                        int resetInterval,
                                        int blockedThreshold,
                                        double keepRatio,
                                        double scoreThreshold,
                                        java.util.concurrent.ScheduledExecutorService executor)

AbstractLatencyScoreStrategyImpl

public AbstractLatencyScoreStrategyImpl(java.lang.String name,
                                        int updateInterval,
                                        int resetInterval,
                                        int blockedThreshold,
                                        double keepRatio,
                                        double scoreThreshold)
Parameters:
name -
updateInterval - In milliseconds
resetInterval - In milliseconds

AbstractLatencyScoreStrategyImpl

public AbstractLatencyScoreStrategyImpl(java.lang.String name,
                                        int updateInterval,
                                        int resetInterval)

AbstractLatencyScoreStrategyImpl

public AbstractLatencyScoreStrategyImpl(java.lang.String name)
Method Detail

createInstance

public final LatencyScoreStrategy.Instance createInstance()
Description copied from interface: LatencyScoreStrategy
Create a new instance to associate with an endpoint

Specified by:
createInstance in interface LatencyScoreStrategy
Returns:

newInstance

protected abstract LatencyScoreStrategy.Instance newInstance()
Template method for creating a new latency tracking instance for a host

Returns:

start

public void start(LatencyScoreStrategy.Listener listener)
Description copied from interface: LatencyScoreStrategy
Start updating stats for instances created using createInstance. This usually spawns an update thread as well as a reset thread operating at configurable intervals

Specified by:
start in interface LatencyScoreStrategy

shutdown

public void shutdown()
Description copied from interface: LatencyScoreStrategy
Shutdown the threads created by calling start()

Specified by:
shutdown in interface LatencyScoreStrategy

removeInstance

public void removeInstance(LatencyScoreStrategy.Instance instance)
Description copied from interface: LatencyScoreStrategy
Remove the instance for an endpoint that is no longer being tracked

Specified by:
removeInstance in interface LatencyScoreStrategy

sortAndfilterPartition

public <CL> java.util.List<HostConnectionPool<CL>> sortAndfilterPartition(java.util.List<HostConnectionPool<CL>> srcPools,
                                                                          java.util.concurrent.atomic.AtomicBoolean prioritized)
Description copied from interface: LatencyScoreStrategy
Sorts and filters a list of hosts by looking at their up state and score.

Specified by:
sortAndfilterPartition in interface LatencyScoreStrategy
prioritized - - Will be set to true if the filtered data is prioritized or not. If prioritized then the first element should be selected from by the load balancing strategy. Otherwise round robin could be used.
Returns:

update

public void update()
Description copied from interface: LatencyScoreStrategy
Update all instance scores

Specified by:
update in interface LatencyScoreStrategy

reset

public void reset()
Description copied from interface: LatencyScoreStrategy
Reset all instance scores

Specified by:
reset in interface LatencyScoreStrategy

getUpdateInterval

public int getUpdateInterval()
Specified by:
getUpdateInterval in interface LatencyScoreStrategy
Returns:
Return interval for updating the scores

getResetInterval

public int getResetInterval()
Specified by:
getResetInterval in interface LatencyScoreStrategy
Returns:
Return interval for clearing scores

getScoreThreshold

public double getScoreThreshold()
Specified by:
getScoreThreshold in interface LatencyScoreStrategy
Returns:
Return threshold after which hosts will be excluded if their score is getScoreThreshold() times larger than the best performing node

getBlockedThreshold

public int getBlockedThreshold()
Specified by:
getBlockedThreshold in interface LatencyScoreStrategy
Returns:
Return threshold of blocked connections after which a host is excluded

getKeepRatio

public double getKeepRatio()
Specified by:
getKeepRatio in interface LatencyScoreStrategy
Returns:
Get ratio for calculating minimum number of hosts that most remain in the pool