KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > examples > example12 > SimpleJob


1 /*
2  * Copyright 2005 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  *
16  */

17
18 package org.quartz.examples.example12;
19
20 import java.util.Date JavaDoc;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.quartz.Job;
25 import org.quartz.JobExecutionContext;
26 import org.quartz.JobExecutionException;
27
28 /**
29  * <p>
30  * A dumb implementation of Job, for unittesting purposes.
31  * </p>
32  *
33  * @author James House
34  */

35 public class SimpleJob implements Job {
36
37     public static final String JavaDoc MESSAGE = "msg";
38
39     private static Log _log = LogFactory.getLog(SimpleJob.class);
40
41     /**
42      * Quartz requires a public empty constructor so that the
43      * scheduler can instantiate the class whenever it needs.
44      */

45     public SimpleJob() {
46     }
47
48     /**
49      * <p>
50      * Called by the <code>{@link org.quartz.Scheduler}</code> when a
51      * <code>{@link org.quartz.Trigger}</code> fires that is associated with
52      * the <code>Job</code>.
53      * </p>
54      *
55      * @throws JobExecutionException
56      * if there is an exception while executing the job.
57      */

58     public void execute(JobExecutionContext context)
59         throws JobExecutionException {
60
61         // This job simply prints out its job name and the
62
// date and time that it is running
63
String JavaDoc jobName = context.getJobDetail().getFullName();
64
65         String JavaDoc message = (String JavaDoc) context.
66             getJobDetail().getJobDataMap().get(MESSAGE);
67
68         _log.info("SimpleJob: " + jobName + " executing at " + new Date JavaDoc());
69         _log.info("SimpleJob: msg: " + message);
70     }
71
72     
73
74 }
Popular Tags