KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > jobs > job > RunJob


1 package org.oddjob.jobs.job;
2
3 import org.oddjob.framework.SimpleJob;
4 import org.oddjob.util.OddjobConfigException;
5
6 /**
7  * @oddjob.description A job which runs another job. The other job can be
8  * local or or on a server.
9  * <p>
10  * This jobs completion state will reflect the success of the run
11  * operation, not the state of job being run.
12  * <p>
13  *
14  * @oddjob.example
15  *
16  * If 'sales' is the id of a {@link org.oddjob.jmx.JMXClientJob}, then
17  * this would run the job fred on the corresponding server.
18  *
19  * <pre>
20  * &lt;run job="${sales.lookup(fred)}"/&gt;
21  * </pre>
22  *
23  * @author Rob Gordon
24  */

25
26 public class RunJob extends SimpleJob {
27     private static final long serialVersionUID = 20050806;
28
29     /**
30      * @oddjob.property
31      * @oddjob.description Job to run
32      * @oddjob.required Yes.
33      */

34     private transient Runnable JavaDoc job;
35
36     /**
37      * Set the stop node directly.
38      *
39      * @param node The job.
40      */

41     synchronized public void setJob(Runnable JavaDoc node) {
42         this.job = node;
43     }
44
45     /**
46      * Get the job.
47      *
48      * @return The node.
49      */

50     synchronized public Runnable JavaDoc getJob() {
51         return this.job;
52     }
53
54     /*
55      * (non-Javadoc)
56      * @see org.oddjob.jobs.AbstractJob#execute()
57      */

58     protected int execute() throws Exception JavaDoc {
59         if (job == null) {
60             throw new OddjobConfigException("A job to start must be provided.");
61         }
62         job.run();
63         return 0;
64     }
65     
66 }
67
Popular Tags