- Timestamp:
- 09/23/13 18:54:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/experiment/Experiment.java
r105 r107 1 1 package com.framsticks.experiment; 2 2 3 import java.util.LinkedList; 4 import java.util.List; 3 5 import java.util.Map; 4 6 … … 8 10 9 11 import com.framsticks.params.EventListener; 12 import com.framsticks.params.MessageLogger; 10 13 import com.framsticks.params.ParamFlags; 11 14 import com.framsticks.params.SimpleUniqueList; … … 13 16 import com.framsticks.params.annotations.FramsClassAnnotation; 14 17 import com.framsticks.params.annotations.ParamAnnotation; 15 import com.framsticks.params.types.ProcedureParam;16 18 import com.framsticks.remote.RemoteTree; 19 import com.framsticks.structure.Path; 17 20 import com.framsticks.structure.messages.ListChange; 21 import com.framsticks.structure.messages.Message; 18 22 import com.framsticks.util.ExceptionHandler; 19 23 import com.framsticks.util.FramsticksException; … … 23 27 import com.framsticks.util.dispatching.DispatcherSetable; 24 28 import com.framsticks.util.dispatching.Dispatching; 29 import com.framsticks.util.dispatching.Future; 30 import com.framsticks.util.dispatching.FutureHandler; 25 31 import com.framsticks.util.dispatching.Joinable; 26 32 import com.framsticks.util.dispatching.JoinableCollection; … … 43 49 protected final BufferedDispatcher<Experiment> bufferedDispatcher = new BufferedDispatcher<>(this); 44 50 51 protected SimulatorProvider simulatorProvider; 52 45 53 protected String expdef; 46 54 55 protected final MessageLogger messages = new MessageLogger(NetLoadSaveLogic.class); 47 56 48 57 /** … … 90 99 91 100 /** 101 * @return the simulatorProvider 102 */ 103 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 104 public SimulatorProvider getSimulatorProvider() { 105 return simulatorProvider; 106 } 107 108 /** 109 * @param simulatorProvider the simulatorProvider to set 110 */ 111 @AutoAppendAnnotation 112 @ParamAnnotation 113 public void setSimulatorProvider(SimulatorProvider simulatorProvider) { 114 this.simulatorProvider = simulatorProvider; 115 } 116 117 /** 92 118 * @return the expdef 93 119 */ … … 118 144 @AutoAppendAnnotation 119 145 public void addSimulator(Simulator simulator) { 146 log.debug("add simulator {}", simulator); 120 147 simulators.add(simulator); 121 148 simulatorAsJoinables.add(simulator); 122 149 simulators.fireChildrenChange(simulator, ListChange.Action.Modify, "ready"); 123 150 151 simulatorCandidates.remove(simulator.getRemoteTree()); 124 152 } 125 153 … … 156 184 157 185 Dispatching.use(simulatorAsJoinables, this); 186 Dispatching.use(simulatorProvider, this); 158 187 Dispatching.use(simulatorCandidates, this); 188 189 tryProvideAllSimulators(Future.<List<Simulator>>doNothing(this)); 159 190 } 160 191 … … 163 194 164 195 Dispatching.drop(simulatorAsJoinables, this); 196 Dispatching.drop(simulatorProvider, this); 165 197 Dispatching.drop(simulatorCandidates, this); 198 199 Dispatching.drop(bufferedDispatcher, this); 166 200 167 201 finishJoinable(); … … 175 209 @Override 176 210 protected void joinableJoin() throws InterruptedException { 177 Dispatching.drop(bufferedDispatcher, this);178 211 179 212 Dispatching.join(simulatorAsJoinables); 213 Dispatching.join(simulatorProvider); 180 214 Dispatching.join(simulatorCandidates); 181 Dispatching.join(bufferedDispatcher.getTargetDispatcher());215 // Dispatching.join(bufferedDispatcher.getTargetDispatcher()); 182 216 } 183 217 … … 197 231 } 198 232 199 @ParamAnnotation(paramType = ProcedureParam.class) 200 public void connectToSimulator(String address) { 201 SimulatorConnector connector = new SimulatorConnector(); 202 connector.setAddress(address); 203 connector.attachTo(this); 233 // @ParamAnnotation(paramType = ProcedureParam.class) 234 // public void connectToSimulator(String address) { 235 // SimulatorConnector connector = new SimulatorConnector(); 236 // connector.setAddress(address); 237 // connector.attachTo(this); 238 // } 239 // 240 241 public Simulator createSimulator(RemoteTree tree, Path path) { 242 return new Simulator(this, tree, path); 243 } 244 245 public void tryProvideNextSimulator(final FutureHandler<Simulator> future) { 246 log.debug("trying to provide next simulator"); 247 simulatorProvider.provideSimulator(new SimulatorSpecification(this, expdef), new Future<Simulator>(future) { 248 249 @Override 250 protected void result(Simulator result) { 251 assert isActive(); 252 if (result != null) { 253 addSimulator(result); 254 } else { 255 log.debug("no more simulators remaining"); 256 } 257 future.pass(result); 258 259 } 260 }); 261 262 } 263 264 public void tryProvideAllSimulators(final FutureHandler<List<Simulator>> future) { 265 log.debug("trying to provide all simulators"); 266 final List<Simulator> list = new LinkedList<>(); 267 268 tryProvideNextSimulator(new Future<Simulator>(future) { 269 270 @Override 271 protected void result(Simulator result) { 272 if (result == null) { 273 future.pass(list); 274 return; 275 } 276 list.add(result); 277 tryProvideNextSimulator(this); 278 } 279 }); 280 281 } 282 283 @ParamAnnotation(id = "messages") 284 public void addMessageListener(EventListener<Message> listener) { 285 messages.add(listener); 286 } 287 288 @ParamAnnotation(id = "messages") 289 public void removeMessageListener(EventListener<Message> listener) { 290 messages.remove(listener); 204 291 } 205 292
Note: See TracChangeset
for help on using the changeset viewer.