| 1 | package de.uka.ipd.sdq.probespec.framework.probes.example; |
| 2 | |
| 3 | import javax.measure.Measure; |
| 4 | import javax.measure.quantity.Dimensionless; |
| 5 | |
| 6 | import de.uka.ipd.sdq.probespec.framework.ProbeSample; |
| 7 | import de.uka.ipd.sdq.probespec.framework.ProbeType; |
| 8 | import de.uka.ipd.sdq.probespec.framework.probes.IProbeStrategy; |
| 9 | |
| 10 | public class ExampleTakeCPUDemandStrategy implements IProbeStrategy { |
| 11 | |
| 12 | /** |
| 13 | * @param o |
| 14 | * expects a {@link ISimpleDemanding} and a |
| 15 | * {@link ASimpleActiveResource} in arbitrary order |
| 16 | */ |
| 17 | @Override |
| 18 | public ProbeSample<Double, Dimensionless> takeSample(String probeId, |
| 19 | Object... o) { |
| 20 | ISimpleDemanding demanding = null; |
| 21 | ASimpleActiveResource resource = null; |
| 22 | for (Object object : o) { |
| 23 | if (object instanceof ISimpleDemanding) { |
| 24 | demanding = (ISimpleDemanding) object; |
| 25 | } else if (object instanceof SimpleCPUResource) { |
| 26 | resource = (ASimpleActiveResource) object; |
| 27 | } |
| 28 | } |
| 29 | if (demanding == null) { |
| 30 | throw new IllegalArgumentException( |
| 31 | "Expected an argument implementing IExampleDemanding."); |
| 32 | } |
| 33 | if (resource == null) { |
| 34 | throw new IllegalArgumentException( |
| 35 | "Expected an argument of type SimpleCPUResource."); |
| 36 | } |
| 37 | |
| 38 | Measure<Double, Dimensionless> demand = Measure.valueOf(demanding |
| 39 | .getDemand(resource), Dimensionless.UNIT); |
| 40 | ProbeSample<Double, Dimensionless> sample = new ProbeSample<Double, Dimensionless>( |
| 41 | demand, probeId, ProbeType.RESOURCE_DEMAND); |
| 42 | |
| 43 | return sample; |
| 44 | } |
| 45 | |
| 46 | } |