| 1 | /** |
| 2 | * |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.sensorframework.dao.file.entities; |
| 5 | |
| 6 | import java.io.File; |
| 7 | import java.io.IOException; |
| 8 | import java.util.List; |
| 9 | |
| 10 | import de.uka.ipd.sdq.sensorframework.dao.file.FileDAOFactory; |
| 11 | import de.uka.ipd.sdq.sensorframework.dao.file.FileManager; |
| 12 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
| 13 | import de.uka.ipd.sdq.sensorframework.entities.Measurement; |
| 14 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
| 15 | import de.uka.ipd.sdq.sensorframework.storage.lists.BackgroundMemoryList; |
| 16 | import de.uka.ipd.sdq.sensorframework.storage.lists.DoubleSerialiser; |
| 17 | |
| 18 | /**TODO add documentation |
| 19 | * @author Ihssane El-Oudghiri |
| 20 | * @author Steffen Becker |
| 21 | * |
| 22 | */ |
| 23 | public abstract class AbstractSensorAndMeasurements |
| 24 | extends AbstractFileEntity |
| 25 | implements SerializableEntity { |
| 26 | |
| 27 | /** |
| 28 | * For serialization |
| 29 | */ |
| 30 | private static final long serialVersionUID = 1L; |
| 31 | |
| 32 | protected static final String EVENT_TIME_SUFFIX = "ET"; |
| 33 | protected static final String MEASUREMENTS_SUFFIX = "MEAS"; |
| 34 | |
| 35 | protected ExperimentRun experimentRun; |
| 36 | protected Sensor sensor; |
| 37 | protected BackgroundMemoryList<Double> eventTimes; |
| 38 | private FileManager fm; |
| 39 | |
| 40 | public AbstractSensorAndMeasurements(FileManager fm, ExperimentRun exprun, Sensor sensor) throws IOException { |
| 41 | super(fm.getDAOFactory()); |
| 42 | this.sensor = sensor; |
| 43 | this.experimentRun = exprun; |
| 44 | this.fm = fm; |
| 45 | |
| 46 | eventTimes = new BackgroundMemoryList<Double>(getEventTimeFileName(), new DoubleSerialiser()); |
| 47 | fm.addOpenList(eventTimes); |
| 48 | } |
| 49 | |
| 50 | protected String getEventTimeFileName() { |
| 51 | return fm.getRootDirectory() + File.separator + |
| 52 | FileDAOFactory.EXPRUN_FILE_NAME_PREFIX |
| 53 | + experimentRun.getExperimentRunID() + "_" |
| 54 | + sensor.getSensorID() + "_" + |
| 55 | EVENT_TIME_SUFFIX + ".ser"; |
| 56 | } |
| 57 | |
| 58 | public String getFileName() { |
| 59 | return FileDAOFactory.EXPRUN_FILE_NAME_PREFIX |
| 60 | + experimentRun.getExperimentRunID() + "_" |
| 61 | + sensor.getSensorID(); |
| 62 | } |
| 63 | |
| 64 | public long getID() { |
| 65 | throw new UnsupportedOperationException(); |
| 66 | } |
| 67 | |
| 68 | public abstract List<Measurement> getMeasurements(); |
| 69 | |
| 70 | protected String getMeasurementsFileName() { |
| 71 | return fm.getRootDirectory() + File.separator + FileDAOFactory.EXPRUN_FILE_NAME_PREFIX |
| 72 | + experimentRun.getExperimentRunID() + "_" |
| 73 | + sensor.getSensorID() + "_" + |
| 74 | MEASUREMENTS_SUFFIX + ".ser"; |
| 75 | } |
| 76 | |
| 77 | public Sensor getSensor() { |
| 78 | return sensor; |
| 79 | } |
| 80 | |
| 81 | public void setSensor(SensorImpl sensor) { |
| 82 | this.sensor = sensor; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Throws a RuntimeException if an IOException is encountered |
| 87 | */ |
| 88 | public void store() { |
| 89 | try { |
| 90 | eventTimes.flush(); |
| 91 | } catch (IOException e) { |
| 92 | throw new RuntimeException(e); |
| 93 | } |
| 94 | } |
| 95 | } |