public class UT2004BotExecution extends Object
UT2004BotExecutionConfig.
The class is not suitable for inheritance ... better copy-paste and adjust for yourself.
| Modifier and Type | Field and Description |
|---|---|
protected Process |
botProcess
When
UT2004BotExecution#start()ed it contains the bot process. |
protected UT2004BotExecutionConfig |
config |
protected Logger |
log
Log used by the object, specified during the construction.
|
protected cz.cuni.amis.utils.flag.Flag<Boolean> |
running
Flag whether the bot is running, we're synchronizing access to this class on this flag.
|
protected Runnable |
shutDownHook
Task that will kill the BOT process when user forgets to do so before the JVM is killed.
|
protected Thread |
shutDownHookThread |
protected cz.cuni.amis.utils.StreamSink |
streamSinkError
Sink for the STDERR of the bot, it may be redirected to
log. |
protected cz.cuni.amis.utils.StreamSink |
streamSinkOutput
Sink for the STDOUT of the bot, it may be redirected to
log. |
protected Runnable |
waitForEnd
Task that is waiting for the end of the bot process to switch
running back to false
and shutdown all other utility threads (like sink). |
protected Thread |
waitForEndThread |
| Constructor and Description |
|---|
UT2004BotExecution(UT2004BotExecutionConfig config,
Logger log) |
| Modifier and Type | Method and Description |
|---|---|
Process |
getBotProcess()
Process of the bot (non-null if started).
|
cz.cuni.amis.utils.flag.ImmutableFlag<Boolean> |
getRunning()
Flag of the state of the bot process.
|
boolean |
isRunning()
Flag of the state of the bot process.
|
protected void |
shutdown(boolean waitForEndThread)
Shutdowns the process and cleans-up everything, preparing the object to be
UT2004BotExecution#start()ed again. |
void |
start(String host,
int port)
Start the bot process.
|
void |
stop()
Shuts down the bot process (if it is running, otherwise does nothing).
|
protected UT2004BotExecutionConfig config
protected cz.cuni.amis.utils.flag.Flag<Boolean> running
Set to TRUE ONLY IN UT2004BotExecution#start() and back to FALSE ONLY IN shutdown(boolean).
Do not alter the flag from anywhere else!
protected Process botProcess
UT2004BotExecution#start()ed it contains the bot process.protected cz.cuni.amis.utils.StreamSink streamSinkOutput
log.protected cz.cuni.amis.utils.StreamSink streamSinkError
log.protected Logger log
protected Runnable shutDownHook
protected Thread shutDownHookThread
protected Runnable waitForEnd
running back to false
and shutdown all other utility threads (like sink).protected Thread waitForEndThread
public UT2004BotExecution(UT2004BotExecutionConfig config, Logger log)
config - bot execution configuration (contains path to jar to run)log - log to be used (stdout/stderr of the bot will be redirected there as well with Level.INFO)public void start(String host, int port) throws cz.cuni.amis.utils.exception.PogamutIOException
PogamutIOException if it fails to start the JVM.
It is wise to observe the state of the getRunning() flag to obtain the state of the process
(whether the process is running or is dead). Usage of FlagListener is advised, see ImmutableFlag.addListener(FlagListener).
host - GB2004 hostport - GB2004 bot portcz.cuni.amis.utils.exception.PogamutIOExceptionprotected void shutdown(boolean waitForEndThread)
UT2004BotExecution#start()ed again.waitForEndThread - whether we're being called from the waitForEnd thread.public void stop()
public Process getBotProcess()
public cz.cuni.amis.utils.flag.ImmutableFlag<Boolean> getRunning()
UT2004BotExecution#start()),
False == process was not started or has been already terminated, either by itself or via stop().public boolean isRunning()
UT2004BotExecution#start()),
False == process was not started or has been already terminated, either by itself or via stop().Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.