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.observer.IUT2004Observer;
14 import cz.cuni.amis.utils.exception.PogamutException;
15
16
17
18
19
20
21
22
23
24
25
26
27 public class UT2004ObserverRunner<OBSERVER extends IUT2004Observer, PARAMS extends UT2004AgentParameters> extends AgentRunner<OBSERVER, 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 UT2004ObserverRunner(IAgentFactory<OBSERVER, 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 UT2004ObserverRunner(IAgentFactory<OBSERVER, PARAMS> factory, String name) {
66 this(
67 factory,
68 name,
69 Pogamut.getPlatform().getProperty(PogamutUT2004Property.POGAMUT_UT2004_OBSERVER_HOST.getKey()) == null ?
70 "localhost"
71 : Pogamut.getPlatform().getProperty(PogamutUT2004Property.POGAMUT_UT2004_OBSERVER_HOST.getKey()),
72 Pogamut.getPlatform().getIntProperty(PogamutUT2004Property.POGAMUT_UT2004_OBSERVER_PORT.getKey()) == 0 ?
73 3002
74 : Pogamut.getPlatform().getIntProperty(PogamutUT2004Property.POGAMUT_UT2004_OBSERVER_PORT.getKey())
75 );
76 }
77
78
79
80
81
82
83
84 public UT2004ObserverRunner(IAgentFactory<OBSERVER, PARAMS> factory) {
85 this(factory, "UT2004Observer");
86 }
87
88 @Override
89 public OBSERVER startAgent() throws PogamutException {
90 return super.startAgent();
91 }
92
93 @Override
94 public List<OBSERVER> startAgents(int count) throws PogamutException {
95 return super.startAgents(count);
96 }
97
98 @Override
99 public List<OBSERVER> startAgents(PARAMS... agentParameters) throws PogamutException {
100 return super.startAgents(agentParameters);
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 }