View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.utils;
2   
3   import java.util.List;
4   
5   import cz.cuni.amis.pogamut.base.agent.IAgentId;
6   import cz.cuni.amis.pogamut.base.agent.params.IAgentParameters;
7   import cz.cuni.amis.pogamut.base.agent.utils.runner.impl.AgentRunner;
8   import cz.cuni.amis.pogamut.base.communication.connection.impl.socket.SocketConnectionAddress;
9   import cz.cuni.amis.pogamut.base.factory.IAgentFactory;
10  import cz.cuni.amis.pogamut.base.utils.Pogamut;
11  import cz.cuni.amis.pogamut.base.utils.PogamutPlatform;
12  import cz.cuni.amis.pogamut.ut2004.analyzer.IUT2004Analyzer;
13  import cz.cuni.amis.pogamut.ut2004.analyzer.UT2004AnalyzerParameters;
14  import cz.cuni.amis.pogamut.ut2004.analyzer.stats.UT2004AnalyzerObsStatsModule;
15  import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
16  import cz.cuni.amis.utils.exception.PogamutException;
17  
18  /**
19   * Class used for creating, connecting and starting analyzers with default settings that are taken from the properties.
20   * <p><p>
21   * The address where the instances will connect are defined either in the constructor
22   * or taken from the properties of the {@link PogamutPlatform}.
23   * <p><p>
24   * For more information about the class see {@link AgentRunner}.
25   * 
26   * @author ik
27   * @author Jimmy
28   */
29  public class UT2004AnalyzerRunner<SERVER extends IUT2004Analyzer, PARAMS extends UT2004AnalyzerParameters> extends AgentRunner<SERVER, PARAMS> {
30  
31  	/**
32  	 * Default host where the instances are going to be connected as defaults, see {@link IAgentParameters#assignDefaults(IAgentParameters)}.
33  	 */
34      protected String host;
35      
36      /**
37  	 * Default port where the instances are going to be connected as defaults, see {@link IAgentParameters#assignDefaults(IAgentParameters)}.
38  	 */
39      protected int port;
40      
41      /**
42  	 * Default name that will serve as a basis for {@link IAgentId}, see {@link IAgentParameters#assignDefaults(IAgentParameters)}.
43  	 */
44  	protected String name;
45  
46  	/** 
47  	 * Construct the runner + specify all defaults.
48  	 * 
49  	 * @param factory to be used for creating new {@link IUT2004Server} instances
50  	 * @param name default name that serve as a basis for {@link IAgentId}
51  	 * @param host default host where the instances are going to be connected
52  	 * @param port default port where the instances are going to be connected
53  	 */
54  	public UT2004AnalyzerRunner(IAgentFactory<SERVER, PARAMS> factory, String name, String host, int port) {
55          super(factory);
56          this.name = name;
57          this.port = port;
58          this.host = host;
59      }
60  
61  	/**
62  	 * Construct the runner + specify the default name, host:port will be taken from the Pogamut platform properties.
63  	 * 
64  	 * @param factory factory to be used for creating new {@link IUT2004Server} instances
65  	 * @param name default name that serve as a basis for {@link IAgentId}
66  	 */
67      public UT2004AnalyzerRunner(IAgentFactory<SERVER, PARAMS> factory, String name) {
68          this(
69          	factory, 
70          	name, 
71          	Pogamut.getPlatform().getProperty(PogamutUT2004Property.POGAMUT_UT2004_SERVER_HOST.getKey()), 
72          	Pogamut.getPlatform().getIntProperty(PogamutUT2004Property.POGAMUT_UT2004_SERVER_PORT.getKey())
73          );
74      }
75      
76      @Override
77      public SERVER startAgent() throws PogamutException {
78      	return super.startAgent();
79      }
80      
81      @Override
82      public List<SERVER> startAgents(int count) throws PogamutException {
83      	return super.startAgents(count);
84      }
85      
86      @Override
87      public List<SERVER> startAgents(PARAMS... agentParameters) throws PogamutException {
88      	return super.startAgents(agentParameters);
89      };
90      
91      /**
92       * Construct the runner without specifying anything as default. Default name for server agents will be "UTServer Factory"
93       * and host:port will be taken from the Pogamut platform properties.
94       * 
95       * @param factory factory to be used for creating new {@link IUT2004Server} instances
96       */
97      public UT2004AnalyzerRunner(IAgentFactory<SERVER, PARAMS> factory) {
98          this(factory, "UT2004Analyzer");
99      }
100 
101     /**
102      * Provides default parameters that is, {@link IAgentId} using {@link UT2004AnalyzerRunner#name} and {@link SocketConnectionAddress}
103      * using {@link UT2004AnalyzerRunner#host} and {@link UT2004AnalyzerRunner#port}.
104      */
105 	@Override
106 	protected IAgentParameters newDefaultAgentParameters() {
107 		return new UT2004AnalyzerParameters().setAgentId(newAgentId(name)).setWorldAddress(new SocketConnectionAddress(host, port)).setObserverModule(new UT2004AnalyzerObsStatsModule());
108 	}
109 	
110 }