|
|||||||||
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 |
CONNECTION_VERBOSITY_LEVEL
|
static int |
DEFAULT_HUB_CONTACT_POLICY
Default policy when contacting Hubs is: |
static int |
DEFAULT_VERBOSITY_LEVEL
|
static int |
ERROR_DETAILS_VERBOSITY_LEVEL
|
static int |
ERROR_VERBOSITY_LEVEL
|
static int |
FATAL_DETAILS_VERBOSITY_LEVEL
|
static int |
FATAL_VERBOSITY_LEVEL
|
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
|
static int |
INITIALIZATION_DETAILS_VERBOSITY_LEVEL
|
static int |
MAX_VERBOSITY_LEVEL
|
static int |
MIN_VERBOSITY_LEVEL
|
protected java.lang.String |
name
This server's name. |
static int |
NIL_VERBOSITY_LEVEL
|
protected java.lang.String |
serverClassName
The name of the Server class to construct to handle a new socket connection. |
static int |
THREAD_ACTIVITY_VERBOSITY_LEVEL
|
static int |
TRAFFIC_DETAILS_VERBOSITY_LEVEL
|
static int |
TRAFFIC_SUMMARY_VERBOSITY_LEVEL
|
static int |
TRANSPORT_DETAILS_VERBOSITY_LEVEL
|
static int |
TRANSPORT_SUMMARY_VERBOSITY_LEVEL
|
static int |
WARNING_VERBOSITY_LEVEL
|
Constructor Summary | |
MainServer()
Default constructor. |
|
MainServer(java.lang.String name)
Constructor. |
|
MainServer(java.lang.String name,
int port)
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,
int port)
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. |
|
MainServer(java.lang.String name,
java.lang.String[] args,
java.lang.String helpText,
int port)
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)
Deprecated. As of Galaxy Communicator 4.0. Use logErrorMessage(String). |
protected void |
error(java.lang.String msg,
java.lang.Exception ex)
Deprecated. As of Galaxy Communicator 4.0. Use logErrorMessage(String, Exception). |
protected void |
fatal(java.lang.String msg)
Deprecated. As of Galaxy Communicator 4.0. Use logFatalMessage(String). |
protected void |
fatal(java.lang.String msg,
java.lang.Exception ex)
Deprecated. As of Galaxy Communicator 4.0. Use logFatalMessage(String, Exception). |
ServerArgParser |
getArgParser()
|
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 of this server. |
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)
Deprecated. As of Galaxy Communicator 4.0. Use logMessage(String, int). |
void |
logErrorMessage(java.lang.String msg)
Displays an error message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.ERROR_VERBOSITY_LEVEL . |
void |
logErrorMessage(java.lang.String msg,
java.lang.Exception ex)
Displays an error message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.ERROR_VERBOSITY_LEVEL . |
void |
logErrorMessage(java.lang.String msg,
java.lang.Exception ex,
java.lang.String location)
Displays an error message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.ERROR_VERBOSITY_LEVEL . |
void |
logErrorMessage(java.lang.String msg,
java.lang.String location)
Displays an error message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.ERROR_VERBOSITY_LEVEL . |
void |
logFatalMessage(java.lang.String msg)
Displays a fatal error message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.FATAL_VERBOSITY_LEVEL . |
void |
logFatalMessage(java.lang.String msg,
java.lang.Exception ex)
Displays a fatal error message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.FATAL_VERBOSITY_LEVEL . |
void |
logFatalMessage(java.lang.String msg,
java.lang.Exception ex,
java.lang.String location)
Displays a fatal error message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.FATAL_VERBOSITY_LEVEL . |
void |
logFatalMessage(java.lang.String msg,
java.lang.String location)
Displays a fatal error message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.FATAL_VERBOSITY_LEVEL . |
void |
logMessage(java.lang.String msg)
Displays a message to System.out (at any verbosity level). |
void |
logMessage(java.lang.String msg,
int level)
Displays a message to System.out. |
void |
logMessage(java.lang.String msg,
int level,
java.lang.String location)
Displays a message to System.out. |
void |
logWarningMessage(java.lang.String msg)
Displays a warning message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.WARNING_VERBOSITY_LEVEL . |
void |
logWarningMessage(java.lang.String msg,
java.lang.String location)
Displays a warning message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.WARNING_VERBOSITY_LEVEL . |
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)
|
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()
Causes this server's thread to be 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 NIL_VERBOSITY_LEVEL
public static final int CONNECTION_VERBOSITY_LEVEL
public static final int ERROR_VERBOSITY_LEVEL
public static final int FATAL_VERBOSITY_LEVEL
public static final int WARNING_VERBOSITY_LEVEL
public static final int TRAFFIC_SUMMARY_VERBOSITY_LEVEL
public static final int TRAFFIC_DETAILS_VERBOSITY_LEVEL
public static final int ERROR_DETAILS_VERBOSITY_LEVEL
public static final int FATAL_DETAILS_VERBOSITY_LEVEL
public static final int INITIALIZATION_DETAILS_VERBOSITY_LEVEL
public static final int THREAD_ACTIVITY_VERBOSITY_LEVEL
public static final int TRANSPORT_SUMMARY_VERBOSITY_LEVEL
public static final int TRANSPORT_DETAILS_VERBOSITY_LEVEL
public static final int DEFAULT_VERBOSITY_LEVEL
public static final int MIN_VERBOSITY_LEVEL
public static final int MAX_VERBOSITY_LEVEL
Constructor Detail |
public MainServer()
public MainServer(java.lang.String name)
name
- the server's namepublic MainServer(java.lang.String name, int port)
name
- the server's nameport
- the port to use (ignored if set to -1)public 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, int port)
name
- the server's nameargs
- the command line argumentsport
- the port to use (ignored if set to -1)public 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 usedpublic MainServer(java.lang.String name, java.lang.String[] args, java.lang.String helpText, int port)
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 usedport
- the port to use (ignored if set to -1)Method 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 ServerArgParser getArgParser()
public void setValidate(boolean validate)
public void setSessionId(java.lang.String sessionId)
public java.lang.String getSessionId()
public void setPort(int port)
port
- this server's listener portpublic void setRequirePort(boolean requirePort)
public int getPort()
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)
public void logMessage(java.lang.String msg, int level)
DiagnosticLogger
logMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displaylevel
- the minimum verbosity level at which to display the message
(verbosity levels are defined in
galaxy.server.MainServer
)public void logMessage(java.lang.String msg, int level, java.lang.String location)
DiagnosticLogger
logMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displaylevel
- the minimum verbosity level at which to display the message
(verbosity levels are defined in
galaxy.server.MainServer
)location
- "location" of the associated call to this method
(e.g., the class and method name from which this call
was made) which is displayed at verbosity levels
4 and abovepublic void logMessage(java.lang.String msg)
DiagnosticLogger
logMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displaypublic void logErrorMessage(java.lang.String msg)
DiagnosticLogger
galaxy.server.MainServer.ERROR_VERBOSITY_LEVEL
.logErrorMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displaypublic void logErrorMessage(java.lang.String msg, java.lang.Exception ex)
DiagnosticLogger
galaxy.server.MainServer.ERROR_VERBOSITY_LEVEL
.logErrorMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displayex
- the stack trace of this exception is also displayedpublic void logErrorMessage(java.lang.String msg, java.lang.String location)
DiagnosticLogger
galaxy.server.MainServer.ERROR_VERBOSITY_LEVEL
.logErrorMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displaylocation
- "location" of the associated call to this method
(e.g., the class and method name from which this call
was made) which is displayed at verbosity levels
4 and abovepublic void logErrorMessage(java.lang.String msg, java.lang.Exception ex, java.lang.String location)
DiagnosticLogger
galaxy.server.MainServer.ERROR_VERBOSITY_LEVEL
.logErrorMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displayex
- the stack trace of this exception is also displayedlocation
- "location" of the associated call to this method
(e.g., the class and method name from which this call
was made) which is displayed at verbosity levels
4 and abovepublic void logFatalMessage(java.lang.String msg)
DiagnosticLogger
galaxy.server.MainServer.FATAL_VERBOSITY_LEVEL
.logFatalMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displaypublic void logFatalMessage(java.lang.String msg, java.lang.Exception ex)
DiagnosticLogger
galaxy.server.MainServer.FATAL_VERBOSITY_LEVEL
.logFatalMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displayex
- the stack trace of this exception is also displayedpublic void logFatalMessage(java.lang.String msg, java.lang.String location)
DiagnosticLogger
galaxy.server.MainServer.FATAL_VERBOSITY_LEVEL
.logFatalMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displaylocation
- "location" of the associated call to this method
(e.g., the class and method name from which this call
was made) which is displayed at verbosity levels
4 and abovepublic void logFatalMessage(java.lang.String msg, java.lang.Exception ex, java.lang.String location)
DiagnosticLogger
galaxy.server.MainServer.FATAL_VERBOSITY_LEVEL
.logFatalMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displayex
- the stack trace of this exception is also displayedlocation
- "location" of the associated call to this method
(e.g., the class and method name from which this call
was made) which is displayed at verbosity levels
4 and abovepublic void logWarningMessage(java.lang.String msg)
DiagnosticLogger
galaxy.server.MainServer.WARNING_VERBOSITY_LEVEL
.logWarningMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displaypublic void logWarningMessage(java.lang.String msg, java.lang.String location)
DiagnosticLogger
galaxy.server.MainServer.WARNING_VERBOSITY_LEVEL
.logWarningMessage
in interface DiagnosticLogger
galaxy.util.DiagnosticLogger
msg
- the message to displaylocation
- "location" of the associated call to this method
(e.g., the class and method name from which this call
was made) which is displayed at verbosity levels
4 and above
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |