1 | package de.uka.ipd.sdq.simucomframework.resources; |
2 | |
3 | import java.util.Iterator; |
4 | import java.util.Map.Entry; |
5 | |
6 | import de.uka.ipd.sdq.simucomframework.SimuComSimProcess; |
7 | import de.uka.ipd.sdq.simucomframework.exceptions.ResourceContainerIsMissingRequiredResourceType; |
8 | import de.uka.ipd.sdq.simucomframework.model.SimuComModel; |
9 | |
10 | public class SimulatedLinkingResourceContainer extends |
11 | AbstractSimulatedResourceContainer { |
12 | |
13 | public SimulatedLinkingResourceContainer(SimuComModel myModel, String id) { |
14 | super(myModel, id); |
15 | } |
16 | |
17 | public void addActiveResource(String id, String typeID, |
18 | String resourceContainerID, String resourceTypeID, |
19 | String description, String throughput, String latencySpec, |
20 | Double failureProbability) { |
21 | SimulatedLinkingResource r = new SimulatedLinkingResource(id, myModel, |
22 | typeID, resourceContainerID, resourceTypeID, description, |
23 | throughput, latencySpec, failureProbability); |
24 | activeResources.put(typeID, r); |
25 | |
26 | // setup calculators |
27 | // TODO: setup waiting time calculator |
28 | // CalculatorHelper.setupWaitingTimeCalculator(r); |
29 | CalculatorHelper.setupDemandCalculator(r, this.myModel); |
30 | CalculatorHelper.setupStateCalculator(r, this.myModel); |
31 | } |
32 | |
33 | /** |
34 | * Retrieves the id of the first (i.e. the one and only) communication link |
35 | * resource specification. |
36 | * |
37 | * @return the id of the communication link resource specification |
38 | */ |
39 | public String getLinkingResourceId() { |
40 | Iterator<Entry<String, AbstractScheduledResource>> iterator = activeResources |
41 | .entrySet().iterator(); |
42 | while (iterator.hasNext()) { |
43 | Entry<String, AbstractScheduledResource> entry = iterator.next(); |
44 | SimulatedLinkingResource resource = (SimulatedLinkingResource) entry |
45 | .getValue(); |
46 | return resource.getId(); |
47 | } |
48 | return null; |
49 | } |
50 | |
51 | public void loadActiveResource(SimuComSimProcess requestingProcess, String originResourceContainerID, String typeID, double demand) { |
52 | AbstractScheduledResource resource = activeResources.get(typeID); |
53 | if (resource == null) { |
54 | throw new ResourceContainerIsMissingRequiredResourceType(typeID); |
55 | } |
56 | resource.consumeResource(requestingProcess, 1, demand); |
57 | } |
58 | |
59 | /** |
60 | * Retrieves the id of the resource type of the first (i.e. the one and |
61 | * only) communication link resource specification. |
62 | * |
63 | * @return the resource type id |
64 | */ |
65 | public String getLinkingResourceTypeId() { |
66 | Iterator<Entry<String, AbstractScheduledResource>> iterator = activeResources |
67 | .entrySet().iterator(); |
68 | while (iterator.hasNext()) { |
69 | Entry<String, AbstractScheduledResource> entry = iterator.next(); |
70 | SimulatedLinkingResource resource = (SimulatedLinkingResource) entry |
71 | .getValue(); |
72 | return resource.getResourceTypeId(); |
73 | } |
74 | return null; |
75 | } |
76 | |
77 | /** |
78 | * Retrieves the resource type name of the first (i.e. the one and only) |
79 | * communication link resource specification. |
80 | * |
81 | * @return the resource type name of the communication link resource |
82 | * specification |
83 | */ |
84 | public String getLinkingResourceTypeName() { |
85 | Iterator<Entry<String, AbstractScheduledResource>> iterator = activeResources |
86 | .entrySet().iterator(); |
87 | while (iterator.hasNext()) { |
88 | Entry<String, AbstractScheduledResource> entry = iterator.next(); |
89 | SimulatedLinkingResource resource = (SimulatedLinkingResource) entry |
90 | .getValue(); |
91 | return resource.getName(); |
92 | } |
93 | return null; |
94 | } |
95 | } |