Package 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
Nested Classes Modifier and Type Class Description 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.
-
Field Summary
Fields Modifier and Type Field Description private boolean
alreadyStarted
private java.lang.String
colossusJar
private java.io.File
flagFile
private java.lang.String
gameId
private GameInfo
gi
private java.lang.String
hostingHost
private int
hostingPort
private java.lang.String
javaCommand
private static java.util.logging.Logger
LOGGER
private WebServerOptions
options
private java.lang.String
reasonStartFailed
private IRunWebServer
server
private java.lang.String
template
private java.lang.String
workFilesBaseDir
-
Constructor Summary
Constructors Constructor Description RunGameInOwnJVM(IRunWebServer server, WebServerOptions options, GameInfo gi)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
createLoggingPropertiesFromTemplate(java.io.File logPropTemplate, java.io.File logPropFile)
private boolean
createServerCfgFile(java.io.File gameDir)
java.lang.String
getHostingHost()
int
getHostingPort()
private java.lang.String
getMissingPlayers(java.util.List<java.lang.String> names)
java.lang.String
getReasonStartFailed()
private boolean
isSocketUp()
java.lang.String
listAsString(java.util.List<java.lang.String> names)
boolean
makeRunningGame()
void
run()
private void
runInOwnJVM()
private void
sleepFor(long millis)
private void
superviseGameStartup()
boolean
tryToStart()
private void
waitForGameShutdown(java.lang.Process p, RunGameInOwnJVM.NullDumper ndout, RunGameInOwnJVM.NullDumper nderr)
private java.lang.String
waitForLine(java.io.BufferedReader in, int checkInterval)
boolean
waitUntilGameStartedSuccessfully(int timeout)
boolean
waitUntilReadyToAcceptClients(int timeout)
Waits until socket is up, i.e.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.colossus.webcommon.IGameRunner
start
-
-
-
-
Field Detail
-
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
-
reasonStartFailed
private java.lang.String reasonStartFailed
-
-
Constructor Detail
-
RunGameInOwnJVM
public RunGameInOwnJVM(IRunWebServer server, WebServerOptions options, GameInfo gi)
-
-
Method Detail
-
makeRunningGame
public boolean makeRunningGame()
- Specified by:
makeRunningGame
in interfaceIGameRunner
-
getHostingPort
public int getHostingPort()
- Specified by:
getHostingPort
in interfaceIGameRunner
-
getHostingHost
public java.lang.String getHostingHost()
- Specified by:
getHostingHost
in interfaceIGameRunner
-
getReasonStartFailed
public java.lang.String getReasonStartFailed()
-
tryToStart
public boolean tryToStart()
- Specified by:
tryToStart
in interfaceIGameRunner
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.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 interfaceIGameRunner
-
waitForLine
private java.lang.String waitForLine(java.io.BufferedReader in, int checkInterval)
-
getMissingPlayers
private java.lang.String getMissingPlayers(java.util.List<java.lang.String> names)
-
listAsString
public java.lang.String listAsString(java.util.List<java.lang.String> names)
-
waitUntilGameStartedSuccessfully
public boolean waitUntilGameStartedSuccessfully(int timeout)
- Specified by:
waitUntilGameStartedSuccessfully
in interfaceIGameRunner
-
sleepFor
private void sleepFor(long millis)
-
-