1 | package schedframe.resources; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.HashMap; |
---|
5 | import java.util.Iterator; |
---|
6 | import java.util.List; |
---|
7 | import java.util.Map; |
---|
8 | |
---|
9 | import schedframe.resources.units.ResourceUnit; |
---|
10 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
11 | |
---|
12 | /** |
---|
13 | * |
---|
14 | * @author Marcin Krystek |
---|
15 | * |
---|
16 | */ |
---|
17 | public class ResourceStateDescription extends ResourceDescription { |
---|
18 | |
---|
19 | protected ResourceType type; |
---|
20 | |
---|
21 | protected Map<String, Integer> queue_size; |
---|
22 | |
---|
23 | public ResourceStateDescription(ResourceProvider provider){ |
---|
24 | super(); |
---|
25 | this.provider = provider; |
---|
26 | this.queue_size = new HashMap<String, Integer>(); |
---|
27 | } |
---|
28 | |
---|
29 | public ResourceStateDescription(ResourceDescription r){ |
---|
30 | super(r); |
---|
31 | } |
---|
32 | |
---|
33 | public void addResourceUnit(ResourceUnit unit){ |
---|
34 | List<ResourceUnit> list = null; |
---|
35 | |
---|
36 | if(this.resUnits.containsKey(unit.getName())){ |
---|
37 | list = this.resUnits.get(unit.getName()); |
---|
38 | } else { |
---|
39 | list = new ArrayList<ResourceUnit>(); |
---|
40 | this.resUnits.put(unit.getName(), list); |
---|
41 | } |
---|
42 | list.add(unit); |
---|
43 | } |
---|
44 | |
---|
45 | public void addResourceUnit(Map<ResourceParameterName, ResourceUnit> allUnits){ |
---|
46 | Iterator<ResourceUnit> itr = allUnits.values().iterator(); |
---|
47 | while(itr.hasNext()){ |
---|
48 | addResourceUnit(itr.next()); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | public void addResourceUnitList(Map<ResourceParameterName, List<ResourceUnit>> allUnits){ |
---|
53 | this.resUnits.putAll(allUnits); |
---|
54 | } |
---|
55 | |
---|
56 | public void setType(ResourceType type){ |
---|
57 | this.type = type; |
---|
58 | } |
---|
59 | |
---|
60 | public ResourceType getType() { |
---|
61 | return type; |
---|
62 | } |
---|
63 | |
---|
64 | public void setQueuesSize(Map<String, Integer> queue_size){ |
---|
65 | this.queue_size = queue_size; |
---|
66 | } |
---|
67 | |
---|
68 | public long getQueueLoad(String queueName) throws NoSuchFieldException{ |
---|
69 | long load = 0; |
---|
70 | if(queueName == null){ |
---|
71 | for(String queue: queue_size.keySet()){ |
---|
72 | load += queue_size.get(queue); |
---|
73 | } |
---|
74 | return load; |
---|
75 | } |
---|
76 | else if(queue_size.containsKey(queueName)) |
---|
77 | return queue_size.get(queueName); |
---|
78 | else |
---|
79 | throw new NoSuchFieldException("Queue " + queueName + |
---|
80 | " is not available in resource " + provider.id); |
---|
81 | } |
---|
82 | } |
---|