galaxy.server
Class Server

java.lang.Object
  |
  +--galaxy.server.Server
All Implemented Interfaces:
DiagnosticLogger, java.lang.Runnable

public class Server
extends java.lang.Object
implements java.lang.Runnable, DiagnosticLogger

This is the base class for all Galaxy servers implemented in Java. It implements the basic message loop, logging, and the symbolic invocation of the dispatch function defined in the received frame.

You can add a ServerListener to receive notification of Server events.

See Also:
MainServer, ServerListener

Field Summary
protected  MainServer mainServer
          Reference to the MainServer that started this server.
 
Constructor Summary
Server(MainServer mainServer, java.net.Socket socket)
          Creates a new server.
 
Method Summary
protected  void addContinuationData(int serverTidx, ContinuationData data)
          Stores continuation data associated with a server token index.
 void addServerListener(ServerListener listener)
           
 void addServiceType(java.lang.String serviceType)
          Adds a service type to this server's lists of supported service types if it is not already in the list.
protected  void addSignature(Signature sig)
          Adds new signature information for this server.
protected  void cleanup()
          This cleanup method is called when this server is preparing to stop.
protected  void deleteServerProperties(java.lang.String[] keys)
          Deletes the specified server properties.
protected  GVector encodeSignatures()
          Encodes this server's signature information in a GVector.
protected  GFrame evaluateHubFrame(GFrame frame)
          Evaluates the Hub frame.
protected  ContinuationData getContinuationData(int serverTidx)
          Gets the continuation data associated with a server token index.
 Environment getCopyOfCurrentEnvironment()
          Returns a copy of this server's current execution environment.
 Environment getCurrentEnvironment()
          Returns this server current execution environment.
 java.lang.String getHostAddress()
          Gets the host address for this server's local host.
 int getHubContactPolicy()
          Gets the Hub contact policy (used if this server is a Hub client).
 java.net.InetAddress getIPAddress()
          Gets the internet address information for this server's local host.
 MainServer getMainServer()
          Returns the reference to the MainServer that started this server.
 GFrame getServerProperties()
          Gets this server's properties.
 GVector getServiceTypes()
          Gets the service types supported by this server.
 java.lang.String getSessionId()
          Gets the session id.
protected  Signature getSignature(java.lang.String op)
          Gets the signature information associated with an operation on this server's interface
 boolean getValidate()
          Gets the value of the method signature validation flag.
 void init()
          Called before server starts.
 boolean isRunning()
          Indicates if this server's thread is marked as running or stopped.
 void log(java.lang.String msg)
          Deprecated. As of Galaxy Communicator 4.0. Use logMessage(String, int).
protected  void logAndSendError(java.lang.String msg)
          Deprecated. As of Galaxy Communicator 4.0. Use logAndSendErrorMessage(String).
protected  void logAndSendError(java.lang.String msg, int errno)
          Deprecated. As of Galaxy Communicator 4.0. Use logAndSendErrorMessage(String, int).
protected  void logAndSendErrorMessage(java.lang.String msg)
           
protected  void logAndSendErrorMessage(java.lang.String msg, java.lang.Exception ex)
           
protected  void logAndSendErrorMessage(java.lang.String msg, java.lang.Exception ex, java.lang.String location)
           
protected  void logAndSendErrorMessage(java.lang.String msg, int errno)
           
protected  void logAndSendErrorMessage(java.lang.String msg, int errno, java.lang.Exception ex)
           
protected  void logAndSendErrorMessage(java.lang.String msg, int errno, java.lang.Exception ex, java.lang.String location)
           
protected  void logAndSendErrorMessage(java.lang.String msg, int errno, java.lang.String location)
           
protected  void logAndSendErrorMessage(java.lang.String msg, java.lang.String location)
           
 void logError(java.lang.String msg)
          Deprecated. As of Galaxy Communicator 4.0. Use logErrorMessage(String).
 void logError(java.lang.String msg, java.lang.Exception ex)
          Deprecated. As of Galaxy Communicator 4.0. Use logErrorMessage(String, Exception).
 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 logFatalError(java.lang.String msg)
          Deprecated. As of Galaxy Communicator 4.0. Use logFatalMessage(String).
 void logFatalError(java.lang.String msg, java.lang.Exception ex)
          Deprecated. As of Galaxy Communicator 4.0. Use logFatalMessage(String, Exception).
 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 logWarning(java.lang.String msg)
          Deprecated. As of Galaxy Communicator 4.0. Use logWarningMessage(String).
 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 was started by this server.
 void removeServerListener(ServerListener listener)
           
 void run()
          This implements the basic message loop.
 void serverOpReinitialize(GFrame frame)
          Subclasses of Server typically override this method in order to provide custom reinitialization.
 void setHubContactPolicy(int hubContactPolicy)
          Sets the Hub contact policy (used if this server is a Hub client).
protected  void setServerProperties(GFrame props)
          Sets the specified server properties.
 void setValidate(boolean validate)
          Sets the method signature validation flag.
 void stop()
          Marks this server's thread as being stopped.
protected  boolean unregisterOutBroker(DataOutBroker broker)
          Unregisters an outgoing broker that was started by this server.
protected  boolean wasHubContactPolicyModified()
          Tests if this server's Hub contact policy has been modified since the the server was created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mainServer

protected MainServer mainServer
Reference to the MainServer that started this server.
Constructor Detail

Server

public Server(MainServer mainServer,
              java.net.Socket socket)
       throws java.io.IOException
Creates a new server. Note that the server is not started in the constructor.
Parameters:
mainServer - the MainServer that created this server
socket - the socket connection to the Hub
Method Detail

init

public void init()
          throws java.lang.Exception
Called before server starts. Subclasses of this class can override this method to provide custom initialization.

setValidate

public void setValidate(boolean validate)
Sets the method signature validation flag.
Parameters:
validate - true if validation should be done, false otherwise

getValidate

public boolean getValidate()
Gets the value of the method signature validation flag.
Returns:
true if validation should be done, false otherwise

getIPAddress

public java.net.InetAddress getIPAddress()
Gets the internet address information for this server's local host.
Returns:
the internet address information or null if there was an error

getHostAddress

public java.lang.String getHostAddress()
Gets the host address for this server's local host.
Returns:
the host address or an empty string if there was an error

getCurrentEnvironment

public Environment getCurrentEnvironment()
Returns this server current execution environment.
Returns:
the environment

getCopyOfCurrentEnvironment

public Environment getCopyOfCurrentEnvironment()
Returns a copy of this server's current execution environment.
Returns:
the environment

getMainServer

public MainServer getMainServer()
Returns the reference to the MainServer that started this server.
Returns:
reference to the MainServer

getServerProperties

public GFrame getServerProperties()
Gets this server's properties.
Returns:
the server's properties

setServerProperties

protected void setServerProperties(GFrame props)
Sets the specified server properties.
Parameters:
props - the properties to set

deleteServerProperties

protected void deleteServerProperties(java.lang.String[] keys)
Deletes the specified server properties.
Parameters:
keys - the keys of the properties to delete

addServiceType

public void addServiceType(java.lang.String serviceType)
Adds a service type to this server's lists of supported service types if it is not already in the list.
Parameters:
serviceType - the service type to add

getServiceTypes

public GVector getServiceTypes()
Gets the service types supported by this server.
Returns:
the service types

setHubContactPolicy

public void setHubContactPolicy(int hubContactPolicy)
Sets the Hub contact policy (used if this server is a Hub client). If an invalid policy is specified, no change is made. Valid values include -1 (use the policy of the parent MainServer object), 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.
Parameters:
hubContactPolicy - the policy

wasHubContactPolicyModified

protected boolean wasHubContactPolicyModified()
Tests if this server's Hub contact policy has been modified since the the server was created.
Returns:
true if the policy has been modified and false otherwise

getHubContactPolicy

public int getHubContactPolicy()
Gets the Hub contact policy (used if this server is a Hub client).
Returns:
the policy

getSessionId

public java.lang.String getSessionId()
Gets the session id.
Returns:
the sessionId

registerOutBroker

protected void registerOutBroker(DataOutBroker broker)
Registers an outgoing broker that was started by this server.
Parameters:
broker - the broker

unregisterOutBroker

protected boolean unregisterOutBroker(DataOutBroker broker)
Unregisters an outgoing broker that was started by this server.
Parameters:
broker - the broker
Returns:
true if the broker was found and unregistered, false if the broker was not found

stop

public void stop()
Marks this server's thread as being stopped. The thread is not actually stopped until this condition is tested in the thread's main loop.

isRunning

public boolean isRunning()
Indicates if this server's thread is marked as running or stopped. Note that this does not return the actual status of the thread (which is only affected when the associated flag is tested in the thread's main loop).
Returns:
true if the thread is marked as running, false otherwise

cleanup

protected void cleanup()
This cleanup method is called when this server is preparing to stop. This is called before the socket connection is closed and this server is unregisterd with the main server. Override this method to provide your own customized cleanup routine. The generic Server cleanup will still take place.

run

public void run()
This implements the basic message loop. It receives a frame, then calls evaluateHubFrame to process the frame. The result is sent back to the hub.
Specified by:
run in interface java.lang.Runnable
See Also:
evaluateHubFrame(galaxy.lang.GFrame)

getContinuationData

protected ContinuationData getContinuationData(int serverTidx)
Gets the continuation data associated with a server token index.
Parameters:
serverTidx - the server token index associated with the continuation
Returns:
the continuation data or null if no data was found for the specified index

addContinuationData

protected void addContinuationData(int serverTidx,
                                   ContinuationData data)
Stores continuation data associated with a server token index.
Parameters:
serverTidx - the server token index associated with the continuation
data - the continuation data

addSignature

protected void addSignature(Signature sig)
Adds new signature information for this server.
Parameters:
sig - the signature information

getSignature

protected Signature getSignature(java.lang.String op)
Gets the signature information associated with an operation on this server's interface
Parameters:
op - the name of the operation
Returns:
the signature information associated with the specified operation or null if no match was found

encodeSignatures

protected GVector encodeSignatures()
Encodes this server's signature information in a GVector.
Returns:
the encoded signature information

evaluateHubFrame

protected GFrame evaluateHubFrame(GFrame frame)
Evaluates the Hub frame. Otherwise the op_name property is extracted from the frame and the method name formed by prepending serverOp when it is called. For example, if serverOp is explode, then the method serverOpExplode will be called.

serverOpReinitialize

public void serverOpReinitialize(GFrame frame)
Subclasses of Server typically override this method in order to provide custom reinitialization.

addServerListener

public void addServerListener(ServerListener listener)

removeServerListener

public void removeServerListener(ServerListener listener)

log

public void log(java.lang.String msg)
Deprecated. As of Galaxy Communicator 4.0. Use logMessage(String, int).


logWarning

public void logWarning(java.lang.String msg)
Deprecated. As of Galaxy Communicator 4.0. Use logWarningMessage(String).


logError

public void logError(java.lang.String msg)
Deprecated. As of Galaxy Communicator 4.0. Use logErrorMessage(String).


logError

public void logError(java.lang.String msg,
                     java.lang.Exception ex)
Deprecated. As of Galaxy Communicator 4.0. Use logErrorMessage(String, Exception).


logFatalError

public void logFatalError(java.lang.String msg)
Deprecated. As of Galaxy Communicator 4.0. Use logFatalMessage(String).


logFatalError

public void logFatalError(java.lang.String msg,
                          java.lang.Exception ex)
Deprecated. As of Galaxy Communicator 4.0. Use logFatalMessage(String, Exception).


logMessage

public void logMessage(java.lang.String msg,
                       int level)
Description copied from interface: DiagnosticLogger
Displays a message to System.out.
Specified by:
logMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display
level - the minimum verbosity level at which to display the message (verbosity levels are defined in galaxy.server.MainServer)

logMessage

public void logMessage(java.lang.String msg,
                       int level,
                       java.lang.String location)
Description copied from interface: DiagnosticLogger
Displays a message to System.out.
Specified by:
logMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display
level - 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 above

logMessage

public void logMessage(java.lang.String msg)
Description copied from interface: DiagnosticLogger
Displays a message to System.out (at any verbosity level).
Specified by:
logMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display

logWarningMessage

public void logWarningMessage(java.lang.String msg)
Description copied from interface: DiagnosticLogger
Displays a warning message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.WARNING_VERBOSITY_LEVEL.
Specified by:
logWarningMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display

logWarningMessage

public void logWarningMessage(java.lang.String msg,
                              java.lang.String location)
Description copied from interface: DiagnosticLogger
Displays a warning message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.WARNING_VERBOSITY_LEVEL.
Specified by:
logWarningMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display
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 above

logErrorMessage

public void logErrorMessage(java.lang.String msg)
Description copied from interface: DiagnosticLogger
Displays an error message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.ERROR_VERBOSITY_LEVEL.
Specified by:
logErrorMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display

logErrorMessage

public void logErrorMessage(java.lang.String msg,
                            java.lang.Exception ex)
Description copied from interface: DiagnosticLogger
Displays an error message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.ERROR_VERBOSITY_LEVEL.
Specified by:
logErrorMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display
ex - the stack trace of this exception is also displayed

logErrorMessage

public void logErrorMessage(java.lang.String msg,
                            java.lang.String location)
Description copied from interface: DiagnosticLogger
Displays an error message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.ERROR_VERBOSITY_LEVEL.
Specified by:
logErrorMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display
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 above

logErrorMessage

public void logErrorMessage(java.lang.String msg,
                            java.lang.Exception ex,
                            java.lang.String location)
Description copied from interface: DiagnosticLogger
Displays an error message to System.err when the current verbosity level is equal to or greater than galaxy.server.MainServer.ERROR_VERBOSITY_LEVEL.
Specified by:
logErrorMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display
ex - the stack trace of this exception is also displayed
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 above

logFatalMessage

public void logFatalMessage(java.lang.String msg)
Description copied from interface: DiagnosticLogger
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.
Specified by:
logFatalMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display

logFatalMessage

public void logFatalMessage(java.lang.String msg,
                            java.lang.Exception ex)
Description copied from interface: DiagnosticLogger
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.
Specified by:
logFatalMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display
ex - the stack trace of this exception is also displayed

logFatalMessage

public void logFatalMessage(java.lang.String msg,
                            java.lang.String location)
Description copied from interface: DiagnosticLogger
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.
Specified by:
logFatalMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display
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 above

logFatalMessage

public void logFatalMessage(java.lang.String msg,
                            java.lang.Exception ex,
                            java.lang.String location)
Description copied from interface: DiagnosticLogger
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.
Specified by:
logFatalMessage in interface DiagnosticLogger
Following copied from interface: galaxy.util.DiagnosticLogger
Parameters:
msg - the message to display
ex - the stack trace of this exception is also displayed
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 above

logAndSendError

protected void logAndSendError(java.lang.String msg)
Deprecated. As of Galaxy Communicator 4.0. Use logAndSendErrorMessage(String).

Logs an error message locally (if enabled) and sends it to the Hub.
Parameters:
msg - the description of the error

logAndSendError

protected void logAndSendError(java.lang.String msg,
                               int errno)
                        throws java.io.IOException
Deprecated. As of Galaxy Communicator 4.0. Use logAndSendErrorMessage(String, int).


logAndSendErrorMessage

protected void logAndSendErrorMessage(java.lang.String msg)
                               throws java.io.IOException

logAndSendErrorMessage

protected void logAndSendErrorMessage(java.lang.String msg,
                                      java.lang.Exception ex)
                               throws java.io.IOException

logAndSendErrorMessage

protected void logAndSendErrorMessage(java.lang.String msg,
                                      int errno)
                               throws java.io.IOException

logAndSendErrorMessage

protected void logAndSendErrorMessage(java.lang.String msg,
                                      int errno,
                                      java.lang.Exception ex)
                               throws java.io.IOException

logAndSendErrorMessage

protected void logAndSendErrorMessage(java.lang.String msg,
                                      java.lang.String location)
                               throws java.io.IOException

logAndSendErrorMessage

protected void logAndSendErrorMessage(java.lang.String msg,
                                      java.lang.Exception ex,
                                      java.lang.String location)
                               throws java.io.IOException

logAndSendErrorMessage

protected void logAndSendErrorMessage(java.lang.String msg,
                                      int errno,
                                      java.lang.String location)
                               throws java.io.IOException

logAndSendErrorMessage

protected void logAndSendErrorMessage(java.lang.String msg,
                                      int errno,
                                      java.lang.Exception ex,
                                      java.lang.String location)
                               throws java.io.IOException