1 | package de.uka.ipd.sdq.simucomframework.probes; |
2 | |
3 | import javax.measure.Measure; |
4 | import javax.measure.quantity.Duration; |
5 | import javax.measure.unit.SI; |
6 | |
7 | import de.uka.ipd.sdq.probespec.framework.ProbeSample; |
8 | import de.uka.ipd.sdq.probespec.framework.ProbeType; |
9 | import de.uka.ipd.sdq.probespec.framework.probes.IProbeStrategy; |
10 | import de.uka.ipd.sdq.simucomframework.resources.ScheduledResource; |
11 | |
12 | /** |
13 | * ProbeStrategy which is able to measure the demanded time of a |
14 | * {@link ScheduledResource}. The unit is assumed to be |
15 | * {@link SI#SECOND}. |
16 | * |
17 | * @author Philipp Merkle |
18 | * |
19 | */ |
20 | public class TakeScheduledResourceDemandStrategy implements IProbeStrategy { |
21 | |
22 | /** |
23 | * @param o |
24 | * expects a {@link Double} that represents the demand |
25 | */ |
26 | public ProbeSample<Double, Duration> takeSample(String probeId, Object... o) { |
27 | Double demand = null; |
28 | if (o.length >= 1 && o[0] instanceof Double) { |
29 | demand = (Double) o[0]; |
30 | } else { |
31 | throw new IllegalArgumentException("Expected an argument of type " |
32 | + Double.class.getSimpleName() + "."); |
33 | } |
34 | |
35 | // Here it is assumed that the simulation time's unit is SI.SECOND |
36 | Measure<Double, Duration> demandMeasure = Measure.valueOf(demand, |
37 | SI.SECOND); |
38 | ProbeSample<Double, Duration> sample = new ProbeSample<Double, Duration>( |
39 | demandMeasure, probeId, ProbeType.RESOURCE_DEMAND); |
40 | |
41 | return sample; |
42 | } |
43 | |
44 | } |