1 package cz.cuni.amis.pogamut.udk.utils;
2
3 import java.util.List;
4 import java.util.logging.Level;
5
6 import cz.cuni.amis.pogamut.base.agent.IAgentId;
7 import cz.cuni.amis.pogamut.base.agent.impl.AgentId;
8 import cz.cuni.amis.pogamut.base.agent.params.IAgentParameters;
9 import cz.cuni.amis.pogamut.base.agent.utils.runner.IAgentDescriptor;
10 import cz.cuni.amis.pogamut.base.agent.utils.runner.impl.MultipleAgentRunner;
11 import cz.cuni.amis.pogamut.base.communication.connection.impl.socket.SocketConnectionAddress;
12 import cz.cuni.amis.pogamut.base.factory.IAgentFactory;
13 import cz.cuni.amis.pogamut.base.utils.Pogamut;
14 import cz.cuni.amis.pogamut.base.utils.PogamutProperty;
15 import cz.cuni.amis.pogamut.udk.agent.params.UDKAgentParameters;
16 import cz.cuni.amis.pogamut.udk.bot.IUDKBot;
17 import cz.cuni.amis.pogamut.udk.bot.impl.UDKBot;
18 import cz.cuni.amis.pogamut.udk.factory.guice.remoteagent.UDKBotFactory;
19 import cz.cuni.amis.pogamut.udk.factory.guice.remoteagent.UDKBotModule;
20 import cz.cuni.amis.utils.NullCheck;
21 import cz.cuni.amis.utils.exception.PogamutException;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class MultipleUDKBotRunner<BOT extends UDKBot, PARAMS extends UDKAgentParameters, MODULE extends UDKBotModule> extends MultipleAgentRunner<BOT, PARAMS, MODULE> {
43
44
45
46
47 protected String host;
48
49
50
51
52 protected int port;
53
54
55
56
57 protected String name;
58
59
60
61
62
63
64
65
66 public MultipleUDKBotRunner(String name, String host, int port) {
67 this.name = name;
68 this.port = port;
69 this.host = host;
70 }
71
72
73
74
75
76
77
78 public MultipleUDKBotRunner(String name) {
79 this(
80 name,
81 Pogamut.getPlatform().getProperty(PogamutUDKProperty.POGAMUT_UDK_BOT_HOST.getKey()),
82 Pogamut.getPlatform().getIntProperty(PogamutUDKProperty.POGAMUT_UDK_BOT_PORT.getKey())
83 );
84 }
85
86
87
88
89
90
91 public String getName() {
92 return name;
93 }
94
95
96
97
98
99
100
101
102
103 public MultipleUDKBotRunner<BOT, PARAMS, MODULE> setName(String name) {
104 if (name == null) name = "UDKBot";
105 this.name = name;
106 return this;
107 }
108
109
110
111
112
113
114 public String getHost() {
115 return host;
116 }
117
118
119
120
121
122
123
124 public MultipleUDKBotRunner<BOT, PARAMS, MODULE> setHost(String host) {
125 this.host = host;
126 NullCheck.check(this.host, "host");
127 return this;
128 }
129
130
131
132
133
134
135 public int getPort() {
136 return port;
137 }
138
139
140
141
142
143
144
145 public MultipleUDKBotRunner<BOT, PARAMS, MODULE> setPort(int port) {
146 this.port = port;
147 return this;
148 }
149
150
151
152
153 @Override
154 protected void preStartHook(BOT agent) throws PogamutException {
155 agent.getLogger().setLevel(Level.WARNING);
156 }
157
158
159
160
161
162 @Override
163 protected IAgentParameters newDefaultAgentParameters() {
164 return new UDKAgentParameters().setAgentId(new AgentId(name)).setWorldAddress(new SocketConnectionAddress(host, port));
165 }
166
167
168
169
170 @Override
171 protected IAgentFactory newAgentFactory(MODULE agentModule) {
172 return new UDKBotFactory<IUDKBot, UDKAgentParameters>(agentModule);
173 }
174
175 public List<BOT> startAgents(IAgentDescriptor<PARAMS,MODULE>... agentDescriptors) {
176 return super.startAgents(agentDescriptors);
177 };
178
179 }