com.caucho.server.cluster
Class ServerPool

java.lang.Object
  extended by com.caucho.server.cluster.ServerPool

public class ServerPool
extends java.lang.Object

A pool of connections to a Resin server.


Constructor Summary
ServerPool(java.lang.String serverId, ClusterServer server)
           
ServerPool(java.lang.String serverId, java.lang.String targetId, java.lang.String address, int port, boolean isSecure)
           
 
Method Summary
 void allocateLoadBalance()
          Allocate a connection for load balancing.
 void busy()
          Called when the server responds with "busy", e.g.
 boolean canConnect()
          Returns true if can connect to the client.
 boolean canOpenSoft()
          Returns true if the server can open a connection.
 boolean canOpenSoftOrRecycle()
          Returns true if the server can open a connection.
 void clearRecycle()
          Clears the recycled connections, e.g.
 void close()
          Close the client
 void disable()
          Disable the client
 void enable()
          Enable the client
 void enableSessionOnly()
          Session only
 void failConnect()
          Called when the socket read/write fails.
 void failSocket()
          Called when the socket read/write fails.
 void freeLoadBalance()
          Free a connection for load balancing.
 int getActiveCount()
          Returns the number of active connections.
 java.lang.String getAddress()
          Returns the hostname of the target server.
 long getBusyCountTotal()
          Returns the count of busy connections.
 long getConnectCountTotal()
          Returns the total number of successful socket connections
 double getCpuLoadAvg()
          Gets the CPU load avg
 java.lang.String getDebugId()
          Returns the debug id.
 long getFailCountTotal()
          Returns the total number of failed connect attempts.
 java.lang.String getId()
          Returns the user-readable id of the target server.
 int getIdleCount()
          Returns the number of idle connections.
 long getKeepaliveCountTotal()
          Returns the number of times a keepalive connection has been used.
 java.util.Date getLastBusyTime()
          Returns the time of the last busy.
 java.util.Date getLastFailConnectTime()
          Returns the time of the last failure.
 java.util.Date getLastFailTime()
          Returns the time of the last failure.
 long getLastSuccessTime()
          Returns the time of the last failure.
 double getLatencyFactor()
          Returns the latency factory
 int getLoadBalanceAllocateCount()
          Returns the number of load balance allocations
 long getLoadBalanceConnectTimeout()
          The socket timeout when connecting to the target server.
 long getLoadBalanceIdleTime()
          How long the connection can be cached in the free pool.
 long getLoadBalanceSocketTimeout()
          The socket timeout when reading from the target server.
 int getLoadBalanceWeight()
          The load balance weight.
 int getPort()
          Gets the port of the target server.
 java.lang.String getState()
          Returns the lifecycle state.
 void init()
          Initialize
 boolean isActive()
          Returns true if the server is active.
 boolean isDead()
          Returns true if the server is dead.
 boolean isEnabled()
          Return true if active.
 boolean message(java.lang.String to, java.io.Serializable message)
          Non-blocking message
 ClusterStream open()
          Open a stream to the target server for the load balancer.
 ClusterStream openForSession()
          Open a stream to the target server for a session.
 ClusterStream openIfLive()
          Open a stream to the target server object persistence.
 ClusterStream openSoft()
          Open a stream to the target server.
 java.lang.Object queryGet(java.lang.String to, java.io.Serializable query)
          Blocking 'GET' query
 java.lang.Object querySet(java.lang.String to, java.io.Serializable query)
           
 void setCpuLoadAvg(double load)
          Sets the CPU load avg (from backend).
 void setLoadBalanceConnectTimeout(long timeout)
          The socket timeout when connecting to the target server.
 void setLoadBalanceIdleTime(long timeout)
          How long the connection can be cached in the free pool.
 void setLoadBalanceRecoverTime(long timeout)
          Returns how long the connection will be treated as dead.
 void setLoadBalanceSocketTimeout(long timeout)
          The socket timeout when reading from the target server.
 void setLoadBalanceWarmupTime(long timeout)
          Returns the time in milliseconds for the slow start throttling.
 void setLoadBalanceWeight(int weight)
          The load balance weight.
 void start()
          Enable the client.
 void stop()
          Disable the client.
 void toBusy()
           
 void toFail()
           
 java.lang.String toString()
           
 void wake()
          We now know that the server is live, e.g.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServerPool

public ServerPool(java.lang.String serverId,
                  java.lang.String targetId,
                  java.lang.String address,
                  int port,
                  boolean isSecure)

ServerPool

public ServerPool(java.lang.String serverId,
                  ClusterServer server)
Method Detail

getId

public java.lang.String getId()
Returns the user-readable id of the target server.


getDebugId

public java.lang.String getDebugId()
Returns the debug id.


getAddress

public java.lang.String getAddress()
Returns the hostname of the target server.


getPort

public int getPort()
Gets the port of the target server.


getLoadBalanceConnectTimeout

public long getLoadBalanceConnectTimeout()
The socket timeout when connecting to the target server.


setLoadBalanceConnectTimeout

public void setLoadBalanceConnectTimeout(long timeout)
The socket timeout when connecting to the target server.


getLoadBalanceSocketTimeout

public long getLoadBalanceSocketTimeout()
The socket timeout when reading from the target server.


setLoadBalanceSocketTimeout

public void setLoadBalanceSocketTimeout(long timeout)
The socket timeout when reading from the target server.


getLoadBalanceIdleTime

public long getLoadBalanceIdleTime()
How long the connection can be cached in the free pool.


setLoadBalanceIdleTime

public void setLoadBalanceIdleTime(long timeout)
How long the connection can be cached in the free pool.


setLoadBalanceRecoverTime

public void setLoadBalanceRecoverTime(long timeout)
Returns how long the connection will be treated as dead.


setLoadBalanceWarmupTime

public void setLoadBalanceWarmupTime(long timeout)
Returns the time in milliseconds for the slow start throttling.


getLoadBalanceWeight

public int getLoadBalanceWeight()
The load balance weight.


setLoadBalanceWeight

public void setLoadBalanceWeight(int weight)
The load balance weight.


init

public void init()
          throws java.lang.Exception
Initialize

Throws:
java.lang.Exception

getActiveCount

public int getActiveCount()
Returns the number of active connections.


getIdleCount

public int getIdleCount()
Returns the number of idle connections.


getLoadBalanceAllocateCount

public int getLoadBalanceAllocateCount()
Returns the number of load balance allocations


allocateLoadBalance

public void allocateLoadBalance()
Allocate a connection for load balancing.


freeLoadBalance

public void freeLoadBalance()
Free a connection for load balancing.


getConnectCountTotal

public long getConnectCountTotal()
Returns the total number of successful socket connections


getKeepaliveCountTotal

public long getKeepaliveCountTotal()
Returns the number of times a keepalive connection has been used.


getFailCountTotal

public long getFailCountTotal()
Returns the total number of failed connect attempts.


getLastFailTime

public java.util.Date getLastFailTime()
Returns the time of the last failure.


getLastFailConnectTime

public java.util.Date getLastFailConnectTime()
Returns the time of the last failure.


getLastSuccessTime

public long getLastSuccessTime()
Returns the time of the last failure.


getLatencyFactor

public double getLatencyFactor()
Returns the latency factory


getBusyCountTotal

public long getBusyCountTotal()
Returns the count of busy connections.


getLastBusyTime

public java.util.Date getLastBusyTime()
Returns the time of the last busy.


setCpuLoadAvg

public void setCpuLoadAvg(double load)
Sets the CPU load avg (from backend).


getCpuLoadAvg

public double getCpuLoadAvg()
Gets the CPU load avg


isActive

public final boolean isActive()
Returns true if the server is active.


isDead

public boolean isDead()
Returns true if the server is dead.


enable

public void enable()
Enable the client


disable

public void disable()
Disable the client


getState

public java.lang.String getState()
Returns the lifecycle state.


canOpenSoftOrRecycle

public boolean canOpenSoftOrRecycle()
Returns true if the server can open a connection.


canOpenSoft

public boolean canOpenSoft()
Returns true if the server can open a connection.


isEnabled

public boolean isEnabled()
Return true if active.


toBusy

public void toBusy()

toFail

public void toFail()

failSocket

public void failSocket()
Called when the socket read/write fails.


failConnect

public void failConnect()
Called when the socket read/write fails.


busy

public void busy()
Called when the server responds with "busy", e.g. HTTP 503


start

public void start()
Enable the client.


stop

public void stop()
Disable the client.


enableSessionOnly

public void enableSessionOnly()
Session only


openSoft

public ClusterStream openSoft()
Open a stream to the target server.

Returns:
the socket's read/write pair.

openIfLive

public ClusterStream openIfLive()
Open a stream to the target server object persistence.

Returns:
the socket's read/write pair.

openForSession

public ClusterStream openForSession()
Open a stream to the target server for a session.

Returns:
the socket's read/write pair.

open

public ClusterStream open()
Open a stream to the target server for the load balancer.

Returns:
the socket's read/write pair.

wake

public void wake()
We now know that the server is live, e.g. if a sibling has contacted us.


clearRecycle

public void clearRecycle()
Clears the recycled connections, e.g. on detection of backend server going down.


close

public void close()
Close the client


canConnect

public boolean canConnect()
Returns true if can connect to the client.


message

public boolean message(java.lang.String to,
                       java.io.Serializable message)
Non-blocking message


queryGet

public java.lang.Object queryGet(java.lang.String to,
                                 java.io.Serializable query)
Blocking 'GET' query


querySet

public java.lang.Object querySet(java.lang.String to,
                                 java.io.Serializable query)
                          throws java.io.IOException
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object