KickJava   Java API By Example, From Geeks To Geeks.

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


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.CronTrigger;
25 import org.quartz.JobDataMap;
26 import org.quartz.JobDetail;
27 import org.quartz.Scheduler;
28 import org.quartz.SchedulerFactory;
29 import org.quartz.impl.StdSchedulerFactory;
30
31 /**
32  * This example is a client program that will remotely
33  * talk to the scheduler to schedule a job. In this
34  * example, we will need to use the JDBC Job Store. The
35  * client will connect to the JDBC Job Store remotely to
36  * schedule the job.
37  *
38  * @author James House, Bill Kratzer
39  */

40 public class RemoteClientExample {
41
42     public void run() throws Exception JavaDoc {
43
44         Log log = LogFactory.getLog(RemoteClientExample.class);
45
46         // First we must get a reference to a scheduler
47
SchedulerFactory sf = new StdSchedulerFactory();
48         Scheduler sched = sf.getScheduler();
49
50         // define the job and ask it to run
51
JobDetail job =
52             new JobDetail("remotelyAddedJob", "default", SimpleJob.class);
53         JobDataMap map = new JobDataMap();
54         map.put("msg", "Your remotely added job has executed!");
55         job.setJobDataMap(map);
56         CronTrigger trigger = new CronTrigger(
57                 "remotelyAddedTrigger", "default",
58                 "remotelyAddedJob", "default",
59                 new Date JavaDoc(),
60                 null,
61                 "/5 * * ? * *");
62
63         // schedule the job
64
sched.scheduleJob(job, trigger);
65
66         log.info("Remote job scheduled.");
67     }
68
69     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
70
71         RemoteClientExample example = new RemoteClientExample();
72         example.run();
73     }
74
75 }
Popular Tags