1 | package de.uka.ipd.sdq.simucomframework.simulationdock; |
2 | |
3 | import java.util.Hashtable; |
4 | import java.util.Map; |
5 | |
6 | import org.osgi.service.event.Event; |
7 | import org.osgi.service.event.EventAdmin; |
8 | |
9 | import de.uka.ipd.sdq.simulation.AbstractSimulationConfig; |
10 | import de.uka.ipd.sdq.simulation.IStatusObserver; |
11 | |
12 | public class SimulationProgressReportingObserver implements IStatusObserver { |
13 | private int lastPercent = 0; |
14 | private AbstractSimulationConfig config; |
15 | private SimulationDockService myDock; |
16 | private EventAdmin eventAdmin; |
17 | |
18 | public SimulationProgressReportingObserver(AbstractSimulationConfig config, |
19 | EventAdmin eventAdmin, SimulationDockService dock) { |
20 | this.config = config; |
21 | this.eventAdmin = eventAdmin; |
22 | this.myDock = dock; |
23 | } |
24 | |
25 | public void updateStatus(int percentDone, double currentSimTime, |
26 | long measurementsTaken) { |
27 | if (percentDone > lastPercent || (config.isDebug() /* TODO: && myDock.isSuspended() */)){ |
28 | Hashtable<String,Object> properties = new Hashtable<String,Object>(); |
29 | properties.put("PERCENT_DONE", percentDone); |
30 | properties.put("CURRENT_TIME", currentSimTime); |
31 | properties.put("MEASUREMENTS_TAKEN", measurementsTaken); |
32 | postEvent("de/uka/ipd/sdq/simucomframework/simucomdock/UPDATE_SIM_STATUS",properties); |
33 | lastPercent = percentDone; |
34 | } |
35 | } |
36 | |
37 | private void postEvent(String topic, Hashtable<String,Object> newProperties) { |
38 | Hashtable<String,Object> properties = new Hashtable<String,Object>(); |
39 | properties.put("DOCK_ID", myDock.getDockId()); |
40 | properties.putAll(newProperties); |
41 | Event event = new Event(topic, (Map)properties); |
42 | eventAdmin.postEvent(event); |
43 | } |
44 | |
45 | } |