cz.cuni.amis.pogamut.ut2004.tournament.botexecution
Class UT2004BotExecution

Package class diagram package UT2004BotExecution
java.lang.Object
  extended by cz.cuni.amis.pogamut.ut2004.tournament.botexecution.UT2004BotExecution

public class UT2004BotExecution
extends Object

Class that wrapps the execution of the bot from the jar defined by UT2004BotExecutionConfig.

The class is not suitable for inheritance ... better copy-paste and adjust for yourself.

Author:
Jimmy

Field Summary
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 Summary
UT2004BotExecution(UT2004BotExecutionConfig config, Logger log)
           
 
Method Summary
 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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

protected UT2004BotExecutionConfig config

running

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.

Set to TRUE ONLY IN UT2004BotExecution#start() and back to FALSE ONLY IN shutdown(boolean). Do not alter the flag from anywhere else!


botProcess

protected Process botProcess
When UT2004BotExecution#start()ed it contains the bot process.


streamSinkOutput

protected cz.cuni.amis.utils.StreamSink streamSinkOutput
Sink for the STDOUT of the bot, it may be redirected to log.


streamSinkError

protected cz.cuni.amis.utils.StreamSink streamSinkError
Sink for the STDERR of the bot, it may be redirected to log.


log

protected Logger log
Log used by the object, specified during the construction.


shutDownHook

protected Runnable shutDownHook
Task that will kill the BOT process when user forgets to do so before the JVM is killed.


shutDownHookThread

protected Thread shutDownHookThread

waitForEnd

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).


waitForEndThread

protected Thread waitForEndThread
Constructor Detail

UT2004BotExecution

public UT2004BotExecution(UT2004BotExecutionConfig config,
                          Logger log)
Parameters:
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)
Method Detail

start

public void start(String host,
                  int port)
           throws cz.cuni.amis.utils.exception.PogamutIOException
Start the bot process. Throws 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).

Parameters:
host - GB2004 host
port - GB2004 bot port
Throws:
cz.cuni.amis.utils.exception.PogamutIOException

shutdown

protected void shutdown(boolean waitForEndThread)
Shutdowns the process and cleans-up everything, preparing the object to be UT2004BotExecution#start()ed again.

Parameters:
waitForEndThread - whether we're being called from the waitForEnd thread.

stop

public void stop()
Shuts down the bot process (if it is running, otherwise does nothing).


getBotProcess

public Process getBotProcess()
Process of the bot (non-null if started).

Returns:

getRunning

public cz.cuni.amis.utils.flag.ImmutableFlag<Boolean> getRunning()
Flag of the state of the bot process. True == process is running (has been started using UT2004BotExecution#start()), False == process was not started or has been already terminated, either by itself or via stop().

Returns:

isRunning

public boolean isRunning()
Flag of the state of the bot process. True == process is running (has been started using UT2004BotExecution#start()), False == process was not started or has been already terminated, either by itself or via stop().

Returns:


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.