KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > examples > example9 > Job1Listener


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.example9;
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.JobDetail;
25 import org.quartz.JobExecutionContext;
26 import org.quartz.JobExecutionException;
27 import org.quartz.JobListener;
28 import org.quartz.Scheduler;
29 import org.quartz.SchedulerException;
30 import org.quartz.SimpleTrigger;
31
32 /**
33  * @author wkratzer
34  *
35  * TODO To change the template for this generated type comment go to
36  * Window - Preferences - Java - Code Style - Code Templates
37  */

38 public class Job1Listener implements JobListener {
39
40     private static Log _log = LogFactory.getLog(Job1Listener.class);
41     
42     public String JavaDoc getName() {
43         return "job1_to_job2";
44     }
45
46     public void jobToBeExecuted(JobExecutionContext inContext) {
47         _log.info("Job1Listener says: Job Is about to be executed.");
48     }
49
50     public void jobExecutionVetoed(JobExecutionContext inContext) {
51         _log.info("Job1Listener says: Job Execution was vetoed.");
52     }
53
54     public void jobWasExecuted(JobExecutionContext inContext,
55             JobExecutionException inException) {
56         _log.info("Job1Listener says: Job was executed.");
57         
58         // Simple job #2
59
JobDetail job2 =
60             new JobDetail("job2",
61                 Scheduler.DEFAULT_GROUP,
62                 SimpleJob2.class);
63         
64         // Simple trigger to fire immediately
65
SimpleTrigger trigger =
66             new SimpleTrigger("job2Trigger",
67                     Scheduler.DEFAULT_GROUP,
68                     new Date JavaDoc(),
69                     null,
70                     0,
71                     0L);
72         
73         try {
74             // schedule the job to run!
75
inContext.getScheduler().scheduleJob(job2, trigger);
76         } catch (SchedulerException e) {
77             _log.warn("Unable to schedule job2!");
78             e.printStackTrace();
79         }
80         
81     }
82
83 }
84
Popular Tags