1 | package de.uka.ipd.sdq.prototype.framework.strategies; |
2 | |
3 | import java.util.HashMap; |
4 | |
5 | import de.uka.ipd.sdq.measurement.strategies.activeresource.IDemandStrategy; |
6 | import de.uka.ipd.sdq.measurement.strategies.activeresource.ResourceTypeEnum; |
7 | |
8 | public class DemandConsumerStrategiesRegistry { |
9 | |
10 | private HashMap<ResourceTypeEnum,IDemandStrategy> strategiesHash = new HashMap<ResourceTypeEnum, IDemandStrategy>(); |
11 | private static DemandConsumerStrategiesRegistry singletonInstance = new DemandConsumerStrategiesRegistry(); |
12 | |
13 | private DemandConsumerStrategiesRegistry() { |
14 | } |
15 | |
16 | public static DemandConsumerStrategiesRegistry singleton() { |
17 | return singletonInstance; |
18 | } |
19 | |
20 | public void registerStrategyFor(ResourceTypeEnum resourceType, IDemandStrategy strategy){ |
21 | strategiesHash.put(resourceType, strategy); |
22 | } |
23 | |
24 | public IDemandStrategy getStrategyFor(ResourceTypeEnum resource) { |
25 | if(!strategiesHash.containsKey(resource)) { |
26 | // TODO: This is a temporary J2EE hack, only simulate CPUs. |
27 | // double procRate = 10; |
28 | // System.out.println("Warning: the CPU strategy has been hard-codedly set to a processing rate of "+procRate); |
29 | // IDemandStrategy strategy = new FibonacciDemand(); |
30 | // strategy.initializeStrategy(DegreeOfAccuracyEnum.MEDIUM,procRate); |
31 | // strategiesHash.put(resource,strategy); |
32 | // return strategy; |
33 | throw new RuntimeException("Requested Resourcestrategy >"+resource+"< is not registered!"); |
34 | } |
35 | |
36 | return strategiesHash.get(resource); |
37 | } |
38 | } |