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.bot.IUT2004Bot;
13 import cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotController;
14 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
15 import cz.cuni.amis.pogamut.ut2004.bot.params.UT2004BotParameters;
16 import cz.cuni.amis.pogamut.ut2004.factory.guice.remoteagent.UT2004BotFactory;
17 import cz.cuni.amis.pogamut.ut2004.factory.guice.remoteagent.UT2004BotModule;
18 import cz.cuni.amis.utils.NullCheck;
19 import cz.cuni.amis.utils.exception.PogamutException;
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public class UT2004BotRunner<BOT extends IUT2004Bot, PARAMS extends UT2004BotParameters> extends AgentRunner<BOT, PARAMS> {
36
37
38
39
40 protected String host;
41
42
43
44
45 protected int port;
46
47
48
49
50 protected String name;
51
52
53
54
55
56
57
58
59
60 public UT2004BotRunner(IAgentFactory<BOT, PARAMS> factory, String name, String host, int port) {
61 super(factory);
62 this.name = name;
63 this.port = port;
64 this.host = host;
65 }
66
67
68
69
70
71
72
73
74 public UT2004BotRunner(IAgentFactory<BOT, PARAMS> factory, String name) {
75 this(
76 factory,
77 name,
78 Pogamut.getPlatform().getProperty(PogamutUT2004Property.POGAMUT_UT2004_BOT_HOST.getKey()) == null ?
79 "localhost"
80 : Pogamut.getPlatform().getProperty(PogamutUT2004Property.POGAMUT_UT2004_BOT_HOST.getKey()),
81 Pogamut.getPlatform().getIntProperty(PogamutUT2004Property.POGAMUT_UT2004_BOT_PORT.getKey()) == 0 ?
82 3000
83 : Pogamut.getPlatform().getIntProperty(PogamutUT2004Property.POGAMUT_UT2004_BOT_PORT.getKey())
84 );
85 }
86
87
88
89
90
91
92
93 public UT2004BotRunner(IAgentFactory<BOT, PARAMS> factory) {
94 this(factory, "UT2004Bot");
95 }
96
97
98
99
100
101
102
103
104
105 public UT2004BotRunner(UT2004BotModule module, String name, String host, int port) {
106 this(new UT2004BotFactory<BOT, PARAMS>(module), name, host, port);
107 }
108
109
110
111
112
113
114
115 public UT2004BotRunner(UT2004BotModule module, String name) {
116 this(
117 module,
118 name,
119 Pogamut.getPlatform().getProperty(PogamutUT2004Property.POGAMUT_UT2004_BOT_HOST.getKey()),
120 Pogamut.getPlatform().getIntProperty(PogamutUT2004Property.POGAMUT_UT2004_BOT_PORT.getKey())
121 );
122 }
123
124
125
126
127
128
129
130 public UT2004BotRunner(UT2004BotModule module) {
131 this(module, "UT2004Bot");
132 }
133
134
135
136
137
138
139
140
141
142 public UT2004BotRunner(Class<? extends IUT2004BotController> botControllerClass, String name, String host, int port) {
143 this(new UT2004BotModule(botControllerClass), name, host, port);
144 }
145
146
147
148
149
150
151
152 public UT2004BotRunner(Class<? extends IUT2004BotController> botControllerClass, String name) {
153 this(
154 new UT2004BotModule(botControllerClass),
155 name,
156 Pogamut.getPlatform().getProperty(PogamutUT2004Property.POGAMUT_UT2004_BOT_HOST.getKey()),
157 Pogamut.getPlatform().getIntProperty(PogamutUT2004Property.POGAMUT_UT2004_BOT_PORT.getKey())
158 );
159 }
160
161
162
163
164
165
166
167 public UT2004BotRunner(Class<? extends IUT2004BotController> botControllerClass) {
168 this(new UT2004BotModule(botControllerClass), "UT2004Bot");
169 }
170
171 @Override
172 public BOT startAgent() throws PogamutException {
173 return super.startAgent();
174 }
175
176 @Override
177 public List<BOT> startAgents(int count) throws PogamutException {
178 return super.startAgents(count);
179 }
180
181 @Override
182 public List<BOT> startAgents(PARAMS... agentParameters) throws PogamutException {
183 return super.startAgents(agentParameters);
184 };
185
186
187
188
189
190
191 public String getName() {
192 return name;
193 }
194
195
196
197
198
199
200
201
202
203 public UT2004BotRunner<BOT, PARAMS> setName(String name) {
204 if (name == null) name = "UT2004Bot";
205 this.name = name;
206 return this;
207 }
208
209
210
211
212
213
214 public String getHost() {
215 return host;
216 }
217
218
219
220
221
222
223
224 public UT2004BotRunner<BOT, PARAMS> setHost(String host) {
225 this.host = host;
226 NullCheck.check(this.host, "host");
227 return this;
228 }
229
230
231
232
233
234
235 public int getPort() {
236 return port;
237 }
238
239
240
241
242
243
244
245 public UT2004BotRunner<BOT, PARAMS> setPort(int port) {
246 this.port = port;
247 return this;
248 }
249
250
251
252
253
254 @Override
255 protected IAgentParameters newDefaultAgentParameters() {
256 return new UT2004BotParameters().setAgentId(newAgentId(name)).setWorldAddress(new SocketConnectionAddress(host, port));
257 }
258
259 @Override
260 public UT2004BotRunner<BOT, PARAMS> setMain(boolean state) {
261 super.setMain(state);
262 return this;
263 }
264
265 @Override
266 public UT2004BotRunner<BOT, PARAMS> setConsoleLogging(boolean enabled) {
267 super.setConsoleLogging(enabled);
268 return this;
269 }
270
271 }