| 1 | package de.uka.ipd.sdq.probespec.framework.probes.example; |
| 2 | |
| 3 | import static javax.measure.unit.SI.MILLI; |
| 4 | import static javax.measure.unit.SI.SECOND; |
| 5 | |
| 6 | import javax.measure.Measure; |
| 7 | import javax.measure.quantity.Duration; |
| 8 | import javax.measure.unit.SI; |
| 9 | |
| 10 | import de.uka.ipd.sdq.probespec.framework.ProbeSample; |
| 11 | import de.uka.ipd.sdq.probespec.framework.ProbeType; |
| 12 | import de.uka.ipd.sdq.probespec.framework.probes.IProbeStrategy; |
| 13 | |
| 14 | /** |
| 15 | * ProbeStrategy which is able to measure the current simulated time. The |
| 16 | * simulated time's unit is assumed to be {@link SI#SECOND}. |
| 17 | * |
| 18 | * @author Philipp Merkle |
| 19 | * |
| 20 | */ |
| 21 | public class ExampleTakeCurrentTimeStrategy implements IProbeStrategy { |
| 22 | |
| 23 | /** |
| 24 | * @param o |
| 25 | * expects a {@link SimpleSimulationContext} |
| 26 | */ |
| 27 | @Override |
| 28 | public ProbeSample<Double, Duration> takeSample(final String probeId, |
| 29 | final Object... o) { |
| 30 | SimpleSimulationContext simContext = null; |
| 31 | if (o.length >= 1 && o[0] instanceof SimpleSimulationContext) { |
| 32 | simContext = (SimpleSimulationContext) o[0]; |
| 33 | } else { |
| 34 | if (o.length == 0) { |
| 35 | throw new IllegalArgumentException("Missing argument of type " |
| 36 | + SimpleSimulationContext.class.getSimpleName() + "."); |
| 37 | } else { |
| 38 | throw new IllegalArgumentException("Expected an argument of type " |
| 39 | + SimpleSimulationContext.class.getSimpleName() |
| 40 | + " but was " + o[0].getClass().getSimpleName() + "."); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | Measure<Double, Duration> time = Measure.valueOf((double) simContext |
| 45 | .getSimulatedTime(), MILLI(SECOND)); |
| 46 | ProbeSample<Double, Duration> sample = new ProbeSample<Double, Duration>( |
| 47 | time, probeId, ProbeType.CURRENT_TIME); |
| 48 | return sample; |
| 49 | } |
| 50 | |
| 51 | } |