| 1 | package de.uka.ipd.sdq.simucomframework.probes; |
| 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 | import de.uka.ipd.sdq.scheduler.IPassiveResource; |
| 10 | |
| 11 | /** |
| 12 | * ProbeStrategy which is able to measure the state of a |
| 13 | * {@link IPassiveResource}. The state is calculated as follows: |
| 14 | * <code>state = capacity - available</code>. |
| 15 | * |
| 16 | * @author Philipp Merkle |
| 17 | * |
| 18 | */ |
| 19 | public class TakePassiveResourceStateStrategy implements IProbeStrategy { |
| 20 | |
| 21 | /** |
| 22 | * @param o |
| 23 | * expects a {@link IPassiveResource} |
| 24 | */ |
| 25 | public ProbeSample<Integer, Dimensionless> takeSample(String probeId, |
| 26 | Object... o) { |
| 27 | IPassiveResource r = null; |
| 28 | if (o.length >= 1 && o[0] instanceof IPassiveResource) { |
| 29 | r = (IPassiveResource) o[0]; |
| 30 | } else { |
| 31 | throw new IllegalArgumentException("Expected an argument of type " |
| 32 | + IPassiveResource.class.getSimpleName() + "."); |
| 33 | } |
| 34 | |
| 35 | int state = r.getCapacity() - r.getAvailable(); |
| 36 | Measure<Integer, Dimensionless> stateMeasure = Measure.valueOf(state, |
| 37 | Dimensionless.UNIT); |
| 38 | ProbeSample<Integer, Dimensionless> sample = new ProbeSample<Integer, Dimensionless>( |
| 39 | stateMeasure, probeId, ProbeType.RESOURCE_STATE); |
| 40 | |
| 41 | return sample; |
| 42 | } |
| 43 | |
| 44 | } |