cz.cuni.amis.pogamut.ut2004.utils
Class MultipleUT2004BotRunner<BOT extends UT2004Bot,PARAMS extends UT2004AgentParameters,MODULE extends UT2004BotModule>

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.agent.utils.runner.impl.MultipleAgentRunner<BOT,PARAMS,MODULE>
      extended by cz.cuni.amis.pogamut.ut2004.utils.MultipleUT2004BotRunner<BOT,PARAMS,MODULE>
All Implemented Interfaces:
IMultipleAgentRunner<BOT,PARAMS,MODULE>

public class MultipleUT2004BotRunner<BOT extends UT2004Bot,PARAMS extends UT2004AgentParameters,MODULE extends UT2004BotModule>
extends MultipleAgentRunner<BOT,PARAMS,MODULE>

This class has only one purpose - execute ONE OR MORE BOTS inside 'main' method. You can't use it for anything else! It is THE SHORTCUT of all SHORTCUTS to execute multiple bots, wait till they finishe and close the whole Pogamut.

Designed especially for the usage inside NetBeans projects.

NOTE: by default, all bots get paused after they start and they are resumed after all bots are present in UT2004. To change this behaviour pass 'false' through MultipleAgentRunner.setPausing(boolean).

NOTE: It's not even meant to be instantiated twice for two different batch of bots and consequently executed in two different threads! Single-purpose class only ;-)

NOTE: It might be very interesting for you to check out the source of method MultipleUT2004BotRunner#startAgent() to see how the agent should be instantiated via UT2004BotFactory using UT2004BotModule.


Field Summary
protected  java.lang.String host
          Default host where the instances are going to be connected as defaults, see IAgentParameters.assignDefaults(IAgentParameters).
protected  java.lang.String name
          Default name that will serve as a basis for IAgentId, see IAgentParameters.assignDefaults(IAgentParameters).
protected  int port
          Default port where the instances are going to be connected as defaults, see IAgentParameters.assignDefaults(IAgentParameters).
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.utils.runner.impl.MultipleAgentRunner
agents, consoleLogging, defaultLogLevel, killed, latch, listener, log, main, mutex
 
Constructor Summary
MultipleUT2004BotRunner(java.lang.String name)
          Construct the runner + specify the default name, host:port will be taken from the Pogamut platform properties.
MultipleUT2004BotRunner(java.lang.String name, java.lang.String host, int port)
          Construct the runner + specify all defaults.
 
Method Summary
 java.lang.String getHost()
          Returns host, where newly launched bots will be connected to.
 java.lang.String getName()
          Returns name that is going to be used to form new IAgentId of the bots.
 int getPort()
          Returns port, where newly launched bots will be connected to.
protected  IAgentFactory newAgentFactory(MODULE agentModule)
          Uses UT2004BotFactory for agent construction.
protected  IAgentParameters newDefaultAgentParameters()
          Provides default parameters that is, IAgentId using name and SocketConnectionAddress using host and port.
protected  void preStartHook(BOT agent)
          We're setting the logging level to Level.WARNING here so the bot won't log much.
 MultipleUT2004BotRunner<BOT,PARAMS,MODULE> setHost(java.lang.String host)
          Sets host, where newly launched bots will be connected to.
 MultipleUT2004BotRunner<BOT,PARAMS,MODULE> setName(java.lang.String name)
          Sets name that is going to be used to form new IAgentId of the bots.
 MultipleUT2004BotRunner<BOT,PARAMS,MODULE> setPort(int port)
          Sets port, where newly launched bots will be connected to.
 java.util.List<BOT> startAgents(IAgentDescriptor<PARAMS,MODULE>... agentDescriptors)
          Start an agent instances described by 'agentDescriptors'.
 
Methods inherited from class cz.cuni.amis.pogamut.base.agent.utils.runner.impl.MultipleAgentRunner
createAgentWithParams, getAgentCount, getLog, isMain, isPausing, killAgent, killAgents, newAgentId, postStartedHook, postStartHook, preInitHook, preResumeHook, setConsoleLogging, setLog, setLogLevel, setMain, setPausing, startAgent, startAgentsMain, startAgentsMain, startAgentsStandard, startAgentsStandard
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

host

protected java.lang.String host
Default host where the instances are going to be connected as defaults, see IAgentParameters.assignDefaults(IAgentParameters).


port

protected int port
Default port where the instances are going to be connected as defaults, see IAgentParameters.assignDefaults(IAgentParameters).


name

protected java.lang.String name
Default name that will serve as a basis for IAgentId, see IAgentParameters.assignDefaults(IAgentParameters).

Constructor Detail

MultipleUT2004BotRunner

public MultipleUT2004BotRunner(java.lang.String name,
                               java.lang.String host,
                               int port)
Construct the runner + specify all defaults.

Parameters:
name - default name that serve as a basis for IAgentId
host - default host where the instances are going to be connected
port - default port where the instances are going to be connected

MultipleUT2004BotRunner

public MultipleUT2004BotRunner(java.lang.String name)
Construct the runner + specify the default name, host:port will be taken from the Pogamut platform properties.

Parameters:
name - default name that serve as a basis for IAgentId
Method Detail

getName

public java.lang.String getName()
Returns name that is going to be used to form new IAgentId of the bots.

Returns:
name used for the newly started bots

setName

public MultipleUT2004BotRunner<BOT,PARAMS,MODULE> setName(java.lang.String name)
Sets name that is going to be used to form new IAgentId of the bots.

If null is passed, generic "UT2004Bot" will be set.

Parameters:
name - name used for the newly started bots
Returns:
this instance

getHost

public java.lang.String getHost()
Returns host, where newly launched bots will be connected to.

Returns:
host running GB2004 server

setHost

public MultipleUT2004BotRunner<BOT,PARAMS,MODULE> setHost(java.lang.String host)
Sets host, where newly launched bots will be connected to.

Parameters:
host - host running GB2004 server (can't be null)
Returns:
this instance

getPort

public int getPort()
Returns port, where newly launched bots will be connected to.

Returns:
port at the host where GB2004 server is listening for bot connections

setPort

public MultipleUT2004BotRunner<BOT,PARAMS,MODULE> setPort(int port)
Sets port, where newly launched bots will be connected to.

Parameters:
port - at the host where GB2004 server is listening for bot connections
Returns:
this instance

preStartHook

protected void preStartHook(BOT agent)
                     throws PogamutException
We're setting the logging level to Level.WARNING here so the bot won't log much.

Overrides:
preStartHook in class MultipleAgentRunner<BOT extends UT2004Bot,PARAMS extends UT2004AgentParameters,MODULE extends UT2004BotModule>
Throws:
PogamutException

newDefaultAgentParameters

protected IAgentParameters newDefaultAgentParameters()
Provides default parameters that is, IAgentId using name and SocketConnectionAddress using host and port.

Specified by:
newDefaultAgentParameters in class MultipleAgentRunner<BOT extends UT2004Bot,PARAMS extends UT2004AgentParameters,MODULE extends UT2004BotModule>
Returns:
new default parameters

newAgentFactory

protected IAgentFactory newAgentFactory(MODULE agentModule)
Uses UT2004BotFactory for agent construction.

Specified by:
newAgentFactory in class MultipleAgentRunner<BOT extends UT2004Bot,PARAMS extends UT2004AgentParameters,MODULE extends UT2004BotModule>
Returns:
new factory configured with 'agentModule'

startAgents

public java.util.List<BOT> startAgents(IAgentDescriptor<PARAMS,MODULE>... agentDescriptors)
Description copied from interface: IMultipleAgentRunner
Start an agent instances described by 'agentDescriptors'. The method creates a new factory for every descriptor (as it must use different agent modules). The length of the 'agentDescriptors' array together with IAgentDescriptor.getCount() determines how many agents are going to be instantiated and started.

Note that if any instantiation/start of the agent fails, all agents are killed before the method throws the exception.

Specified by:
startAgents in interface IMultipleAgentRunner<BOT extends UT2004Bot,PARAMS extends UT2004AgentParameters,MODULE extends UT2004BotModule>
Overrides:
startAgents in class MultipleAgentRunner<BOT extends UT2004Bot,PARAMS extends UT2004AgentParameters,MODULE extends UT2004BotModule>
Returns:
array of started agents