1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.sensorframework.dao.file.entities; |
5 | |
6 | import java.io.IOException; |
7 | import java.util.ArrayList; |
8 | import java.util.List; |
9 | |
10 | import de.uka.ipd.sdq.sensorframework.dao.file.FileManager; |
11 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
12 | import de.uka.ipd.sdq.sensorframework.entities.Measurement; |
13 | import de.uka.ipd.sdq.sensorframework.entities.ScalabilitySensor; |
14 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
15 | import de.uka.ipd.sdq.sensorframework.storage.lists.BackgroundMemoryList; |
16 | |
17 | /** |
18 | * @author Ihssane El-Oudghiri |
19 | * @author Steffen Becker |
20 | */ |
21 | public class ScalabilitySensorAndMeasurement extends AbstractSensorAndMeasurements { |
22 | |
23 | private static final long serialVersionUID = 3516448762784779531L; |
24 | private BackgroundMemoryList<Double[]> timeSpans; |
25 | |
26 | public ScalabilitySensorAndMeasurement(FileManager fm, ExperimentRun er, Sensor sensor) throws IOException { |
27 | super(fm, er, sensor); |
28 | timeSpans = new BackgroundMemoryList<Double[]>( |
29 | getMeasurementsFileName(), |
30 | new ParameterValueSerialiser((ScalabilitySensor)sensor)); |
31 | fm.addOpenList(timeSpans); |
32 | } |
33 | |
34 | public synchronized void addResult(Double[] ts, double et) { |
35 | eventTimes.add(et); |
36 | timeSpans.add(ts); |
37 | } |
38 | |
39 | @Override |
40 | public boolean equals(Object obj) { |
41 | if (!(obj instanceof ScalabilitySensorAndMeasurement)) |
42 | return false; |
43 | ScalabilitySensorAndMeasurement sam = (ScalabilitySensorAndMeasurement) obj; |
44 | |
45 | return super.equals(obj) && equalTimeSpans(this,sam); |
46 | } |
47 | |
48 | private boolean equalTimeSpans( |
49 | ScalabilitySensorAndMeasurement sam1, |
50 | ScalabilitySensorAndMeasurement sam2) { |
51 | if (sam1.timeSpans.size() == sam2.timeSpans.size()) { |
52 | for (int i=0; i<sam1.timeSpans.size(); i++){ |
53 | if (sam1.timeSpans.get(i) != sam2.timeSpans.get(i)) |
54 | return false; |
55 | } |
56 | return true; |
57 | } else { |
58 | return false; |
59 | } |
60 | } |
61 | |
62 | @Override |
63 | public synchronized List<Measurement> getMeasurements() { |
64 | ArrayList<Measurement> m = new ArrayList<Measurement>(); |
65 | for (int i = 0; i < timeSpans.size(); i++) { |
66 | m.add(new ScalabilityMeasurementImpl(i, eventTimes.get(i), timeSpans |
67 | .get(i))); |
68 | } |
69 | return m; |
70 | } |
71 | |
72 | @Override |
73 | public void store() { |
74 | super.store(); |
75 | try { |
76 | timeSpans.flush(); |
77 | } catch (IOException e) { |
78 | throw new RuntimeException(e); |
79 | } |
80 | } |
81 | |
82 | } |