org.jlab.coda.cMsg.cMsgDomain.server
Class cMsgNameServer

java.lang.Object
  extended by java.lang.Thread
      extended by org.jlab.coda.cMsg.cMsgDomain.server.cMsgNameServer
All Implemented Interfaces:
java.lang.Runnable

public class cMsgNameServer
extends java.lang.Thread

This class implements a cMsg name server in the cMsg domain. A word of caution. If multiple cMsgNameServer objects exist in a single JVM and they both service clients in the cMsg subdomain, then there will be undesirable effects. In other words, the cMsg subdomain uses static data in some of its implementing classes (cMsgServerBridge & subdomains.cMsg).

Version:
1.0
Author:
Carl Timmer

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
cMsgNameServer(int port, int udpPort, boolean timeOrdered, boolean standAlone, java.lang.String clientPassword, java.lang.String cloudPassword, int debug)
          Constructor which reads environmental variables and opens listening sockets.
 
Method Summary
 void cloudLock()
          This method locks a lock used in adding servers to the server cloud and in adding clients to servers.
 boolean cloudLock(int delay)
          This method locks a lock used in adding servers to the server cloud and in adding clients to servers.
 void cloudUnlock()
          This method unlocks a lock used in adding servers to the server cloud and in adding clients to servers.
 int getCloudStatus()
          Get the status of the relationship of this server to the cMsg subdomain server cloud.
 boolean getKillAllThreads()
          Gets boolean value specifying whether to kill this and all spawned threads.
 int getPort()
          Get the name server's listening port.
 java.lang.String getServerName()
          Get this server's name (host:port).
static void main(java.lang.String[] args)
          Run as a stand-alone application.
 void printSizes()
          This method prints out the sizes of all objects which store other objects.
 void run()
          This method is executed as a thread.
 void setCloudStatus(int status)
          Set the status of the relationship of this server to the cMsg subdomain server cloud.
 void setKillAllThreads(boolean b)
          Sets boolean to kill this and all spawned threads.
 void startServer(java.lang.String serverToJoin)
          Method to start up this server and join the cMsg server cloud that the argument, serverToJoin, is a part of.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

cMsgNameServer

public cMsgNameServer(int port,
                      int udpPort,
                      boolean timeOrdered,
                      boolean standAlone,
                      java.lang.String clientPassword,
                      java.lang.String cloudPassword,
                      int debug)
Constructor which reads environmental variables and opens listening sockets.

Parameters:
port - TCP listening port for communication from clients
udpPort - UDP listening port for receiving broadcasts from clients
timeOrdered - if true all client commands are processed in the order received
standAlone - if true no other cMsg servers are allowed to attached to this one and form a cloud
clientPassword - password client needs to provide to connect to this server
cloudPassword - password server needs to provide to connect to this server to become part of a cloud
debug - desired level of debug output
Method Detail

setKillAllThreads

public void setKillAllThreads(boolean b)
Sets boolean to kill this and all spawned threads.

Parameters:
b - setting to true will kill this and all spawned threads

getKillAllThreads

public boolean getKillAllThreads()
Gets boolean value specifying whether to kill this and all spawned threads.

Returns:
boolean value specifying whether to kill this and all spawned threads

cloudLock

public void cloudLock()
This method locks a lock used in adding servers to the server cloud and in adding clients to servers. This is used only in the cMsg subdomain.


cloudLock

public boolean cloudLock(int delay)
This method locks a lock used in adding servers to the server cloud and in adding clients to servers. This is used only in the cMsg subdomain.

Parameters:
delay - time in milliseconds to wait for the lock before timing out
Returns:
true if locked, false otherwise

cloudUnlock

public void cloudUnlock()
This method unlocks a lock used in adding servers to the server cloud and in adding clients to servers. This is used only in the cMsg subdomain.


getCloudStatus

public int getCloudStatus()
Get the status of the relationship of this server to the cMsg subdomain server cloud.

Returns:
status which is one of INCLOUD, NONCLOUD, or BECOMINGCLOUD

setCloudStatus

public void setCloudStatus(int status)
Set the status of the relationship of this server to the cMsg subdomain server cloud. The status may only be one of INCLOUD, NONCLOUD, or BECOMINGCLOUD.

Parameters:
status - status of the relationship of this server to the cMsg subdomain server cloud

getServerName

public java.lang.String getServerName()
Get this server's name (host:port).

Returns:
server's name

getPort

public int getPort()
Get the name server's listening port.

Returns:
listening port

printSizes

public void printSizes()
This method prints out the sizes of all objects which store other objects.


main

public static void main(java.lang.String[] args)
Run as a stand-alone application.


startServer

public void startServer(java.lang.String serverToJoin)
Method to start up this server and join the cMsg server cloud that the argument, serverToJoin, is a part of. If the argument is null, this server is the nucleas of a new server cloud.

Parameters:
serverToJoin - server whose cloud this server is to be joined to

run

public void run()
This method is executed as a thread.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread