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

COVERAGE SUMMARY FOR SOURCE FILE [DemandBasedWaitingTimeCalculator.java]

nameclass, %method, %block, %line, %
DemandBasedWaitingTimeCalculator.java0%   (0/1)0%   (0/3)0%   (0/98)0%   (0/31)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DemandBasedWaitingTimeCalculator0%   (0/1)0%   (0/3)0%   (0/98)0%   (0/31)
DemandBasedWaitingTimeCalculator (ProbeSpecContext, Integer, Integer): void 0%   (0/1)0%   (0/6)0%   (0/2)
calculate (ProbeSetSample, ProbeSetSample): Vector 0%   (0/1)0%   (0/66)0%   (0/22)
obtainDemandProbeSample (ProbeSetSample): ProbeSample 0%   (0/1)0%   (0/26)0%   (0/7)

1package de.uka.ipd.sdq.probespec.framework.calculator;
2 
3import java.util.Vector;
4 
5import javax.measure.Measure;
6import javax.measure.quantity.Duration;
7import javax.measure.quantity.Quantity;
8import javax.measure.unit.Unit;
9 
10import de.uka.ipd.sdq.probespec.framework.ProbeSample;
11import de.uka.ipd.sdq.probespec.framework.ProbeSetSample;
12import de.uka.ipd.sdq.probespec.framework.ProbeSpecContext;
13import de.uka.ipd.sdq.probespec.framework.ProbeType;
14import de.uka.ipd.sdq.probespec.framework.exceptions.CalculatorException;
15import de.uka.ipd.sdq.probespec.framework.matching.IMatchRule;
16import de.uka.ipd.sdq.probespec.framework.matching.ProbeTypeMatchRule;
17 
18/**
19 * Calculates the waiting time for resources in environments where the stop of
20 * the waiting period cannot be observed directly. Rather the following values
21 * (respectively events) should be observable.
22 * <ul>
23 * <li><code>start</code> - "request for processing"-event</li>
24 * <li><code>stop</code> - "end of processing"-event (Notice: This is different
25 * from the waiting period stop)</li>
26 * <li><code>demand</code> - the demanded time</li>
27 * </ul>
28 * The waiting time results from calculating
29 * <code>(stop - start) - demand </code>.
30 * 
31 * @author pmerkle
32 * 
33 */
34public class DemandBasedWaitingTimeCalculator extends WaitingTimeCalculator {
35 
36    public DemandBasedWaitingTimeCalculator(ProbeSpecContext ctx, Integer startWaitingProbeSetID,
37            Integer stopProcessingProbeSetID) {
38        super(ctx, startWaitingProbeSetID, stopProcessingProbeSetID);
39    }
40 
41        @SuppressWarnings("unchecked")
42        @Override
43        protected Vector<Measure<?, ? extends Quantity>> calculate(
44                        ProbeSetSample start, ProbeSetSample end)
45                        throws CalculatorException {
46                // Obtain demand. The demand of start and end should be equal!
47                ProbeSample<Double, Duration> demandSample = obtainDemandProbeSample(start);
48                if (demandSample == null) {
49                        throw new CalculatorException(
50                                        "Could not access demand probe sample.");
51                }
52 
53                // Obtain processing time
54                Vector<Measure<?, ? extends Quantity>> timeSpanResultTuple = super
55                                .calculate(start, end);
56                Measure<Double, Duration> processingTimeSpanMeasure = (Measure<Double, Duration>) timeSpanResultTuple
57                                .get(0);
58                Measure<Double, Duration> endTimeMeasure = (Measure<Double, Duration>) timeSpanResultTuple
59                                .get(1);
60 
61                // Calculate waiting time
62                Unit<Duration> unit = processingTimeSpanMeasure.getUnit();
63                double demand = demandSample.getMeasure().doubleValue(unit);
64                double processingTime = processingTimeSpanMeasure.doubleValue(unit);
65                double waitingTime = processingTime - demand;
66                if (waitingTime < 0) {
67//                        final double threshold = -0.000001;
68//                        if (waitingTime < threshold) {
69//                                throw new RuntimeException(
70//                                                "Calculated negative waiting time. This should not happen!");
71//                        } else {
72                                waitingTime = 0;
73//                        }
74                }
75 
76                // Create result tuple
77                Measure<Double, Duration> waitingTimeMeasure = Measure.valueOf(
78                                waitingTime, unit);
79                Vector<Measure<?, ? extends Quantity>> resultTuple = new Vector<Measure<?, ? extends Quantity>>();
80                resultTuple.add(waitingTimeMeasure);
81                resultTuple.add(endTimeMeasure);
82 
83                return resultTuple;
84        }
85 
86        @SuppressWarnings("unchecked")
87        private ProbeSample<Double, Duration> obtainDemandProbeSample(
88                        ProbeSetSample probeSetSample) {
89                IMatchRule[] rules = new IMatchRule[1];
90                rules[0] = new ProbeTypeMatchRule(ProbeType.RESOURCE_DEMAND);
91                Vector<ProbeSample<?, ? extends Quantity>> result = probeSetSample
92                                .getProbeSamples(rules);
93 
94                if (result != null && result.size() > 0)
95                        return (ProbeSample<Double, Duration>) result.get(0);
96 
97                return null;
98        }
99 
100}

[all classes][de.uka.ipd.sdq.probespec.framework.calculator]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov