1 | package de.uka.ipd.sdq.sensorframework.dao.memory; |
2 | |
3 | import java.util.Collection; |
4 | import java.util.Collections; |
5 | import java.util.HashMap; |
6 | |
7 | import de.uka.ipd.sdq.sensorframework.entities.Measurement; |
8 | import de.uka.ipd.sdq.sensorframework.entities.ScalabilityMeasurement; |
9 | import de.uka.ipd.sdq.sensorframework.entities.ScalabilitySensor; |
10 | import de.uka.ipd.sdq.sensorframework.entities.State; |
11 | import de.uka.ipd.sdq.sensorframework.entities.StateMeasurement; |
12 | import de.uka.ipd.sdq.sensorframework.entities.StateSensor; |
13 | import de.uka.ipd.sdq.sensorframework.entities.TimeSpanMeasurement; |
14 | import de.uka.ipd.sdq.sensorframework.entities.TimeSpanSensor; |
15 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
16 | import de.uka.ipd.sdq.sensorframework.entities.dao.IMeasurementDAO; |
17 | import de.uka.ipd.sdq.sensorframework.entities.impl.ScalabilityMeasurementImpl; |
18 | import de.uka.ipd.sdq.sensorframework.entities.impl.StateMeasurementImpl; |
19 | import de.uka.ipd.sdq.sensorframework.entities.impl.TimeSpanMeasurementImpl; |
20 | |
21 | /** |
22 | * TODO |
23 | * |
24 | */ |
25 | public class MemoryMeasurementDAO implements IMeasurementDAO { |
26 | |
27 | private long nextID = 0; |
28 | private IDAOFactory myFactory; |
29 | private HashMap<Long, Measurement> index = new HashMap<Long, Measurement>(); |
30 | |
31 | public MemoryMeasurementDAO(IDAOFactory myFactory){ |
32 | this.myFactory = myFactory; |
33 | } |
34 | |
35 | public synchronized StateMeasurement addStateMeasurement(StateSensor p_sensor, |
36 | State p_sensorstate, double p_eventtime) { |
37 | StateMeasurement result = new StateMeasurementImpl(myFactory); |
38 | result.setMeasurementID(nextID++); |
39 | result.setEventTime(p_eventtime); |
40 | result.setSensor(p_sensor); |
41 | result.setSensorState(p_sensorstate); |
42 | |
43 | index.put(result.getMeasurementID(), result); |
44 | return result; |
45 | } |
46 | |
47 | public synchronized TimeSpanMeasurement addTimeSpanMeasurement(TimeSpanSensor p_sensor, |
48 | double p_eventtime, double p_timespan) { |
49 | TimeSpanMeasurement result = new TimeSpanMeasurementImpl(myFactory); |
50 | result.setMeasurementID(nextID++); |
51 | result.setEventTime(p_eventtime); |
52 | result.setSensor(p_sensor); |
53 | result.setTimeSpan(p_timespan); |
54 | |
55 | index.put(result.getMeasurementID(), result); |
56 | return result; |
57 | } |
58 | |
59 | public synchronized ScalabilityMeasurement addScalabilityMeasurement(ScalabilitySensor p_sensor, |
60 | Double[] p_params, double p_result ) { |
61 | ScalabilityMeasurement result = new ScalabilityMeasurementImpl(myFactory); |
62 | result.setMeasurementID(nextID++); |
63 | result.setEventTime(p_result); |
64 | result.setSensor(p_sensor); |
65 | result.setParameters(p_params); |
66 | |
67 | index.put(result.getMeasurementID(), result); |
68 | return result; |
69 | } |
70 | |
71 | public synchronized Measurement get(long id) { |
72 | return index.get(id); |
73 | } |
74 | |
75 | public synchronized Collection<Measurement> getMeasurements() { |
76 | return Collections.unmodifiableCollection(index.values()); |
77 | } |
78 | |
79 | public synchronized void removeMeasurement(Measurement measurement, boolean doCascade) { |
80 | if (measurement == null) { |
81 | return; |
82 | } |
83 | |
84 | index.remove(measurement.getMeasurementID()); |
85 | } |
86 | } |