|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--galaxy.server.MainServer
This is the base class for all Galaxy Java server applications. MainServer
is responsible for listening for connections and spawning
Server
s to service requests for those connections. MainServer
can also be configured to connect to a specified set of Hubs upon startup
rather than listening for connections.
You may add a MainServerListener
to receive events generated by
this class.
After constructing the main server, make calls to set options, then call
init()
to perform one time initialization. Options include the
port number to listen on, the name of the server class for handling
connections, and a list of Hub host/port pairs to which this server will
connect (if this latter option is set, the listener port setting for this
server is ignored). After this you may call start()
to start
listening for connections or connect this server to the specified Hub(s).
In the case where this server is listening for connections, when a new
connection is received, a server is created to handle the connection. The
name of the server class may be specified using
setServerClassName
before the main server is started. It
defaults to galaxy.server.Server
The name is used to
dynamically load the server class, and instantiate an instance to handle
the connection. This class must be a subclass of Server
.
In the case where this server is configured to connect to a Hub or set of Hubs, the connections are established, and a server is created for each connection to handle messages from the associated Hub.
This class is intended to be very generic. Subclasses are used to perform more specfic tasks.
Server
,
MainServerListener
Field Summary | |
protected ServerArgParser |
argParser
Argument parser. |
static int |
DEFAULT_HUB_CONTACT_POLICY
Default policy when contacting Hubs is: |
static int |
DEFAULT_VERBOSITY_LEVEL
Default verbosity level (all logging on). |
protected static int |
GAL_BROKER_LISTENER
If this bit is set in this servers connection flag, the server listens for connections from broker clients. |
protected static int |
GAL_CONNECTION_LISTENER
If this bit is set in this servers connection flag, the server listens for connections from Hubs. |
protected static int |
GAL_HUB_CLIENT
If this bit is set in this servers connection flag, the server contacts Hubs when establishing connections. |
static int |
GAL_HUB_CLIENT_CONNECT_FAILURE_MASK
|
static int |
GAL_HUB_CLIENT_CONNECT_FAILURE_NOOP
Indicates server should only make one attempt to contact Hub. |
static int |
GAL_HUB_CLIENT_CONNECT_FAILURE_RETRY
Indicates server should keep trying to connect to Hub until successful. |
static int |
GAL_HUB_CLIENT_CONNECT_FAILURE_SHUTDOWN
Indicates server should shutdown if it can not establish initial connection to Hub. |
static int |
GAL_HUB_CLIENT_DISCONNECT_MASK
|
static int |
GAL_HUB_CLIENT_DISCONNECT_NOOP
Indicates server should do nothing if connection to Hub is lost. |
static int |
GAL_HUB_CLIENT_DISCONNECT_RETRY
Indicates server should try to reconnect to Hub if connection to Hub is lost. |
static int |
GAL_HUB_CLIENT_DISCONNECT_SHUTDOWN
Indicates server should shutdown if connection to Hub is lost. |
protected static int |
GAL_SERVER_TYPE_MASK
|
protected java.lang.String |
name
This server's name. |
protected java.lang.String |
serverClassName
The name of the Server class to construct to handle a new socket connection. |
Constructor Summary | |
MainServer()
Default constructor. |
|
MainServer(java.lang.String name)
Constructor. |
|
MainServer(java.lang.String name,
java.lang.String[] args)
This constructor initializes itself based on the command line arguments. |
|
MainServer(java.lang.String name,
java.lang.String[] args,
java.lang.String helpText)
This constructor initializes itself based on the command line arguments. |
Method Summary | |
void |
addMainServerListener(MainServerListener listener)
Add a MainServerListener. |
protected void |
cleanup()
This cleanup method is called when this server is preparing to stop. |
void |
contactHub(java.lang.String host,
int port,
java.lang.String sessionId,
int hubContactPolicy)
Adds the specified Hub info to the list of Hubs to contact. |
protected void |
error(java.lang.String msg)
|
protected void |
error(java.lang.String msg,
java.lang.Exception ex)
|
protected void |
fatal(java.lang.String msg)
|
protected void |
fatal(java.lang.String msg,
java.lang.Exception ex)
|
int |
getHubContactPolicy()
Gets the current policy for contacting Hubs. |
int |
getMaxConnections()
|
java.lang.String |
getName()
Get this server's name. |
int |
getPort()
Returns the the current listener port (or the default) of this server. |
boolean |
getRequirePort()
Deprecated. As of Galaxy Communicator 3.0. Use isRequiredPort. |
java.lang.String |
getServerClassName()
|
java.lang.String |
getSessionId()
|
static int |
getVerbosityLevel()
Returns the current logging verbosity level. |
void |
init()
Call this function to initialize the main server. |
protected void |
initServer(Server server)
Called by the framework after createServer(). |
boolean |
isBrokerListener()
|
boolean |
isHubClient()
|
boolean |
isHubListener()
|
boolean |
isRequiredPort()
|
boolean |
isRunning()
|
protected boolean |
listenerHasPort()
Tests if the listener thread started by this server has acquired a port. |
protected void |
log(java.lang.String msg)
|
protected void |
registerOutBroker(DataOutBroker broker)
Registers an outgoing broker that is managed by this server. |
void |
removeMainServerListener(MainServerListener listener)
|
void |
run()
This server's main loop. |
void |
setActsAsBrokerListener(boolean actsAsBrokerListener)
|
void |
setActsAsHubClient(boolean actsAsHubClient)
|
void |
setActsAsHubListener(boolean actsAsHubListener)
|
void |
setHubContactInfoCollection(java.util.List newHubContactInfoCollection)
|
void |
setHubContactPolicy(int hubContactPolicy)
Sets the Hub contact policy (used if this server is a Hub client). |
void |
setMaxConnections(int maxConnections)
|
void |
setName(java.lang.String name)
Set this server's name. |
void |
setPort(int port)
Sets the listener port used by this server. |
void |
setRequirePort(boolean requirePort)
Sets the flag that indicates if the current listener port is required (i.e., if true, the server should exit if it cannot obtain the port). |
void |
setServerClassName(java.lang.String serverClassName)
|
void |
setSessionId(java.lang.String sessionId)
|
void |
setValidate(boolean validate)
|
static void |
setVerbosityLevel(int verbosityLevel)
Sets the current logging verbosity level. |
void |
start()
Starts this server's thread if it is not already running. |
protected boolean |
startBrokerListenerThread()
Starts this server's listener thread if it is not already running. |
void |
stop()
Marks this server's thread as being stopped. |
protected boolean |
unregisterOutBroker(DataOutBroker broker)
Unregisters an outgoing broker is managed by this server. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected volatile java.lang.String serverClassName
protected java.lang.String name
protected ServerArgParser argParser
protected static final int GAL_CONNECTION_LISTENER
protected static final int GAL_BROKER_LISTENER
protected static final int GAL_HUB_CLIENT
protected static final int GAL_SERVER_TYPE_MASK
public static final int GAL_HUB_CLIENT_CONNECT_FAILURE_RETRY
public static final int GAL_HUB_CLIENT_CONNECT_FAILURE_SHUTDOWN
public static final int GAL_HUB_CLIENT_CONNECT_FAILURE_NOOP
public static final int GAL_HUB_CLIENT_CONNECT_FAILURE_MASK
public static final int GAL_HUB_CLIENT_DISCONNECT_RETRY
public static final int GAL_HUB_CLIENT_DISCONNECT_SHUTDOWN
public static final int GAL_HUB_CLIENT_DISCONNECT_NOOP
public static final int GAL_HUB_CLIENT_DISCONNECT_MASK
public static final int DEFAULT_HUB_CONTACT_POLICY
a) When trying to establish connection to Hub, keep trying until successful.
b) When connection to Hub is lost, try to reconnect.
public static final int DEFAULT_VERBOSITY_LEVEL
Constructor Detail |
public MainServer()
public MainServer(java.lang.String name)
name
- the server's namepublic MainServer(java.lang.String name, java.lang.String[] args)
name
- the server's nameargs
- the command line argumentspublic MainServer(java.lang.String name, java.lang.String[] args, java.lang.String helpText)
name
- the server's nameargs
- the command line argumentshelpText
- this text is prepended to the message that is displayed
when the -help command line argument is usedMethod Detail |
public boolean isRunning()
public void setActsAsHubListener(boolean actsAsHubListener)
public boolean isHubListener()
public void setActsAsBrokerListener(boolean actsAsBrokerListener)
public boolean isBrokerListener()
public void setActsAsHubClient(boolean actsAsHubClient)
public boolean isHubClient()
public void setValidate(boolean validate)
public void setSessionId(java.lang.String sessionId)
public java.lang.String getSessionId()
public void setPort(int port)
setRequirePort
has been previously called, calling
setPort
will not change the listener port used by this
server. setRequirePort
would need to be called again
to set the required port to be the new port.port
- this server's listener portpublic int getPort()
public void setRequirePort(boolean requirePort)
requirePort
- true if (the current port is required), false
otherwisepublic boolean getRequirePort()
public boolean isRequiredPort()
public void setServerClassName(java.lang.String serverClassName)
public java.lang.String getServerClassName()
public void setHubContactInfoCollection(java.util.List newHubContactInfoCollection)
public void setMaxConnections(int maxConnections)
public int getMaxConnections()
public void setName(java.lang.String name)
name
- the server's name. A value of null
is ignored
and the current name is retained.public java.lang.String getName()
public void setHubContactPolicy(int hubContactPolicy)
hubContactPolicy
- the policy. Valid values include
MainServer.DEFAULT_HUB_CONTACT_POLICY, and any or'ed
combination of one of a)
MainServer.GAL_HUB_CLIENT_CONNECT_FAILURE_RETRY,
MainServer.GAL_HUB_CLIENT_CONNECT_FAILURE_SHUTDOWN, or
MainServer.GAL_HUB_CLIENT_CONNECT_FAILURE_NOOP, and one of b)
MainServer.GAL_HUB_CLIENT_DISCONNECT_RETRY,
MainServer.GAL_HUB_CLIENT_DISCONNECT_SHUTDOWN, and
MainServer.GAL_HUB_CLIENT_DISCONNECT_NOOP.public int getHubContactPolicy()
public static void setVerbosityLevel(int verbosityLevel)
verbosityLevel
- the verbosity level. At the moment, the only
valid values are0 (no logging) and 1 (all logging
on). If an invalid value is specified, the
current verbosity level is not changed.public static int getVerbosityLevel()
public void contactHub(java.lang.String host, int port, java.lang.String sessionId, int hubContactPolicy)
host
- name of the Hub's host machineport
- listener port of the HubsessionId
- session id to use for the connectionhubContactPolicy
- Hub contact policy flag (if -1, current
policy of this MainServer is always used).protected boolean listenerHasPort()
protected boolean startBrokerListenerThread()
public void init() throws java.lang.Exception
public void start()
protected void cleanup()
Server
objects (and their outgoing brokers)
created by this server have stopped.
Override this method to provide your own customized cleanup routine.public void stop()
public void run()
run
in interface java.lang.Runnable
protected void initServer(Server server) throws java.lang.Exception
protected void registerOutBroker(DataOutBroker broker)
broker
- the brokerprotected boolean unregisterOutBroker(DataOutBroker broker)
broker
- the brokerpublic void addMainServerListener(MainServerListener listener)
public void removeMainServerListener(MainServerListener listener)
protected void log(java.lang.String msg)
protected void error(java.lang.String msg)
protected void error(java.lang.String msg, java.lang.Exception ex)
protected void fatal(java.lang.String msg)
protected void fatal(java.lang.String msg, java.lang.Exception ex)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |