EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.pipesandfilters.framework.recorder.sensorframework.strategies]

COVERAGE SUMMARY FOR SOURCE FILE [ExecutionResultWriteDataStrategy.java]

nameclass, %method, %block, %line, %
ExecutionResultWriteDataStrategy.java0%   (0/1)0%   (0/6)0%   (0/172)0%   (0/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ExecutionResultWriteDataStrategy0%   (0/1)0%   (0/6)0%   (0/172)0%   (0/40)
ExecutionResultWriteDataStrategy (IDAOFactory, Experiment, ExperimentRun): void 0%   (0/1)0%   (0/11)0%   (0/3)
findSuccessState (): State 0%   (0/1)0%   (0/55)0%   (0/12)
initSensor (String): void 0%   (0/1)0%   (0/36)0%   (0/6)
initStatesCache (MetaDataInit): void 0%   (0/1)0%   (0/31)0%   (0/7)
initialise (MetaDataInit): void 0%   (0/1)0%   (0/8)0%   (0/3)
writeData (PipeData): void 0%   (0/1)0%   (0/31)0%   (0/9)

1package de.uka.ipd.sdq.pipesandfilters.framework.recorder.sensorframework.strategies;
2 
3import java.util.HashMap;
4import java.util.Map;
5 
6import javax.measure.Measure;
7import javax.measure.quantity.Dimensionless;
8import javax.measure.quantity.Duration;
9import javax.measure.unit.SI;
10 
11import de.uka.ipd.sdq.pipesandfilters.framework.MetaDataInit;
12import de.uka.ipd.sdq.pipesandfilters.framework.PipeData;
13import de.uka.ipd.sdq.pipesandfilters.framework.recorder.sensorframework.ExecutionResultMetaDataInit;
14import de.uka.ipd.sdq.pipesandfilters.framework.recorder.sensorframework.SensorHelper;
15import de.uka.ipd.sdq.sensorframework.entities.Experiment;
16import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun;
17import de.uka.ipd.sdq.sensorframework.entities.State;
18import de.uka.ipd.sdq.sensorframework.entities.StateSensor;
19import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory;
20 
21/**
22 * Realizes a write strategy for reliability sensors.
23 * 
24 * @author brosch
25 * 
26 */
27public class ExecutionResultWriteDataStrategy extends AbstractWriteDataStrategy {
28 
29        /**
30         * Stores the dynamically created set of states.
31         */
32        private HashMap<Integer, State> statesCache = new HashMap<Integer, State>();
33 
34        /**
35         * Constructor for the strategy.
36         * 
37         * @param daoFactory
38         *            the DAO factory
39         * @param experiment
40         *            the current experiment
41         * @param run
42         *            the simulation run
43         */
44        public ExecutionResultWriteDataStrategy(final IDAOFactory daoFactory,
45                        final Experiment experiment, final ExperimentRun run) {
46                super(daoFactory, experiment, run);
47        }
48 
49        /*
50         * (non-Javadoc)
51         * 
52         * @see
53         * de.uka.ipd.sdq.pipesandfilters.framework.recorder.sensorframework.strategies
54         * .
55         * AbstractWriteDataStrategy#initialise(de.uka.ipd.sdq.pipesandfilters.framework
56         * .MetaDataInit)
57         */
58        public void initialise(final MetaDataInit metaData) {
59                initStatesCache(metaData);
60                initSensor(metaData.getMeasurementName());
61        }
62 
63        /*
64         * (non-Javadoc)
65         * 
66         * @see
67         * de.uka.ipd.sdq.pipesandfilters.framework.recorder.sensorframework.strategies
68         * .IWriteDataStrategy#writeData(de.uka.ipd.sdq.pipesandfilters.framework.
69         * PipeData)
70         */
71        @SuppressWarnings("unchecked")
72        public void writeData(final PipeData data) {
73                Measure<Double, Duration> measurementTimeMeasure = (Measure<Double, Duration>) data
74                                .getTupleElement(0);
75                double measurementTime = measurementTimeMeasure.doubleValue(SI.SECOND);
76                Measure<Integer, Dimensionless> numericStateMeasure = (Measure<Integer, Dimensionless>) data
77                                .getTupleElement(1);
78                int stateId = numericStateMeasure.intValue(Dimensionless.UNIT);
79                run.addStateMeasurement((StateSensor) sensor, statesCache.get(stateId),
80                                measurementTime);
81        }
82 
83        /**
84         * Finds or creates the success state for the sensor to be used by this
85         * strategy.
86         * 
87         * @return the success state
88         */
89        private State findSuccessState() {
90 
91                // Assume that the success state is named "Success":
92                for (State state : statesCache.values()) {
93                        if (state.getStateLiteral().equals("Success")) {
94                                return state;
95                        }
96                }
97 
98                // Assume that the success state has ID = 0:
99                State state = statesCache.get(0);
100                if (state != null) {
101                        return state;
102                }
103 
104                // Return an additional success state:
105                int newID = 0;
106                while(statesCache.containsKey(newID)){
107                        newID++;
108                }
109                State newState = SensorHelper.createOrReuseState(daoFactory, "Success");
110                statesCache.put(newID, newState);
111                return newState;
112        }
113 
114        /**
115         * Initializes the state sensor to be used by the strategy.
116         * 
117         * @param sensorId
118         *            the id of the sensor to be used
119         */
120        private void initSensor(String sensorId) {
121                sensor = SensorHelper.createOrReuseStateSensor(daoFactory, experiment,
122                                sensorId, findSuccessState());
123                for (State state : statesCache.values()) {
124                        if (!((StateSensor) sensor).getSensorStates().contains(state)) {
125                                ((StateSensor) sensor).addSensorState(state);
126                        }
127                }
128        }
129 
130        /**
131         * Initializes the cache of execution result states.
132         * 
133         * @param metaData
134         *            the meta data for the initialization of the strategy
135         */
136        private void initStatesCache(final MetaDataInit metaData) {
137                Map<Integer, String> resultTypes = ((ExecutionResultMetaDataInit) metaData)
138                                .getExecutionResultTypes();
139                for (Integer key : resultTypes.keySet()) {
140                        State state = SensorHelper.createOrReuseState(daoFactory,
141                                        resultTypes.get(key));
142                        statesCache.put(key, state);
143                }
144        }
145}

[all classes][de.uka.ipd.sdq.pipesandfilters.framework.recorder.sensorframework.strategies]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov