source: xssim/src/test/rewolucja/resources/description/AbstractResourceDescription.java @ 104

Revision 104, 3.6 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.rewolucja.resources.description;
2
3
4import java.util.ArrayList;
5import java.util.Collection;
6import java.util.HashMap;
7import java.util.Iterator;
8import java.util.List;
9import java.util.Map;
10
11import schedframe.resources.units.ResourceUnit;
12import schedframe.scheduling.utils.ResourceParameterName;
13import test.rewolucja.resources.ResourceType;
14import test.rewolucja.scheduling.queue.GSSIMQueue;
15
16
17public abstract class AbstractResourceDescription {
18
19        //protected ResourceProvider provider;
20        protected String resourceId;
21        /*protected AbstractResourceDescription parent;
22        /public AbstractResourceDescription getParent() {
23                return parent;
24        }
25
26        public void setParent(AbstractResourceDescription parent) {
27                this.parent = parent;
28        }*/
29
30        protected List<AbstractResourceDescription> children;
31        protected ResourceType type;
32        protected Map<ResourceParameterName, List<ResourceUnit>> resUnits;
33       
34        public AbstractResourceDescription(ResourceType type){
35                this.type = type;
36                this.children = null;
37                //this.resUnits = new HashMap<ResourceParameterName, List<ResourceUnit>>();
38        }
39
40        public List<AbstractResourceDescription> getChildren() {
41                return children;
42        }
43       
44        public void setChildren(List<AbstractResourceDescription> children) {
45                this.children = children;
46        }
47       
48        public void addChildren(AbstractResourceDescription child) {
49                //child.setParent(this);
50                if(children == null)
51                        children = new ArrayList<AbstractResourceDescription> (1);
52                this.children.add(child);
53        }
54       
55        /**
56         *
57         * @return resource id
58         */
59        public String getResourceId(){
60                return this.resourceId;
61        }
62
63        /**
64         *
65         * @param unitName name of the resource unit
66         * @return resource unit value
67         * @throws NoSuchFieldException if particular resource unit is not defined
68         */
69        public ResourceUnit getResourceUnit(ResourceParameterName unitName) throws NoSuchFieldException{
70                return getResourceUnitList(unitName).get(0);
71        }
72       
73        public List<ResourceUnit> getResourceUnitList(ResourceParameterName unitName) throws NoSuchFieldException{
74                if(resUnits.containsKey(unitName))
75                        return resUnits.get(unitName);
76                else
77                        throw new NoSuchFieldException("Resource unit " + unitName +
78                                                        " is not available in resource " + this.resourceId);
79       
80        }
81       
82        public Collection<ResourceUnit> getResourceUnit(){
83                if(resUnits == null)
84                        return null;
85                List<ResourceUnit> values = new ArrayList<ResourceUnit>();
86                Collection<List<ResourceUnit>> lists = resUnits.values();
87                Iterator<List<ResourceUnit>> itr = lists.iterator();
88               
89                while(itr.hasNext()){
90                        List<ResourceUnit> list = itr.next();
91                        values.addAll(list);
92                }
93               
94                return values;
95        }
96       
97        public  Map<ResourceParameterName, List<ResourceUnit>> getResourceUnits(){
98                return resUnits;
99        }
100
101
102        public Object clone(){
103                AbstractResourceDescription copy = null;
104                try {
105                        copy = (AbstractResourceDescription) super.clone();
106                        copy.resUnits = new HashMap<ResourceParameterName, List<ResourceUnit>>();
107                        Iterator<ResourceParameterName> itr = this.resUnits.keySet().iterator();
108                        while(itr.hasNext()){
109                                ResourceParameterName name = itr.next();
110                                List<ResourceUnit> list = this.resUnits.get(name);
111                                List<ResourceUnit> newList = new ArrayList<ResourceUnit>(list.size());
112                                for(int i = 0; i < list.size(); i++){
113                                        newList.add((ResourceUnit)list.get(i).clone());
114                                }
115                                copy.resUnits.put(name, newList);
116                        }
117                       
118                } catch (CloneNotSupportedException e) {
119                        e.printStackTrace();
120                }
121               
122                return copy;
123        }
124       
125        /*public enum ResourceType {
126                COMPUTING_RESOURCE,
127                QUEUING_SYSTEM;
128        }
129        */
130        public abstract long getQueueLoad(String queueName) throws NoSuchFieldException;
131
132        public ResourceType getType() {
133                return type;
134        }
135       
136        public abstract List<GSSIMQueue> getAccessQueues();
137       
138}
Note: See TracBrowser for help on using the repository browser.