source: xssim/src/test/rewolucja/resources/manager/utils/ResourceManagerUtils.java @ 104

Revision 104, 2.3 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.rewolucja.resources.manager.utils;
2
3import java.util.ArrayList;
4import java.util.HashSet;
5import java.util.List;
6import java.util.Map;
7import java.util.Set;
8
9import schedframe.resources.units.Memory;
10import schedframe.resources.units.ResourceUnit;
11import schedframe.scheduling.utils.ResourceParameterName;
12import test.rewolucja.resources.ProcessingElements;
13import test.rewolucja.resources.ResourceStatus;
14import test.rewolucja.resources.UnitState;
15import test.rewolucja.resources.physical.base.ComputingResource;
16
17public class ResourceManagerUtils {
18       
19        public static void clearPendingResources(Map<ResourceParameterName, ResourceUnit> choosenResources){
20
21                ProcessingElements processingElements = (ProcessingElements)choosenResources.get(ResourceParameterName.PROCESSINGELEMENTS);
22                if(processingElements != null) {
23                        for (int i = 0; i < processingElements.size(); i++) {
24                                ComputingResource pe = processingElements.get(i);
25                                if (pe.getStatus() == ResourceStatus.PENDING) {
26                                        pe.setStatus(ResourceStatus.FREE);
27                                }
28                        }
29                }
30                Memory memory = (Memory)choosenResources.get(ResourceParameterName.MEMORY);
31                if(memory != null){
32                        if(memory.getState()==UnitState.PENDING)
33                                memory.setState(UnitState.FREE);
34                }
35        }
36       
37        public static void setPendingResources(Map<ResourceParameterName, ResourceUnit> choosenResources){
38
39                ProcessingElements processingElements = (ProcessingElements)choosenResources.get(ResourceParameterName.PROCESSINGELEMENTS);
40                if(processingElements != null) {
41                        for (int i = 0; i < processingElements.size(); i++) {
42                                ComputingResource pe = processingElements.get(i);
43                                if (pe.getStatus() == ResourceStatus.FREE) {
44                                        pe.setStatus(ResourceStatus.PENDING);
45                                }
46                        }
47                }
48                Memory memory = (Memory)choosenResources.get(ResourceParameterName.MEMORY);
49                if(memory != null){
50                        if(memory.getState()==UnitState.FREE)
51                                memory.setState(UnitState.PENDING);
52                }
53
54        }
55       
56        public static ComputingResource getCommonParent(List<ComputingResource> resources){
57
58                Set<ComputingResource> parents = new HashSet<ComputingResource>(resources);
59                while(parents.size() != 1){
60                        parents = new HashSet<ComputingResource>();
61                        for(ComputingResource resource: resources){
62                                parents.add(resource.getParent());
63                        }
64                        resources = new ArrayList<ComputingResource>(parents);
65                }
66                return resources.get(0);
67        }
68
69
70}
Note: See TracBrowser for help on using the repository browser.