1 | package de.uka.ipd.sdq.simulation.abstractsimengine.desmoj; |
2 | |
3 | import de.uka.ipd.sdq.simulation.abstractsimengine.AbstractExperiment; |
4 | import desmoj.core.simulator.Experiment; |
5 | import desmoj.core.simulator.ExternalEvent; |
6 | import desmoj.core.simulator.TimeSpan; |
7 | |
8 | /** |
9 | * @author Steffen Becker |
10 | * @author Philipp Merkle |
11 | */ |
12 | public class DesmoJExperiment extends AbstractExperiment { |
13 | |
14 | private Experiment experiment; |
15 | |
16 | private DesmoJModel desmojModel; |
17 | |
18 | public DesmoJExperiment(DesmoJModel model) { |
19 | super(model); |
20 | |
21 | this.desmojModel = model; |
22 | this.experiment = new Experiment(model.getConfiguration().getNameExperimentRun()); |
23 | this.desmojModel.connectToExperiment(experiment); |
24 | this.experiment.setShowProgressBar(false); |
25 | |
26 | this.scheduleEvent(this.CHECK_EVENT, 1); |
27 | } |
28 | |
29 | public double getCurrentSimulationTime() { |
30 | return experiment.getSimClock().getTime().getTimeAsDouble(); |
31 | } |
32 | |
33 | public Experiment getExperiment() { |
34 | return this.experiment; |
35 | } |
36 | |
37 | @Override |
38 | public void scheduleEvent(final IEvent event, final double delay) { |
39 | new ExternalEvent(desmojModel, "StopEvent", false) { |
40 | @Override |
41 | public void eventRoutine() { |
42 | event.run(); |
43 | } |
44 | }.schedule(new TimeSpan(delay)); |
45 | } |
46 | |
47 | @Override |
48 | public void startSimulator() { |
49 | this.experiment.start(); |
50 | } |
51 | |
52 | @Override |
53 | public void stopSimulator() { |
54 | // TODO in Desmo-J, "stopped" experiments can be proceeded. Check, if it is here necessary |
55 | // to abort the experiment instead. |
56 | this.experiment.stop(); |
57 | } |
58 | |
59 | } |