com.netflix.loadbalancer
Class AbstractServerPredicate

java.lang.Object
  extended by com.netflix.loadbalancer.AbstractServerPredicate
All Implemented Interfaces:
com.google.common.base.Predicate<PredicateKey>
Direct Known Subclasses:
AvailabilityPredicate, CompositePredicate, ZoneAffinityPredicate, ZoneAvoidancePredicate

public abstract class AbstractServerPredicate
extends java.lang.Object
implements com.google.common.base.Predicate<PredicateKey>

A basic building block for server filtering logic which can be used in rules and server list filters. The input object of the predicate is PredicateKey, which has Server and load balancer key information. Therefore, it is possible to develop logic to filter servers by both Server and load balancer key or either one of them.


Field Summary
protected  IRule rule
           
 
Constructor Summary
AbstractServerPredicate()
           
AbstractServerPredicate(IRule rule)
           
AbstractServerPredicate(IRule rule, com.netflix.client.config.IClientConfig clientConfig)
           
AbstractServerPredicate(LoadBalancerStats lbStats, com.netflix.client.config.IClientConfig clientConfig)
           
 
Method Summary
static AbstractServerPredicate alwaysTrue()
           
 com.google.common.base.Optional<Server> chooseRandomlyAfterFiltering(java.util.List<Server> servers)
          Choose a random server after the predicate filters a list of servers.
 com.google.common.base.Optional<Server> chooseRandomlyAfterFiltering(java.util.List<Server> servers, java.lang.Object loadBalancerKey)
          Choose a random server after the predicate filters list of servers given list of servers and load balancer key.
 com.google.common.base.Optional<Server> chooseRoundRobinAfterFiltering(java.util.List<Server> servers)
          Choose a server in a round robin fashion after the predicate filters a list of servers.
 com.google.common.base.Optional<Server> chooseRoundRobinAfterFiltering(java.util.List<Server> servers, java.lang.Object loadBalancerKey)
          Choose a server in a round robin fashion after the predicate filters a given list of servers and load balancer key.
 java.util.List<Server> getEligibleServers(java.util.List<Server> servers)
          Get servers filtered by this predicate from list of servers.
 java.util.List<Server> getEligibleServers(java.util.List<Server> servers, java.lang.Object loadBalancerKey)
          Get servers filtered by this predicate from list of servers.
protected  LoadBalancerStats getLBStats()
           
 com.google.common.base.Predicate<Server> getServerOnlyPredicate()
          Get the predicate to filter list of servers.
static AbstractServerPredicate ofKeyPredicate(com.google.common.base.Predicate<PredicateKey> p)
          Create an instance from a predicate.
static AbstractServerPredicate ofServerPredicate(com.google.common.base.Predicate<Server> p)
          Create an instance from a predicate.
 void setLoadBalancerStats(LoadBalancerStats stats)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.google.common.base.Predicate
apply, equals
 

Field Detail

rule

protected IRule rule
Constructor Detail

AbstractServerPredicate

public AbstractServerPredicate()

AbstractServerPredicate

public AbstractServerPredicate(IRule rule)

AbstractServerPredicate

public AbstractServerPredicate(IRule rule,
                               com.netflix.client.config.IClientConfig clientConfig)

AbstractServerPredicate

public AbstractServerPredicate(LoadBalancerStats lbStats,
                               com.netflix.client.config.IClientConfig clientConfig)
Method Detail

alwaysTrue

public static AbstractServerPredicate alwaysTrue()

getLBStats

protected LoadBalancerStats getLBStats()

setLoadBalancerStats

public void setLoadBalancerStats(LoadBalancerStats stats)

getServerOnlyPredicate

public com.google.common.base.Predicate<Server> getServerOnlyPredicate()
Get the predicate to filter list of servers. The load balancer key is treated as null as the input of this predicate.


getEligibleServers

public java.util.List<Server> getEligibleServers(java.util.List<Server> servers)
Get servers filtered by this predicate from list of servers. Load balancer key is presumed to be null.

See Also:
getEligibleServers(List, Object)

getEligibleServers

public java.util.List<Server> getEligibleServers(java.util.List<Server> servers,
                                                 java.lang.Object loadBalancerKey)
Get servers filtered by this predicate from list of servers.


chooseRandomlyAfterFiltering

public com.google.common.base.Optional<Server> chooseRandomlyAfterFiltering(java.util.List<Server> servers)
Choose a random server after the predicate filters a list of servers. Load balancer key is presumed to be null.


chooseRoundRobinAfterFiltering

public com.google.common.base.Optional<Server> chooseRoundRobinAfterFiltering(java.util.List<Server> servers)
Choose a server in a round robin fashion after the predicate filters a list of servers. Load balancer key is presumed to be null.


chooseRandomlyAfterFiltering

public com.google.common.base.Optional<Server> chooseRandomlyAfterFiltering(java.util.List<Server> servers,
                                                                            java.lang.Object loadBalancerKey)
Choose a random server after the predicate filters list of servers given list of servers and load balancer key.


chooseRoundRobinAfterFiltering

public com.google.common.base.Optional<Server> chooseRoundRobinAfterFiltering(java.util.List<Server> servers,
                                                                              java.lang.Object loadBalancerKey)
Choose a server in a round robin fashion after the predicate filters a given list of servers and load balancer key.


ofKeyPredicate

public static AbstractServerPredicate ofKeyPredicate(com.google.common.base.Predicate<PredicateKey> p)
Create an instance from a predicate.


ofServerPredicate

public static AbstractServerPredicate ofServerPredicate(com.google.common.base.Predicate<Server> p)
Create an instance from a predicate.