com.caucho.server.cluster
Class Cluster

java.lang.Object
  extended by com.caucho.server.cluster.Cluster
All Implemented Interfaces:
SchemaBean, EnvironmentBean, EnvironmentListener
Direct Known Subclasses:
ClusterDef

public class Cluster
extends java.lang.Object
implements EnvironmentListener, EnvironmentBean, SchemaBean

Defines a set of clustered servers.


Nested Class Summary
 class Cluster.ServerVar
           
 class Cluster.Var
          EL variables
 
Field Summary
protected static EnvironmentLocal<Cluster> _clusterLocal
           
protected static EnvironmentLocal<java.lang.String> _serverIdLocal
           
 
Constructor Summary
Cluster()
           
Cluster(Resin resin)
           
 
Method Summary
 void addBuilderProgram(ConfigProgram program)
          Adds a program.
 void addServer(ClusterServer server)
          Adds a new server to the cluster.
 void addServerDefault(ContainerProgram program)
          Adds a new server to the cluster.
 void classLoaderDestroy(DynamicClassLoader loader)
          Handles the case where a class loader is dropped.
 void classLoaderInit(DynamicClassLoader loader)
          Handles the case where a class loader has completed initialization
 void close()
          Closes the cluster.
 StoreManager createClusterStore()
           
 StoreManager createFileStore()
           
 StoreManager createJdbcStore()
           
 Machine createMachine()
          Adds a new server to the cluster.
 StoreManager createPrivateFileStore()
           
 ClusterServer createServer()
          Adds a new server to the cluster.
static int decode(int code)
           
 void environmentStart(EnvironmentClassLoader loader)
          Handles the case where the environment is starting (after init).
 void environmentStop(EnvironmentClassLoader loader)
          Handles the case where the environment is stopping
 ServerConnector findConnector(java.lang.String address, int port)
          Adds a srun server.
 ClusterServer findServer(java.lang.String id)
          Finds the first server with the given server-id.
 long generateBackupCode(int index)
          Generate the primary, secondary, tertiary, returning the value encoded in a long.
 void generateBackupCode(java.lang.StringBuilder cb, long backupCode)
          Adds the primary/backup/third digits to the id.
 ClusterMXBean getAdmin()
          Returns the admin.
 java.lang.ClassLoader getClassLoader()
          Returns the environment class loader.
 long getClientConnectTimeout()
          Gets the connect timeout.
 long getClientFailRecoverTime()
          Gets the client fail-recover time.
 long getClientMaxIdleTime()
          Gets the live time.
 long getClientReadTimeout()
          Gets the read timeout.
 long getClientWarmupTime()
          Gets the client warmup time.
static Cluster getCluster(java.lang.ClassLoader loader)
          Returns the currently active local cluster.
 java.lang.String getId()
          Gets the cluster id.
static Cluster getLocal()
          Returns the currently active local cluster.
 java.util.ArrayList<Machine> getMachineList()
          Returns the machine list.
 javax.management.ObjectName getObjectName()
          Returns the JMX object name.
 ClusterServer getPrimary(java.lang.String id, int offset)
          Returns the primary server.
 Resin getResin()
          Returns the owning resin server.
 Path getRootDirectory()
          Gets the root directory.
 java.lang.String getSchema()
          Returns the relax schema.
 ClusterServer getSecondary(java.lang.String id, int offset)
          Returns the secondary server.
 ClusterServer getSelfServer()
          Returns the server corresponding to the current server-id.
 ClusterServer getServer(int index)
          Returns the server with the matching index.
 ClusterServer getServer(java.lang.String serverId)
          Returns the server in the cluster with the given server-id.
static java.lang.String getServerId()
          Returns the server id.
 ClusterServer[] getServerList()
          Returns the server list.
 java.util.ArrayList<ClusterPort> getServerPorts(java.lang.String serverId)
          Returns the matching ports.
 StoreManager getStore()
          Returns the cluster store.
 ClusterServer getTertiary(java.lang.String id, int offset)
          Returns the tertiary server.
 void setClientConnectTimeout(Period period)
          Sets the connect timeout.
 void setClientDeadTime(Period period)
          Deprecated.  
 void setClientFailRecoverTime(Period period)
          Sets the client connection fail-recover time.
 void setClientLiveTime(Period period)
          Deprecated.  
 void setClientMaxIdleTime(Period period)
          Sets the max-idle time.
 void setClientReadTimeout(Period period)
          Sets the read timeout.
 void setClientWarmupTime(Period period)
          Sets the client warmup time.
 void setClientWriteTimeout(Period period)
          Sets the write timeout.
 void setId(java.lang.String id)
          Sets the cluster id.
 void setRootDirectory(Path rootDirectory)
          Sets the root directory.
 void start()
          Initializes the cluster.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_serverIdLocal

protected static final EnvironmentLocal<java.lang.String> _serverIdLocal

_clusterLocal

protected static final EnvironmentLocal<Cluster> _clusterLocal
Constructor Detail

Cluster

public Cluster(Resin resin)

Cluster

public Cluster()
Method Detail

getLocal

public static Cluster getLocal()
Returns the currently active local cluster.


getCluster

public static Cluster getCluster(java.lang.ClassLoader loader)
Returns the currently active local cluster.


setId

public void setId(java.lang.String id)
Sets the cluster id.


getId

public java.lang.String getId()
Gets the cluster id.


getResin

public Resin getResin()
Returns the owning resin server.


getClassLoader

public java.lang.ClassLoader getClassLoader()
Returns the environment class loader.

Specified by:
getClassLoader in interface EnvironmentBean

getSchema

public java.lang.String getSchema()
Returns the relax schema.

Specified by:
getSchema in interface SchemaBean

getRootDirectory

public Path getRootDirectory()
Gets the root directory.


setRootDirectory

public void setRootDirectory(Path rootDirectory)
Sets the root directory.


getAdmin

public ClusterMXBean getAdmin()
Returns the admin.


findServer

public ClusterServer findServer(java.lang.String id)
Finds the first server with the given server-id.


addServerDefault

public void addServerDefault(ContainerProgram program)
                      throws java.lang.Throwable
Adds a new server to the cluster.

Throws:
java.lang.Throwable

createMachine

public Machine createMachine()
                      throws java.lang.Exception
Adds a new server to the cluster.

Throws:
java.lang.Exception

createServer

public ClusterServer createServer()
                           throws java.lang.Exception
Adds a new server to the cluster.

Throws:
java.lang.Exception

addServer

public void addServer(ClusterServer server)
               throws ConfigException
Adds a new server to the cluster.

Throws:
ConfigException

findConnector

public ServerConnector findConnector(java.lang.String address,
                                     int port)
Adds a srun server.


getStore

public StoreManager getStore()
Returns the cluster store.


setClientMaxIdleTime

public void setClientMaxIdleTime(Period period)
Sets the max-idle time.


getClientMaxIdleTime

public long getClientMaxIdleTime()
Gets the live time.


setClientLiveTime

public void setClientLiveTime(Period period)
Deprecated. 

Sets the live time.


setClientFailRecoverTime

public void setClientFailRecoverTime(Period period)
Sets the client connection fail-recover time.


getClientFailRecoverTime

public long getClientFailRecoverTime()
Gets the client fail-recover time.


setClientDeadTime

public void setClientDeadTime(Period period)
Deprecated. 

Sets the dead time.


setClientWarmupTime

public void setClientWarmupTime(Period period)
Sets the client warmup time.


getClientWarmupTime

public long getClientWarmupTime()
Gets the client warmup time.


setClientConnectTimeout

public void setClientConnectTimeout(Period period)
Sets the connect timeout.


getClientConnectTimeout

public long getClientConnectTimeout()
Gets the connect timeout.


setClientReadTimeout

public void setClientReadTimeout(Period period)
Sets the read timeout.


getClientReadTimeout

public long getClientReadTimeout()
Gets the read timeout.


setClientWriteTimeout

public void setClientWriteTimeout(Period period)
Sets the write timeout.


createJdbcStore

public StoreManager createJdbcStore()
                             throws ConfigException
Throws:
ConfigException

createPrivateFileStore

public StoreManager createPrivateFileStore()
                                    throws ConfigException
Throws:
ConfigException

createFileStore

public StoreManager createFileStore()
                             throws ConfigException
Throws:
ConfigException

createClusterStore

public StoreManager createClusterStore()
                                throws ConfigException
Throws:
ConfigException

addBuilderProgram

public void addBuilderProgram(ConfigProgram program)
Adds a program.


start

public void start()
           throws ConfigException
Initializes the cluster.

Throws:
ConfigException

getServerId

public static java.lang.String getServerId()
Returns the server id.


getObjectName

public javax.management.ObjectName getObjectName()
Returns the JMX object name.


getSelfServer

public ClusterServer getSelfServer()
Returns the server corresponding to the current server-id.


getServerList

public ClusterServer[] getServerList()
Returns the server list.


getMachineList

public java.util.ArrayList<Machine> getMachineList()
Returns the machine list.


getServer

public ClusterServer getServer(java.lang.String serverId)
Returns the server in the cluster with the given server-id.


getServer

public ClusterServer getServer(int index)
Returns the server with the matching index.


getServerPorts

public java.util.ArrayList<ClusterPort> getServerPorts(java.lang.String serverId)
Returns the matching ports.


generateBackupCode

public long generateBackupCode(int index)
Generate the primary, secondary, tertiary, returning the value encoded in a long.


generateBackupCode

public void generateBackupCode(java.lang.StringBuilder cb,
                               long backupCode)
Adds the primary/backup/third digits to the id.


getPrimary

public ClusterServer getPrimary(java.lang.String id,
                                int offset)
Returns the primary server.


getSecondary

public ClusterServer getSecondary(java.lang.String id,
                                  int offset)
Returns the secondary server.


getTertiary

public ClusterServer getTertiary(java.lang.String id,
                                 int offset)
Returns the tertiary server.


classLoaderInit

public void classLoaderInit(DynamicClassLoader loader)
Handles the case where a class loader has completed initialization


classLoaderDestroy

public void classLoaderDestroy(DynamicClassLoader loader)
Handles the case where a class loader is dropped.


environmentStart

public void environmentStart(EnvironmentClassLoader loader)
Handles the case where the environment is starting (after init).

Specified by:
environmentStart in interface EnvironmentListener

environmentStop

public void environmentStop(EnvironmentClassLoader loader)
Handles the case where the environment is stopping

Specified by:
environmentStop in interface EnvironmentListener

close

public void close()
Closes the cluster.


toString

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

decode

public static int decode(int code)