KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > examples > example5 > MisfireJob


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.example5;
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.StatefulJob;
25 import org.quartz.JobDataMap;
26 import org.quartz.JobExecutionContext;
27 import org.quartz.JobExecutionException;
28
29 /**
30  * <p>
31  * A dumb implementation of Job, for unittesting purposes.
32  * </p>
33  *
34  * @author James House
35  */

36 public class MisfireJob implements StatefulJob {
37
38     // Logging
39
private static Log _log = LogFactory.getLog(MisfireJob.class);
40
41     // Constants
42
public static final String JavaDoc NUM_EXECUTIONS = "NumExecutions";
43     public static final String JavaDoc EXECUTION_DELAY = "ExecutionDelay";
44
45     /**
46      * Empty public constructor for job initilization
47      */

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

60     public void execute(JobExecutionContext context)
61         throws JobExecutionException {
62         String JavaDoc jobName = context.getJobDetail().getFullName();
63         _log.info("---" + jobName + " executing at " + new Date JavaDoc());
64
65         // default delay to five seconds
66
long delay = 5000L;
67
68         // use the delay passed in as a job parameter (if it exists)
69
JobDataMap map = context.getJobDetail().getJobDataMap();
70         if (map.containsKey(EXECUTION_DELAY)) {
71             delay = map.getLong(EXECUTION_DELAY);
72         }
73
74         try {
75             Thread.sleep(delay);
76         } catch (Exception JavaDoc ignore) {
77         }
78
79         _log.info("---" + jobName + " completed at " + new Date JavaDoc());
80     }
81
82 }
Popular Tags