|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcz.cuni.amis.pogamut.udk.utils.UCCWrapper
public class UCCWrapper
Wrapper of running instance of UDK server. Implements pooling of instances.
The location of UDK executabe will be determined by an environment variable
pogamut.udk.home (e.g. c:\Games\UDK). The property cam be set via java ...
-Dpogamut.udk.home=c:\Games\UDK. Another posibility is to set it
by code System.setProperty("pogamut.udk.home", "c:\\udks\\UDK-2011-05");
.
As of now, UCCWrapper uses console command exit to kill the server when calling stop()
or
upon JVM shutdown. However, this fails if there are non-Pogamut players connected (e.g. when spectating) and the server stays alive.
If the exit command is not effective, UCCWrapper tries to kill the server in a platform dependent way using UDK process PID. However, some
tricks are needed to obtain the pid. The biggest problem is that UDK.com which needs to be run in order to get console output from the server
spawns another process called UDK.exe and killing the original process does not kill UDK.exe. Moreover,
if used on UNIX (see below) the UDK.exe is not a child process of UDK.com for some reason... So there are some not exactly neat tricks.
However, on Windows, the UCCWrapper might be considered reliable (even thread-safe) providing no other code in current JVM spawns
(directly or undirectly)
processes called UDK.exe. On UNIX, there are some additional issues (see below).
It is possible to use UCCWrapper under UNIX systems. First you need to setup UDK as described at our WIKI: pogamut.cuni.cz/pogamut-devel/doku.php?id=guidelines:udk_on_linux. Then UCCWrapper must have access to Wine in order to this, UCCWrapper uses property called WINE (might be an environment variable or it might be a Java property - see above). Property value defaults to "wine" which should be just fine if you have wine regularly installed. Make sure that WINEPREFIX environment variable is set in the shell that runs your program, otherwise Wine will not have access to correct wineprefix.
As noted above, there are some not very neat tricks in getting the process PID of UDK. On UNIX, UCCWrapper relies on the fact that no other program than the current JVM spawns new processes called UDK.exe. If this is not true, UCCWrapper will usually detect this situation and not read PID at all. But on very rare occasions (another process starts UDK.exe at the same time and starting of UDK.exe in this JVM fails or is delayed) UCCWrapper may take pid of a different UDK.exe process. Since pid is only used to kill the server if the EXIT command fails, it is even more unlikely that this problem will actually exhibit in killing wrong process.
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. |
static class |
UCCWrapper.UCCWrapperConf
Configuration object of the UCC wrapper instance. |
Field Summary | |
---|---|
protected boolean |
aggressiveKilling
Agressive killing means that the server is always killed by PID, if PID is available Otherwise it is killed by EXIT command first and if the connection dies, it is considered killed. |
protected static int |
basePort
First port assigned to a ucc instance. |
static int |
CHANGE_MAP_COMMAND_MAX_REPEATS
How many times will the wrapper try to send ChangeMap command to server, until it gives up waiting for notification. |
static int |
CHANGE_MAP_CONFIRMATION_TIMEOUT
How long (msec) will wrapper wait for confirmation of ChangeMap message |
protected UCCWrapper.UCCWrapperConf |
configuration
|
protected int |
controlPort
Port for server connection. |
static long |
DEFAULT_START_TIMEOUT
|
static long |
DEFAULT_UDK_EXE_SPAWN_TIMEOUT_UNIX
The ammount of time taken to to start UDK.exe on UNIX is quite large, since wine needs to boot in that time |
static long |
DEFAULT_UDK_EXE_SPAWN_TIMEOUT_WINDOWS
|
protected static int |
fileCounter
|
protected int |
gbPort
Port for bots. |
protected static Integer |
nextUccWrapperUID
|
protected int |
observerPort
Port for observer connection. |
protected UDKServerFactory |
serverFactory
|
static long |
stamp
|
protected long |
startingTimeout
|
protected boolean |
stopped
Was this instance already released? |
protected LogCategory |
uccLog
Loger containing all output from running instance of UCC. |
protected int |
uccPid
|
protected int |
uccWrapperUID
ID of the wrapper object. |
protected String |
unrealHome
|
protected IUDKServer |
utServer
|
Constructor Summary | |
---|---|
UCCWrapper(UCCWrapper.UCCWrapperConf configuration)
|
|
UCCWrapper(UCCWrapper.UCCWrapperConf configuration,
boolean startImmediately)
|
|
UCCWrapper(UCCWrapper.UCCWrapperConf configuration,
UDKServerFactory factory)
|
|
UCCWrapper(UCCWrapper.UCCWrapperConf configuration,
UDKServerFactory serverFactory,
boolean startImmediately)
|
Method Summary | |
---|---|
CountDownLatch |
awaitGameStart()
Returns a countdown latch, that is raised after map change message was encountered |
void |
changeMap(String mapName,
boolean notifyGame,
long timeout)
Tries to change map on the server and blocks until either the map has changed or timeout happens. |
SocketConnectionAddress |
getBotAddress()
|
int |
getBotPort()
|
UCCWrapper.UCCWrapperConf |
getConfiguration()
|
int |
getControlPort()
|
String |
getHost()
|
Logger |
getLogger()
|
protected String |
getMapNameWithOptions()
|
SocketConnectionAddress |
getObserverAddress()
Deprecated. there is no observer connection in UDK |
int |
getObserverPort()
Deprecated. observer port is not used in UDK |
Process |
getProcess()
Process of the |
SocketConnectionAddress |
getServerAddress()
|
UDKServerFactory |
getServerFactory()
|
long |
getStartingTimeout()
|
long |
getUdkExeSpawnTimeoutUnix()
|
long |
getUdkExeSpawnTimeoutWindows()
|
protected String |
getUnrealHome()
|
IUDKServer |
getUTServer()
|
protected void |
initUCCWrapper()
|
boolean |
isAggressiveKilling()
|
static void |
killAllUCCs(LogCategory uccLog)
Kills all UDK instances with platform specific-system call. |
void |
restartServer()
|
void |
setAggressiveKilling(boolean aggressiveKilling)
|
void |
setConfiguration(UCCWrapper.UCCWrapperConf configuration)
Only makes sense if created with startImmediately = false |
void |
setServerFactory(UDKServerFactory serverFactory)
Only makes sense if created with startImmediately = false |
void |
setStartingTimeout(long startingTimeout)
Only makes sense if created with startImmediately = false and the serve was not started yet |
void |
setUdkExeSpawnTimeoutUnix(long udkExeSpawnTimeoutUnix)
Only makes sense if created with startImmediately = false and the serve was not started yet |
void |
setUdkExeSpawnTimeoutWindows(long udkExeSpawnTimeoutWindows)
Only makes sense if created with startImmediately = false and the serve was not started yet |
void |
start()
Start the server, if not already started. |
void |
stop()
Stops the UCC server. |
protected void |
stopCheck()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long DEFAULT_START_TIMEOUT
public static final int CHANGE_MAP_COMMAND_MAX_REPEATS
public static final long DEFAULT_UDK_EXE_SPAWN_TIMEOUT_WINDOWS
public static final long DEFAULT_UDK_EXE_SPAWN_TIMEOUT_UNIX
public static final int CHANGE_MAP_CONFIRMATION_TIMEOUT
protected LogCategory uccLog
protected static int fileCounter
protected int gbPort
protected int controlPort
protected int observerPort
protected IUDKServer utServer
protected static final int basePort
protected static Integer nextUccWrapperUID
protected int uccWrapperUID
protected String unrealHome
protected UCCWrapper.UCCWrapperConf configuration
protected long startingTimeout
protected int uccPid
protected UDKServerFactory serverFactory
protected boolean aggressiveKilling
public static long stamp
protected boolean stopped
Constructor Detail |
---|
public UCCWrapper(UCCWrapper.UCCWrapperConf configuration)
public UCCWrapper(UCCWrapper.UCCWrapperConf configuration, UDKServerFactory factory)
public UCCWrapper(UCCWrapper.UCCWrapperConf configuration, boolean startImmediately)
public UCCWrapper(UCCWrapper.UCCWrapperConf configuration, UDKServerFactory serverFactory, boolean startImmediately) throws UCCStartException
configuration
- startingTimeout
- serverFactory
- allows to specify external server factory. As of 3.3.0, this is needed to prevent memory leaks on subsequent creation of multiple UCCWrappers
UCCStartException
Method Detail |
---|
public void start() throws UCCStartException
UCCStartException
protected String getMapNameWithOptions()
public static void killAllUCCs(LogCategory uccLog)
public Logger getLogger()
public IUDKServer getUTServer()
public void restartServer()
protected String getUnrealHome()
public UCCWrapper.UCCWrapperConf getConfiguration()
public void setConfiguration(UCCWrapper.UCCWrapperConf configuration)
configuration
- public UDKServerFactory getServerFactory()
public void setServerFactory(UDKServerFactory serverFactory)
serverFactory
- public long getStartingTimeout()
public void setStartingTimeout(long startingTimeout)
udkExeSpawnTimeout
- public long getUdkExeSpawnTimeoutUnix()
public void setUdkExeSpawnTimeoutUnix(long udkExeSpawnTimeoutUnix)
udkExeSpawnTimeout
- public long getUdkExeSpawnTimeoutWindows()
public void setUdkExeSpawnTimeoutWindows(long udkExeSpawnTimeoutWindows)
udkExeSpawnTimeout
- public boolean isAggressiveKilling()
public void setAggressiveKilling(boolean aggressiveKilling)
protected void initUCCWrapper() throws UCCStartException
UCCStartException
public void changeMap(String mapName, boolean notifyGame, long timeout)
cz.cuni.amis.utils.exception.PogamutException
- if the map change was not succesfulpublic CountDownLatch awaitGameStart()
public Process getProcess()
public void stop()
public int getBotPort()
@Deprecated public int getObserverPort()
public int getControlPort()
protected void stopCheck()
public String getHost()
public SocketConnectionAddress getBotAddress()
public SocketConnectionAddress getServerAddress()
@Deprecated public SocketConnectionAddress getObserverAddress()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |