KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > scheduling > UnscheduleJob


1 package org.oddjob.scheduling;
2
3 import org.oddjob.arooa.ArooaHandler;
4 import org.oddjob.arooa.ArooaContext;
5 import org.oddjob.framework.SimpleJob;
6 import org.oddjob.util.OddjobConfigException;
7
8 /**
9  * @oddjob.description Remove a schedule from a scheduler.
10  *
11  * @oddjob.example
12  *
13  *<pre>
14  * &lt;sequential name="A Job That Unschedules Itself"&gt;
15  * &lt;scheduler id="myscheduler" name="My Scheduler"&gt;
16  * &lt;schedules&gt;
17  * &lt;ojschedule id="myschedule" name="My Schedule" job="${useful}"&gt;
18  * &lt;schedule&gt;
19  * &lt;now/&gt;
20  * &lt;/schedule&gt;
21  * &lt;/ojschedule&gt;
22  * &lt;/schedules&gt;
23  * &lt;/scheduler&gt;
24  * &lt;folder&gt;
25  * &lt;sequential id="useful"&gt;
26  * &lt;echo text="This could do something useful."/&gt;
27  * &lt;unschedule scheduler="${myscheduler}" scheduleId="myschedule"/&gt;
28  * &lt;/sequential&gt;
29  * &lt;/folder&gt;
30  * &lt;/sequential&gt;
31  *</pre>
32  *
33  * @author Rob Gordon
34  */

35
36
37 public class UnscheduleJob extends SimpleJob {
38     static final long serialVersionUID = 20051121;
39
40     /**
41      * @oddjob.property
42      * @oddjob.description The id of the schedule to remove from the scheduler.
43      * @oddjob.required Yes.
44      */

45     private String JavaDoc scheduleId;
46     
47     /**
48      * @oddjob.property
49      * @oddjob.description An OddjobScheduler to remove the schedules
50      * from.
51      * @oddjob.required Yes.
52      */

53     private OddjobScheduler scheduler;
54
55     /**
56      * Set the scheduleId.
57      *
58      * @param the scheduleId.
59      */

60     public void setScheduleId(String JavaDoc scheduleId) {
61         this.scheduleId = scheduleId;
62     }
63     
64     /**
65      * Get the scheduleId.
66      *
67      * @return The scheduleId.
68      */

69     public String JavaDoc getScheduleId() {
70         return scheduleId;
71     }
72     
73     /**
74      * Handler for &lt;schedules&gt;.
75      *
76      * @param arooaContext The context;
77      * @return The handler.
78      */

79     public ArooaHandler handlerForSchedules(ArooaContext arooaContext) {
80         return ScheduleInstructionFactory.handlerFor(arooaContext);
81     }
82     
83     /*
84      * (non-Javadoc)
85      * @see org.oddjob.framework.SimpleJob#execute()
86      */

87     protected int execute() throws Exception JavaDoc {
88         if (scheduler == null) {
89             throw new OddjobConfigException("No scheduler specified.");
90         }
91         if (scheduleId == null) {
92             throw new OddjobConfigException("Nothing to unschedule.");
93         }
94         scheduler.unSchedule(scheduleId);
95         return 0;
96     }
97     
98     /**
99      * @return Returns the scheduler.
100      */

101     public OddjobScheduler getScheduler() {
102         return scheduler;
103     }
104     /**
105      * @param scheduler The scheduler to set.
106      */

107     public void setScheduler(OddjobScheduler scheduler) {
108         this.scheduler = scheduler;
109     }
110 }
111
112
Popular Tags