source: DCWoRMS/trunk/build/classes/schedframe/scheduling/plan/impl/ScheduledTask.java @ 539

Revision 539, 5.6 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.scheduling.plan.impl;
2
3import java.io.StringWriter;
4import java.util.ArrayList;
5
6import org.exolab.castor.xml.MarshalException;
7import org.exolab.castor.xml.ValidationException;
8import org.qcg.broker.schemas.schedulingplan.types.AllocationStatus;
9
10import schedframe.scheduling.plan.AllocationInterface;
11import schedframe.scheduling.plan.ScheduledTaskInterface;
12import schedframe.scheduling.plan.ScheduledTimeInterface;
13import schedframe.scheduling.tasks.TaskInterface;
14
15public class ScheduledTask implements ScheduledTaskInterface<org.qcg.broker.schemas.schedulingplan.Task> {
16
17        private static final long serialVersionUID = -9006532413203045991L;
18        protected org.qcg.broker.schemas.schedulingplan.Task t;
19
20        public ScheduledTask(){
21                t = new org.qcg.broker.schemas.schedulingplan.Task();
22                allocationList = new ArrayList<AllocationInterface<?>>();
23        }
24       
25        public ScheduledTask(org.qcg.broker.schemas.schedulingplan.Task value){
26                t = value;
27                allocationList = new ArrayList<AllocationInterface<?>>();
28        }
29       
30       
31        public org.qcg.broker.schemas.schedulingplan.Task getDescription() {
32                return t;
33        }
34
35        public String getDocument() {
36                StringWriter writer = new StringWriter();
37                try {
38                        t.marshal(writer);
39                } catch (MarshalException e) {
40                        e.printStackTrace();
41                } catch (ValidationException e) {
42                        e.printStackTrace();
43                }
44                return writer.toString();
45        }
46
47        public <Allocation_> void addAllocation(
48                        AllocationInterface<Allocation_> allocation)
49                        throws IndexOutOfBoundsException {
50                t.addAllocation((org.qcg.broker.schemas.schedulingplan.Allocation) allocation.getDescription());
51                allocationList.add(allocation);
52        }
53
54        public <Allocation_> void addAllocation(int index, AllocationInterface<Allocation_> allocation)
55                        throws IndexOutOfBoundsException {
56                t.addAllocation(index, (org.qcg.broker.schemas.schedulingplan.Allocation) allocation.getDescription());
57                allocationList.add(index, allocation);
58        }
59
60        public void deleteTopology() {
61                t.deleteTopology();
62        }
63
64        @SuppressWarnings("unchecked")
65        public AllocationInterface<org.qcg.broker.schemas.schedulingplan.Allocation> getAllocation(int index)
66                        throws IndexOutOfBoundsException {
67                return new schedframe.scheduling.plan.impl.Allocation(t.getAllocation(index));
68        }
69
70        @SuppressWarnings("unchecked")
71        public AllocationInterface<org.qcg.broker.schemas.schedulingplan.Allocation>[] getAllocation() {
72                org.qcg.broker.schemas.schedulingplan.Allocation tab[] = t.getAllocation();
73                if(tab == null) return null;
74               
75                schedframe.scheduling.plan.impl.Allocation ret[] = new schedframe.scheduling.plan.impl.Allocation[tab.length];
76                for(int i = 0; i < tab.length; i++){
77                        ret[i] = new schedframe.scheduling.plan.impl.Allocation(tab[i]);
78                }
79                return ret;
80        }
81
82        public int getAllocationCount() {
83                return t.getAllocationCount();
84        }
85
86        public String getJobId() {
87                return t.getJobId();
88        }
89
90        public AllocationStatus getStatus() {
91                return t.getStatus();
92        }
93       
94        public String getStatusDescription(){
95                return t.getStatusDescription();
96        }
97
98        public String getTaskId() {
99                return t.getTaskId();
100        }
101
102        public int getTopology() {
103                return t.getTopology();
104        }
105
106        public boolean hasTopology() {
107                return t.hasTopology();
108        }
109
110        public void removeAllAllocation() {
111                t.removeAllAllocation();
112        }
113
114        public <Allocation_> boolean removeAllocation(
115                        AllocationInterface<Allocation_> allocation) {
116                return t.removeAllocation((org.qcg.broker.schemas.schedulingplan.Allocation) allocation.getDescription());
117        }
118
119        @SuppressWarnings("unchecked")
120        public AllocationInterface<org.qcg.broker.schemas.schedulingplan.Allocation> removeAllocationAt(int index) {
121                return new schedframe.scheduling.plan.impl.Allocation(t.removeAllocationAt(index));
122        }
123
124        public <Allocation_> void setAllocation(int index,
125                        AllocationInterface<Allocation_> allocation)
126                        throws IndexOutOfBoundsException {
127                t.setAllocation(index, (org.qcg.broker.schemas.schedulingplan.Allocation)allocation.getDescription());
128                allocationList.set(index, allocation);
129        }
130
131        public <Allocation_> void setAllocation(
132                        AllocationInterface<Allocation_>[] allocationArray) {
133                if(allocationArray == null) return;
134               
135                org.qcg.broker.schemas.schedulingplan.Allocation tab[] = new org.qcg.broker.schemas.schedulingplan.Allocation[allocationArray.length];
136                for(int i = 0; i < allocationArray.length; i++){
137                        tab[i] = (org.qcg.broker.schemas.schedulingplan.Allocation)allocationArray[i].getDescription();
138                }
139                t.setAllocation(tab);
140        }
141
142        public void setJobId(String jobId) {
143                t.setJobId(jobId);
144        }
145
146        public void setStatus(AllocationStatus status) {
147                t.setStatus(status);
148        }
149
150        public void setStatusDescription(String statusDescription){
151                t.setStatusDescription(statusDescription);
152        }
153       
154        public void setTaskId(String taskId) {
155                t.setTaskId(taskId);
156        }
157
158        public void setTopology(int topology) {
159                t.setTopology(topology);
160        }
161
162        @SuppressWarnings("unchecked")
163        public ScheduledTimeInterface<org.qcg.broker.schemas.schedulingplan.ScheduledTime> getScheduledTime() {
164                org.qcg.broker.schemas.schedulingplan.ScheduledTime time = t.getScheduledTime();
165                if(time == null)
166                        return null;
167               
168                ScheduledTime st = new ScheduledTime(time);
169                return st;
170        }
171
172        public <ScheduledTime_> void setScheduledTime(
173                        ScheduledTimeInterface<ScheduledTime_> scheduledTime) {
174                t.setScheduledTime((org.qcg.broker.schemas.schedulingplan.ScheduledTime) scheduledTime.getDescription());
175        }
176       
177
178        protected TaskInterface<?> task;
179        protected ArrayList<AllocationInterface<?>> allocationList;
180
181        public ScheduledTask(TaskInterface<?> task){
182                this();
183                this.task = task;
184        }
185
186        public ArrayList<AllocationInterface<?>> getAllocations() {
187                return this.allocationList;
188        }
189       
190        public TaskInterface<?> getTask(){
191                return this.task;
192        }
193}
Note: See TracBrowser for help on using the repository browser.