|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.netflix.loadbalancer.AbstractLoadBalancer
com.netflix.loadbalancer.BaseLoadBalancer
public class BaseLoadBalancer
A basic implementation of the load balancer where an arbitrary list of servers can be set as the server pool. A ping can be set to determine the liveness of a server. Internally, this class maintains an "all" server list and an "up" server list and use them depending on what the caller asks for.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class com.netflix.loadbalancer.AbstractLoadBalancer |
|---|
AbstractLoadBalancer.ServerGroup |
| Field Summary | |
|---|---|
protected java.util.List<Server> |
allServerList
|
protected java.util.concurrent.locks.ReadWriteLock |
allServerLock
|
protected LoadBalancerStats |
lbStats
|
protected java.util.Timer |
lbTimer
|
protected int |
maxTotalPingTimeSeconds
|
protected java.lang.String |
name
|
protected IPing |
ping
|
protected java.util.concurrent.atomic.AtomicBoolean |
pingInProgress
|
protected int |
pingIntervalSeconds
|
protected IRule |
rule
|
protected java.util.Comparator<Server> |
serverComparator
|
protected java.util.List<Server> |
upServerList
|
protected java.util.concurrent.locks.ReadWriteLock |
upServerLock
|
| Constructor Summary | |
|---|---|
BaseLoadBalancer()
Default constructor which sets name as "default", sets null ping, and RoundRobinRule as the rule. |
|
BaseLoadBalancer(com.netflix.client.config.IClientConfig config)
|
|
BaseLoadBalancer(com.netflix.client.config.IClientConfig config,
IRule rule,
IPing ping)
|
|
BaseLoadBalancer(IPing ping,
IRule rule)
|
|
BaseLoadBalancer(java.lang.String lbName,
IRule rule,
LoadBalancerStats lbStats)
|
|
BaseLoadBalancer(java.lang.String name,
IRule rule,
LoadBalancerStats stats,
IPing ping)
|
|
| Method Summary | |
|---|---|
void |
addServer(Server newServer)
Add a server to the 'allServer' list; does not verify uniqueness, so you could give a server a greater share by adding it more than once. |
void |
addServerListChangeListener(ServerListChangeListener listener)
|
void |
addServers(java.util.List<Server> newServers)
Add a list of servers to the 'allServer' list; does not verify uniqueness, so you could give a server a greater share by adding it more than once |
void |
cancelPingTask()
|
java.lang.String |
choose(java.lang.Object key)
|
Server |
chooseServer(java.lang.Object key)
Choose a server from load balancer. |
void |
forceQuickPing()
|
com.netflix.client.config.IClientConfig |
getClientConfig()
|
LoadBalancerStats |
getLoadBalancerStats()
Obtain LoadBalancer related Statistics |
int |
getMaxTotalPingTime()
|
java.lang.String |
getName()
|
IPing |
getPing()
|
int |
getPingInterval()
|
PrimeConnections |
getPrimeConnections()
|
IRule |
getRule()
|
Server |
getServerByIndex(int index,
boolean availableOnly)
return the server |
int |
getServerCount(boolean onlyAvailable)
get the count of servers. |
java.util.List<Server> |
getServerList(AbstractLoadBalancer.ServerGroup serverGroup)
List of servers that this Loadbalancer knows about |
java.util.List<Server> |
getServerList(boolean availableOnly)
Get the current list of servers. |
protected void |
init()
Register with monitors and start priming connections if it is set. |
void |
initWithNiwsConfig(com.netflix.client.config.IClientConfig clientConfig)
|
boolean |
isEnablePrimingConnections()
|
boolean |
isPingInProgress()
|
java.util.concurrent.locks.Lock |
lockAllServerList(boolean write)
|
java.util.concurrent.locks.Lock |
lockUpServerList(boolean write)
|
void |
markServerDown(Server server)
To be called by the clients of the load balancer to notify that a Server is down else, the LB will think its still Alive until the next Ping cycle - potentially (assuming that the LB Impl does a ping) |
void |
markServerDown(java.lang.String id)
|
void |
primeCompleted(Server s,
java.lang.Throwable lastException)
|
void |
removeServerListChangeListener(ServerListChangeListener listener)
|
void |
setEnablePrimingConnections(boolean enablePrimingConnections)
|
void |
setLoadBalancerStats(LoadBalancerStats lbStats)
|
void |
setMaxTotalPingTime(int maxTotalPingTimeSeconds)
|
void |
setPing(IPing ping)
|
void |
setPingInterval(int pingIntervalSeconds)
|
void |
setPrimeConnections(PrimeConnections primeConnections)
|
void |
setRule(IRule rule)
|
void |
setServersList(java.util.List lsrv)
Set the list of servers used as the server pool. |
void |
shutdown()
|
java.lang.String |
toString()
|
| Methods inherited from class com.netflix.loadbalancer.AbstractLoadBalancer |
|---|
chooseServer |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected IRule rule
protected IPing ping
@Monitor(name="LoadBalancer_AllServerList",
type=INFORMATIONAL)
protected volatile java.util.List<Server> allServerList
@Monitor(name="LoadBalancer_UpServerList",
type=INFORMATIONAL)
protected volatile java.util.List<Server> upServerList
protected java.util.concurrent.locks.ReadWriteLock allServerLock
protected java.util.concurrent.locks.ReadWriteLock upServerLock
protected java.lang.String name
protected java.util.Timer lbTimer
protected int pingIntervalSeconds
protected int maxTotalPingTimeSeconds
protected java.util.Comparator<Server> serverComparator
protected java.util.concurrent.atomic.AtomicBoolean pingInProgress
protected LoadBalancerStats lbStats
| Constructor Detail |
|---|
public BaseLoadBalancer()
RoundRobinRule as the rule.
This constructor is mainly used by ClientFactory. Calling this
constructor must be followed by calling init() or
initWithNiwsConfig(IClientConfig) to complete initialization.
This constructor is provided for reflection. When constructing
programatically, it is recommended to use other constructors.
public BaseLoadBalancer(java.lang.String lbName,
IRule rule,
LoadBalancerStats lbStats)
public BaseLoadBalancer(IPing ping,
IRule rule)
public BaseLoadBalancer(java.lang.String name,
IRule rule,
LoadBalancerStats stats,
IPing ping)
public BaseLoadBalancer(com.netflix.client.config.IClientConfig config)
public BaseLoadBalancer(com.netflix.client.config.IClientConfig config,
IRule rule,
IPing ping)
| Method Detail |
|---|
public void initWithNiwsConfig(com.netflix.client.config.IClientConfig clientConfig)
initWithNiwsConfig in interface com.netflix.client.IClientConfigAwarepublic void addServerListChangeListener(ServerListChangeListener listener)
public void removeServerListChangeListener(ServerListChangeListener listener)
public com.netflix.client.config.IClientConfig getClientConfig()
public java.lang.String getName()
public LoadBalancerStats getLoadBalancerStats()
AbstractLoadBalancer
getLoadBalancerStats in class AbstractLoadBalancerpublic void setLoadBalancerStats(LoadBalancerStats lbStats)
public java.util.concurrent.locks.Lock lockAllServerList(boolean write)
public java.util.concurrent.locks.Lock lockUpServerList(boolean write)
public void setPingInterval(int pingIntervalSeconds)
public int getPingInterval()
public void setMaxTotalPingTime(int maxTotalPingTimeSeconds)
public int getMaxTotalPingTime()
public IPing getPing()
public IRule getRule()
public boolean isPingInProgress()
public void setPing(IPing ping)
public void setRule(IRule rule)
public int getServerCount(boolean onlyAvailable)
onlyAvailable - if true, return only up servers.public void addServer(Server newServer)
public void addServers(java.util.List<Server> newServers)
addServers in interface ILoadBalancernewServers - new servers to addpublic void setServersList(java.util.List lsrv)
public Server getServerByIndex(int index,
boolean availableOnly)
index - availableOnly - public java.util.List<Server> getServerList(boolean availableOnly)
ILoadBalancer
getServerList in interface ILoadBalanceravailableOnly - if true, only live and available servers should be returnedpublic java.util.List<Server> getServerList(AbstractLoadBalancer.ServerGroup serverGroup)
AbstractLoadBalancer
getServerList in class AbstractLoadBalancerserverGroup - Servers grouped by status, e.g., AbstractLoadBalancer.ServerGroup.STATUS_UPpublic void cancelPingTask()
public Server chooseServer(java.lang.Object key)
ILoadBalancer
chooseServer in interface ILoadBalancerkey - An object that the load balancer may use to determine which server to return. null if
the load balancer does not use this parameter.
public java.lang.String choose(java.lang.Object key)
public void markServerDown(Server server)
ILoadBalancer
markServerDown in interface ILoadBalancerserver - Server to mark as downpublic void markServerDown(java.lang.String id)
public void forceQuickPing()
public java.lang.String toString()
toString in class java.lang.Objectprotected void init()
public final PrimeConnections getPrimeConnections()
public final void setPrimeConnections(PrimeConnections primeConnections)
public void primeCompleted(Server s,
java.lang.Throwable lastException)
primeCompleted in interface PrimeConnections.PrimeConnectionListenerpublic boolean isEnablePrimingConnections()
public final void setEnablePrimingConnections(boolean enablePrimingConnections)
public void shutdown()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||