cz.cuni.pogamut.server
Class UCCWrapper

java.lang.Object
  extended by cz.cuni.pogamut.server.UCCWrapper

public class UCCWrapper
extends java.lang.Object

Wrapper of running instance of UCC server. Implements pooling of instances. Usage scenario is: UCCWrapper ucc = UCCWrapper.create(); ... ucc.release(); The location of UCC executabe will be determined by an environment variable pogamut.unreal.home (e.g. c:\Games\UT2004). The property cam be set via java ... -Dpogamut.unreal.home=c:\Games\UT2004


Nested Class Summary
 class UCCWrapper.ScannerSink
          Scanns the output of UCC for some specific srings (Ports bounded.
protected  class UCCWrapper.StreamSink
          Reads content of the stream and discards it.
 
Field Summary
protected static int basePort
          First port assigned to a ucc instance.
protected  int controlPort
           
protected static int fileCounter
          Counter of files with ports.
protected  java.lang.String gameType
          One of BotAPI.* modes
protected  int gbPort
           
protected  long killAfter
          Time in miliseconds for which the unused instance will remain in the pool of servers.
protected  java.lang.String mapName
           
protected static java.lang.Integer nextUccWrapperUID
           
protected  java.util.Timer poolCleanerTimer
          Timer executing tasks for cleaning pool of UCC servers.
private static java.lang.Object poolRetrievalLock
          Lock used when retrieving existing node from the pool.
protected  boolean released
          Was this instance already released?
static long stamp
           
protected  java.util.TimerTask terminationTask
          Task that will remove this timer from the pool.
static java.lang.String UCC_EXEC
          Constant for environment variable with ucc executable.
protected  java.util.logging.Logger uccLog
          Loger containing all output from running instance of UCC.
protected static java.util.Collection<UCCWrapper> uccPool
          Pool of unused ucc servers, it takes some time to start new ucc server so it is convenientto keep unused instances in this pool.
(package private)  java.lang.Process uccProcess
           
protected static java.util.Collection<UCCWrapper> uccUnreleased
          List of unreleased UCC instances.
protected  int uccWrapperUID
          ID of the wrapper object.
static java.lang.String UNREAL_HOME
          Constant for environment variable with path to the Unreal home dir.
protected  UTServer utServer
           
 
Constructor Summary
protected UCCWrapper(java.util.logging.Logger parent)
          Creates new instance ith default parrent logger
 
Method Summary
protected  void close()
          Removes the UCC from the pool and terminates it.
static UCCWrapper create()
          Returns instance of UCC server that is not in use.
static UCCWrapper create(java.util.logging.Logger parent)
          Returns instance of UCC server that is not in use.
static UCCWrapper create(long maxTimeInPool)
          Returns instance of UCC server that is not in use.
static UCCWrapper create(long maxTimeInPool, java.util.logging.Logger parent)
          Returns instance of UCC server that is not in use.
 int getControlPort()
           
 int getGbPort()
           
 java.util.logging.Logger getLogger()
           
 java.lang.Process getProcess()
           
protected static java.lang.String getUnrealHome()
           
 UTServer getUTServer()
           
protected  void initUCCWrapper()
           
 void kill()
           
 void release()
          This informs UCC that you dont want to use it in the future.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

uccLog

protected java.util.logging.Logger uccLog
Loger containing all output from running instance of UCC.


UNREAL_HOME

public static final java.lang.String UNREAL_HOME
Constant for environment variable with path to the Unreal home dir.

See Also:
Constant Field Values

UCC_EXEC

public static final java.lang.String UCC_EXEC
Constant for environment variable with ucc executable. On win32 probably ucc.exe, on unix probably ucc-bin

See Also:
Constant Field Values

uccPool

protected static java.util.Collection<UCCWrapper> uccPool
Pool of unused ucc servers, it takes some time to start new ucc server so it is convenientto keep unused instances in this pool.


uccUnreleased

protected static java.util.Collection<UCCWrapper> uccUnreleased
List of unreleased UCC instances.


poolCleanerTimer

protected java.util.Timer poolCleanerTimer
Timer executing tasks for cleaning pool of UCC servers.


terminationTask

protected java.util.TimerTask terminationTask
Task that will remove this timer from the pool.


fileCounter

protected static int fileCounter
Counter of files with ports. Used to generate unique file name.


uccProcess

java.lang.Process uccProcess

gbPort

protected int gbPort

controlPort

protected int controlPort

utServer

protected UTServer utServer

basePort

protected static final int basePort
First port assigned to a ucc instance.

See Also:
Constant Field Values

nextUccWrapperUID

protected static java.lang.Integer nextUccWrapperUID

uccWrapperUID

protected int uccWrapperUID
ID of the wrapper object. Useful for debuging.


mapName

protected java.lang.String mapName

gameType

protected java.lang.String gameType
One of BotAPI.* modes


stamp

public static long stamp

killAfter

protected long killAfter
Time in miliseconds for which the unused instance will remain in the pool of servers.


poolRetrievalLock

private static java.lang.Object poolRetrievalLock
Lock used when retrieving existing node from the pool.


released

protected boolean released
Was this instance already released?

Constructor Detail

UCCWrapper

protected UCCWrapper(java.util.logging.Logger parent)
              throws UCCStartException
Creates new instance ith default parrent logger

Parameters:
parent - Parent logger for sending UT messages. Can be null.
Throws:
UCCStartException
Method Detail

getLogger

public java.util.logging.Logger getLogger()
Returns:
Log with output of UCC. If you want to listen also for messages from the startup sequence then use UCCWrapper.create(Logger parent). Set Parent logger of this log and register listeners before creating this instance of UCCWrapper.

getUTServer

public UTServer getUTServer()

getUnrealHome

protected static java.lang.String getUnrealHome()

create

public static UCCWrapper create(long maxTimeInPool)
                         throws UCCStartException
Returns instance of UCC server that is not in use.

Parameters:
maxTimeInPool - Time in miliseconds for which the unused instance will remain in the pool of servers.
Throws:
UCCStartException

create

public static UCCWrapper create(long maxTimeInPool,
                                java.util.logging.Logger parent)
                         throws UCCStartException
Returns instance of UCC server that is not in use.

Parameters:
maxTimeInPool - Time in miliseconds for which the unused instance will remain in the pool of servers.
parent - Parent logger for logging UCC output. Can be null.
Throws:
UCCStartException

create

public static UCCWrapper create()
                         throws UCCStartException
Returns instance of UCC server that is not in use.

Throws:
UCCStartException

create

public static UCCWrapper create(java.util.logging.Logger parent)
                         throws UCCStartException
Returns instance of UCC server that is not in use.

Parameters:
parent - Parent logger for logging UCC output. Can be null.
Throws:
UCCStartException

initUCCWrapper

protected void initUCCWrapper()
                       throws UCCStartException
Throws:
UCCStartException

getProcess

public java.lang.Process getProcess()

kill

public void kill()

close

protected void close()
Removes the UCC from the pool and terminates it. Must be called only from block synchronized on poolRetrievalLock.


release

public void release()
This informs UCC that you dont want to use it in the future. UCC is send to the pool where it will reside for some time and if no one will ask for it it will be terminated.


getGbPort

public int getGbPort()
Returns:
Port for GameBots connection.

getControlPort

public int getControlPort()
Returns:
Port for control connection.