source: xssim/trunk/src/schedframe/scheduling/TimeResourceAllocation.java @ 104

Revision 104, 2.6 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.scheduling;
2
3import java.util.Collection;
4import java.util.Iterator;
5
6import org.joda.time.DateTime;
7import org.joda.time.MutableInterval;
8
9import schedframe.resources.ResourceDescription;
10import schedframe.resources.units.ResourceUnit;
11
12/**
13 * This class defines a resource allocation over time
14 * It contains information about time frame and specific resources allocated
15 * It may be initialized by a description of allocated resources or
16 * by a list of allocated resource units (e.g. number of CPUs, memory etc.)
17 *
18 * @author Ariel
19 * @author Marcin Krystek
20 */
21public class TimeResourceAllocation extends MutableInterval {
22       
23        /**
24         *
25         */
26        private static final long serialVersionUID = -8327181428985141349L;
27
28        /**
29         * Id of this allocation
30         */
31        protected String id;
32
33        /**
34         * Contains detail information about resource.
35         */
36        protected ResourceDescription allocatedResource;
37
38       
39        protected static int uniqueID_ = -1;
40       
41        protected synchronized int getUniqueID(){
42                uniqueID_++;
43                return uniqueID_;
44        }
45       
46        public TimeResourceAllocation(DateTime startTime, DateTime endTime) {
47                super(startTime, endTime);
48
49                allocatedResource = null;
50               
51                id = String.valueOf(getUniqueID());
52        }
53       
54        public TimeResourceAllocation(ResourceDescription allocatedResource, DateTime startTime,
55                        DateTime endTime) {
56
57                this(startTime, endTime);
58               
59                this.allocatedResource = allocatedResource;
60
61        }
62
63        /**
64         * Copy constructor
65         * @param alloc
66         */
67        public TimeResourceAllocation(TimeResourceAllocation alloc) {
68                super(alloc.getStart(), alloc.getEnd());
69                this.id = alloc.getId();
70                this.allocatedResource = (ResourceDescription)alloc.getAllocatedResource().clone();
71        }
72       
73       
74       
75        public String getId() {
76                return id;
77        }
78
79
80        public ResourceDescription getAllocatedResource(){
81                return this.allocatedResource;
82        }
83       
84        public void setAllocatedResource(ResourceDescription resDesc){
85                this.allocatedResource = resDesc;
86        }
87
88        public String toString() {
89                String start = getStart().toString("YYYY-MM-dd HH:mm:ss");
90                String end = getEnd().toString("YYYY-MM-dd HH:mm:ss");
91                String resources = "";
92                String desc = id + " resources: " + resources + " <" + start
93                                + " - " + end + ">";
94
95                Collection<ResourceUnit> res =  this.allocatedResource.getResourceUnit();
96                if (res != null) {
97                        Iterator<ResourceUnit> itr = res.iterator();
98                        while(itr.hasNext()){
99                                ResourceUnit unit = itr.next();
100                                desc += unit;
101                        }
102                }
103                return desc;
104        }
105
106        public boolean equals(Object obj) {
107                if (obj instanceof TimeResourceAllocation == false)
108                        return false;
109               
110                TimeResourceAllocation other = (TimeResourceAllocation) obj;
111               
112                if (! id.equals(other.id)) return false;
113               
114                return super.equals(other);
115        }
116       
117}
Note: See TracBrowser for help on using the repository browser.