source:
java/main/src/main/java/com/framsticks/experiment/SimulatorRange.java
@
107
Last change on this file since 107 was 107, checked in by , 11 years ago | |
---|---|
File size: 2.4 KB |
Line | |
---|---|
1 | package com.framsticks.experiment; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.Iterator; |
5 | import java.util.List; |
6 | |
7 | import org.apache.logging.log4j.Logger; |
8 | import org.apache.logging.log4j.LogManager; |
9 | |
10 | import com.framsticks.communication.Address; |
11 | import com.framsticks.params.annotations.FramsClassAnnotation; |
12 | import com.framsticks.params.annotations.ParamAnnotation; |
13 | import com.framsticks.params.types.UniversalParam; |
14 | import com.framsticks.util.dispatching.FutureHandler; |
15 | import com.framsticks.util.dispatching.JoinableCollection; |
16 | |
17 | @FramsClassAnnotation |
18 | public class SimulatorRange extends JoinableCollection<SimulatorProvider> implements SimulatorProvider { |
19 | private static final Logger log = LogManager.getLogger(Experiment.class); |
20 | |
21 | |
22 | protected List<String> hosts = new ArrayList<>(); |
23 | protected List<Integer> ports = new ArrayList<>(); |
24 | |
25 | protected Iterator<Address> addresses; |
26 | protected boolean run = true; |
27 | |
28 | @Override |
29 | public String getName() { |
30 | return "simulator range"; |
31 | } |
32 | |
33 | @Override |
34 | public void provideSimulator(final SimulatorSpecification specification, final FutureHandler<Simulator> future) { |
35 | if (addresses == null) { |
36 | log.info("providing simulators from set: {} X {}", hosts, ports); |
37 | |
38 | List<Address> list = new ArrayList<Address>(); |
39 | for (String host : hosts) { |
40 | for (Integer port : ports) { |
41 | list.add(new Address(host, port)); |
42 | } |
43 | } |
44 | addresses = list.iterator(); |
45 | } |
46 | |
47 | if (!addresses.hasNext()) { |
48 | future.pass(null); |
49 | return; |
50 | } |
51 | Address address = addresses.next(); |
52 | SingleSimulatorProvider provider = (run ? new SimulatorRunner() : new SimulatorConnector()); |
53 | provider.setAddress(address); |
54 | add(provider); |
55 | provider.provideSimulator(specification, future); |
56 | } |
57 | |
58 | /** |
59 | * @return the hosts |
60 | */ |
61 | @ParamAnnotation(paramType = UniversalParam.class) |
62 | public List<String> getHosts() { |
63 | return hosts; |
64 | } |
65 | |
66 | /** |
67 | * @param hosts the hosts to set |
68 | */ |
69 | @ParamAnnotation |
70 | public void setHosts(List<String> hosts) { |
71 | this.hosts = hosts; |
72 | } |
73 | |
74 | /** |
75 | * @return the ports |
76 | */ |
77 | @ParamAnnotation(paramType = UniversalParam.class) |
78 | public List<Integer> getPorts() { |
79 | return ports; |
80 | } |
81 | |
82 | /** |
83 | * @param ports the ports to set |
84 | */ |
85 | @ParamAnnotation |
86 | public void setPorts(List<Integer> ports) { |
87 | this.ports = ports; |
88 | } |
89 | |
90 | /** |
91 | * @return the run |
92 | */ |
93 | @ParamAnnotation |
94 | public boolean getRun() { |
95 | return run; |
96 | } |
97 | |
98 | /** |
99 | * @param run the run to set |
100 | */ |
101 | @ParamAnnotation |
102 | public void setRun(boolean run) { |
103 | this.run = run; |
104 | } |
105 | } |
Note: See TracBrowser
for help on using the repository browser.