net.sf.colossus.webserver
Class RunGameInOwnJVM
java.lang.Object
java.lang.Thread
net.sf.colossus.webserver.RunGameInOwnJVM
- All Implemented Interfaces:
- java.lang.Runnable, IGameRunner
public class RunGameInOwnJVM
- extends java.lang.Thread
- implements IGameRunner
This class runs (starts and supervises) a Game on the Game Server
(as opposed to: on the User's PC).
It finds and reserves a port for it, starts it in a separate process
and when the process terminates, join()s it and releases the port.
If the game is run on a user's PC, the class RunGameInSameJVM will be
used.
- Author:
- Clemens Katzer
Nested Class Summary |
private static class |
RunGameInOwnJVM.NullDumper
NullDumper is a dummy reader that just consumes all the output
produced by a Game's process - similar to /dev/null. |
Nested classes/interfaces inherited from class java.lang.Thread |
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
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 |
LOGGER
private static final java.util.logging.Logger LOGGER
hostingPort
private int hostingPort
hostingHost
private java.lang.String hostingHost
server
private final IRunWebServer server
options
private final WebServerOptions options
gi
private final GameInfo gi
gameId
private final java.lang.String gameId
workFilesBaseDir
private java.lang.String workFilesBaseDir
template
private java.lang.String template
javaCommand
private java.lang.String javaCommand
colossusJar
private java.lang.String colossusJar
flagFile
private java.io.File flagFile
alreadyStarted
private boolean alreadyStarted
RunGameInOwnJVM
public RunGameInOwnJVM(IRunWebServer server,
WebServerOptions options,
GameInfo gi)
makeRunningGame
public boolean makeRunningGame()
- Specified by:
makeRunningGame
in interface IGameRunner
getHostingPort
public int getHostingPort()
- Specified by:
getHostingPort
in interface IGameRunner
getHostingHost
public java.lang.String getHostingHost()
- Specified by:
getHostingHost
in interface IGameRunner
tryToStart
public boolean tryToStart()
- Specified by:
tryToStart
in interface IGameRunner
run
public void run()
- Specified by:
run
in interface java.lang.Runnable
- Overrides:
run
in class java.lang.Thread
runInOwnJVM
private void runInOwnJVM()
createServerCfgFile
private boolean createServerCfgFile(java.io.File gameDir)
createLoggingPropertiesFromTemplate
private boolean createLoggingPropertiesFromTemplate(java.io.File logPropTemplate,
java.io.File logPropFile)
superviseGameStartup
private void superviseGameStartup()
waitForGameShutdown
private void waitForGameShutdown(java.lang.Process p,
RunGameInOwnJVM.NullDumper ndout,
RunGameInOwnJVM.NullDumper nderr)
isSocketUp
private boolean isSocketUp()
waitUntilReadyToAcceptClients
public boolean waitUntilReadyToAcceptClients(int timeout)
- Description copied from interface:
IGameRunner
- Waits until socket is up, i.e. game is ready to accept clients.
- Specified by:
waitUntilReadyToAcceptClients
in interface IGameRunner
waitForLine
private java.lang.String waitForLine(java.io.BufferedReader in,
int checkInterval)
waitUntilGameStartedSuccessfully
public boolean waitUntilGameStartedSuccessfully(int timeout)
- Specified by:
waitUntilGameStartedSuccessfully
in interface IGameRunner
sleepFor
private void sleepFor(long millis)