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.agent.params.UT2004AgentParameters;
13 import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
14 import cz.cuni.amis.utils.exception.PogamutException;
15
16
17
18
19
20
21
22
23
24
25
26
27 public class UT2004ServerRunner<SERVER extends IUT2004Server, PARAMS extends UT2004AgentParameters> extends AgentRunner<SERVER, PARAMS> {
28
29
30
31
32 protected String host;
33
34
35
36
37 protected int port;
38
39
40
41
42 protected String name;
43
44
45
46
47
48
49
50
51
52 public UT2004ServerRunner(IAgentFactory<SERVER, PARAMS> factory, String name, String host, int port) {
53 super(factory);
54 this.name = name;
55 this.port = port;
56 this.host = host;
57 }
58
59
60
61
62
63
64
65 public UT2004ServerRunner(IAgentFactory<SERVER, PARAMS> factory, String name) {
66 this(
67 factory,
68 name,
69 Pogamut.getPlatform().getProperty(PogamutUT2004Property.POGAMUT_UT2004_SERVER_HOST.getKey()) == null ?
70 "localhost"
71 : Pogamut.getPlatform().getProperty(PogamutUT2004Property.POGAMUT_UT2004_SERVER_HOST.getKey()),
72 Pogamut.getPlatform().getIntProperty(PogamutUT2004Property.POGAMUT_UT2004_SERVER_PORT.getKey()) == 0 ?
73 3001
74 : Pogamut.getPlatform().getIntProperty(PogamutUT2004Property.POGAMUT_UT2004_SERVER_PORT.getKey())
75 );
76 }
77
78 @Override
79 public SERVER startAgent() throws PogamutException {
80 return super.startAgent();
81 }
82
83 @Override
84 public List<SERVER> startAgents(int count) throws PogamutException {
85 return super.startAgents(count);
86 }
87
88 @Override
89 public List<SERVER> startAgents(PARAMS... agentParameters) throws PogamutException {
90 return super.startAgents(agentParameters);
91 };
92
93
94
95
96
97
98
99 public UT2004ServerRunner(IAgentFactory<SERVER, PARAMS> factory) {
100 this(factory, "UT2004Server");
101 }
102
103
104
105
106
107 @Override
108 protected IAgentParameters newDefaultAgentParameters() {
109 return new UT2004AgentParameters().setAgentId(newAgentId(name)).setWorldAddress(new SocketConnectionAddress(host, port));
110 }
111
112 }