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

Revision 104, 2.9 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.List;
4
5import org.joda.time.DateTime;
6
7import schedframe.resources.ResourceDescription;
8import schedframe.resources.ResourceProvider;
9import schedframe.scheduling.utils.ResourceParameterName;
10
11/**
12 *
13 * @author Marcin Krystek
14 *
15 */
16public class Reservation extends TimeResourceAllocation {
17
18        private static final long serialVersionUID = 7837525861926610754L;
19
20        protected Status status;
21
22        protected DateTime creationTime;
23       
24        protected ResourceProvider resourceProvider;
25       
26        protected List<ReservedHost> reservedHosts;
27       
28        protected String jobId;
29       
30        protected String taskId;
31       
32        protected String userId;
33       
34        public Reservation(ResourceDescription allocatedResource,
35                        DateTime startTime, DateTime endTime, DateTime creationTime) {
36                super(allocatedResource, startTime, endTime);
37                this.creationTime = creationTime;
38        }
39       
40        public Reservation(Reservation r){
41                super(r);
42                this.status = r.getStatus();
43                this.creationTime = new DateTime(r.getCreationTime());
44                this.resourceProvider = r.getResourceProvider();
45        }
46
47        public Status getStatus(){
48                return this.status;
49        }
50       
51        public synchronized void setStatus(Status status){
52                this.status = status;
53        }
54       
55        public ResourceProvider getResourceProvider(){
56                return this.resourceProvider;
57        }
58       
59        public void setResourceProvider(ResourceProvider provider){
60                this.resourceProvider = provider;
61        }
62       
63        public DateTime getCreationTime(){
64                return this.creationTime;
65        }
66       
67        public boolean equals(Object obj){
68                if(obj instanceof Reservation == false)
69                        return false;
70               
71                if(! super.equals(obj)) return false;
72               
73                Reservation r = (Reservation) obj;
74               
75                if(creationTime != null && ! creationTime.equals(r.getCreationTime())) return false;
76               
77                if(resourceProvider != null && ! resourceProvider.equals(r.resourceProvider)) return false;
78               
79                if(status != r.getStatus())
80                        throw new RuntimeException("Two objects, representing reservation "+ this.id +
81                                        " have different status.");
82               
83                return true;
84        }
85       
86        public String toString(){
87                String s = null;
88                try {
89                        s = "reservation id/jobId/taskId/start/end: " +
90                        id + "/" + jobId + "/" + taskId + "/" + getStart() + "/" + getEnd() +
91                        " res amount: " + allocatedResource.getResourceUnit(ResourceParameterName.CPUCOUNT).getUsedAmount();
92                } catch (NoSuchFieldException e) {
93                        e.printStackTrace();
94                }
95                return s;
96        }
97       
98        public String getJobId() {
99                return jobId;
100        }
101
102        public void setJobId(String jobId) {
103                this.jobId = jobId;
104        }
105
106        public String getTaskId() {
107                return taskId;
108        }
109
110        public void setTaskId(String taskId) {
111                this.taskId = taskId;
112        }
113
114        public String getUserId() {
115                return userId;
116        }
117
118        public void setUserId(String userId) {
119                this.userId = userId;
120        }
121       
122        public List<ReservedHost> getReservedHosts(){
123                return this.reservedHosts;
124        }
125       
126        public void setReservedHosts(List<ReservedHost> list){
127                this.reservedHosts = list;
128        }
129       
130        public enum Status{
131                INITIAL(),
132                COMMITTED(),
133                ACTIVE(),
134                EXPIRED(),
135                CANCELED(),
136                FINISHED();
137        }
138}
Note: See TracBrowser for help on using the repository browser.