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:
ProCluster

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 addDynamicServer(ClusterServer server)
          Adds a new server to the cluster.
 void addDynamicServer(java.lang.String serverId, java.lang.String address, int port)
          Adds a new server to the cluster.
 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 createJdbcStore()
           
 Machine createMachine()
          Adds a new server to the cluster.
protected  StoreManager createPersistentStore(java.lang.String type)
          Creates a persistent store instance.
protected  Server createResinServer(ClusterServer clusterServer)
           
 ClusterServer createServer()
          Adds a new server to the cluster.
static int decode(int code)
           
 void environmentBind(EnvironmentClassLoader loader)
          Handles the case where the environment is starting (after init).
 void environmentConfigure(EnvironmentClassLoader loader)
          Handles the case where the environment is configured (after init).
 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.
 ClusterServer findServer(java.lang.String address, int port)
          Finds the first server with the given server-id.
 void generateBackup(java.lang.StringBuilder sb, int index)
           
 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.
static Cluster getCluster(java.lang.ClassLoader loader)
          Returns the currently active local cluster.
static Cluster getCurrent()
          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.
 int getPrimaryIndex(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.
 int getSecondaryIndex(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.
 int getTertiaryIndex(java.lang.String id, int offset)
          Returns the tertiary server.
 long getVersion()
          Returns the version
 boolean isDynamicServerEnable()
          Enables dynamic servers
 void removeDynamicServer(ClusterServer server)
          Adds a new server to the cluster.
 void setDynamicServerEnable(boolean isEnable)
          Enables dynamic servers
 void setId(java.lang.String id)
          Sets the cluster id.
 void setRootDirectory(Path rootDirectory)
          Sets the root directory.
protected  void setStore(StoreManager store)
          Sets the cluster store.
 void start()
          Initializes the cluster.
 void startClusterUpdate()
           
 void startPersistentStore()
           
 void startRemote()
          Start any work in notifying other members in the cluster that the server is active.
 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.


getCurrent

public static Cluster getCurrent()
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.


setDynamicServerEnable

public void setDynamicServerEnable(boolean isEnable)
Enables dynamic servers


isDynamicServerEnable

public boolean isDynamicServerEnable()
Enables dynamic servers


getVersion

public long getVersion()
Returns the version


getAdmin

public ClusterMXBean getAdmin()
Returns the admin.


findServer

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


findServer

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


addServerDefault

public void addServerDefault(ContainerProgram program)
Adds a new server to the cluster.


createMachine

public Machine createMachine()
Adds a new server to the cluster.


createServer

public ClusterServer createServer()
Adds a new server to the cluster.


addServer

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

Throws:
ConfigException

addDynamicServer

public void addDynamicServer(java.lang.String serverId,
                             java.lang.String address,
                             int port)
                      throws ConfigException
Adds a new server to the cluster.

Throws:
ConfigException

addDynamicServer

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

Throws:
ConfigException

removeDynamicServer

public void removeDynamicServer(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.


setStore

protected void setStore(StoreManager store)
Sets the cluster store.


createJdbcStore

public StoreManager createJdbcStore()
                             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.


createResinServer

protected Server createResinServer(ClusterServer clusterServer)

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.


generateBackup

public void generateBackup(java.lang.StringBuilder sb,
                           int index)

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.


getPrimaryIndex

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


getSecondaryIndex

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


getTertiaryIndex

public int getTertiaryIndex(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.


startRemote

public void startRemote()
Start any work in notifying other members in the cluster that the server is active.


createPersistentStore

protected StoreManager createPersistentStore(java.lang.String type)
Creates a persistent store instance.


startPersistentStore

public void startPersistentStore()

startClusterUpdate

public void startClusterUpdate()

environmentConfigure

public void environmentConfigure(EnvironmentClassLoader loader)
Handles the case where the environment is configured (after init).

Specified by:
environmentConfigure in interface EnvironmentListener

environmentBind

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

Specified by:
environmentBind in interface EnvironmentListener

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)