galaxy.server
Class ServerCreationThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--galaxy.server.ServerCreationThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
ClientThread, ListenerThread

public abstract class ServerCreationThread
extends java.lang.Thread

This is a thread that creates and starts new instances of Server. This class must be extended.


Field Summary
protected static int CLIENT
          Hub client thread type.
protected  GalaxyInputStream in
          This threads input stream.
protected  boolean isRunning
          Flag that indicates if this thread is running.
protected static int LISTENER
          Listener thread type.
protected  MainServer mainServer
          The MainServer that created this thread.
protected  GalaxyOutputStream out
          This threads output stream.
protected  java.lang.Thread thread
          Reference to this thread.
protected  int threadType
          This thread's type.
protected  boolean tooManyServers
          This flag is set if there was an attempt to start too many servers.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ServerCreationThread(java.lang.String name, MainServer mainServer, int threadType)
          Creats a new thread that creates servers.
 
Method Summary
protected  Server createServer(java.net.Socket clientSocket, java.lang.String sessionId)
          Creates a new server to handle a new connection.
 boolean isRunning()
           
protected  void logErrorMessage(java.lang.String message)
           
protected  void logErrorMessage(java.lang.String message, java.lang.Exception ex)
           
protected  void logErrorMessage(java.lang.String message, java.lang.Exception ex, java.lang.String location)
           
protected  void logErrorMessage(java.lang.String message, java.lang.String location)
           
protected  void logMessage(java.lang.String message, int level)
           
protected  void logMessage(java.lang.String message, int level, java.lang.String location)
           
protected  void logWarningMessage(java.lang.String message)
           
protected  void logWarningMessage(java.lang.String message, java.lang.String location)
           
abstract  void run()
          The main routine for this thread.
protected  java.lang.Thread startServer(Server server)
          Starts the specified server.
 void stopThread()
          Marks this broker's thread as being interrupted.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, 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
 

Field Detail

LISTENER

protected static final int LISTENER
Listener thread type.

CLIENT

protected static final int CLIENT
Hub client thread type.

threadType

protected int threadType
This thread's type.

mainServer

protected MainServer mainServer
The MainServer that created this thread.

in

protected GalaxyInputStream in
This threads input stream.

out

protected GalaxyOutputStream out
This threads output stream.

thread

protected java.lang.Thread thread
Reference to this thread.

tooManyServers

protected boolean tooManyServers
This flag is set if there was an attempt to start too many servers.

isRunning

protected volatile boolean isRunning
Flag that indicates if this thread is running.
Constructor Detail

ServerCreationThread

public ServerCreationThread(java.lang.String name,
                            MainServer mainServer,
                            int threadType)
Creats a new thread that creates servers.
Parameters:
mainServer - the MainServer that created this thread
threadType - the type of thread created (e.g., a listener, a Hub client). The valid values are defined in this class.
Method Detail

logMessage

protected void logMessage(java.lang.String message,
                          int level)

logMessage

protected void logMessage(java.lang.String message,
                          int level,
                          java.lang.String location)

logWarningMessage

protected void logWarningMessage(java.lang.String message)

logWarningMessage

protected void logWarningMessage(java.lang.String message,
                                 java.lang.String location)

logErrorMessage

protected void logErrorMessage(java.lang.String message,
                               java.lang.Exception ex)

logErrorMessage

protected void logErrorMessage(java.lang.String message)

logErrorMessage

protected void logErrorMessage(java.lang.String message,
                               java.lang.Exception ex,
                               java.lang.String location)

logErrorMessage

protected void logErrorMessage(java.lang.String message,
                               java.lang.String location)

run

public abstract void run()
The main routine for this thread.
Overrides:
run in class java.lang.Thread

stopThread

public void stopThread()
Marks this broker's thread as being interrupted.

isRunning

public boolean isRunning()

createServer

protected Server createServer(java.net.Socket clientSocket,
                              java.lang.String sessionId)
Creates a new server to handle a new connection. The server is created dynamically based on the value of MainServer.serverClassName.
Parameters:
clientSocket - the client connection that is to be associated with the new server
sessionId - initial session id of the server
Returns:
reference to the new server

startServer

protected java.lang.Thread startServer(Server server)
                                throws java.lang.Exception
Starts the specified server. Server.init is invoked on the server to perform custom initialization. Just before the server is started, listeners registered with MainServer are notified by calling MainServer.fireNewServer.
Parameters:
server - the server to start
Returns:
reference to the server thread object