KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > crontab > SampleCronJob


1
2 /*
3
4 This software is OSI Certified Open Source Software.
5 OSI Certified is a certification mark of the Open Source Initiative.
6
7 The license (Mozilla version 1.0) can be read at the MMBase site.
8 See http://www.MMBase.org/license
9
10 */

11 package org.mmbase.applications.crontab;
12
13 import org.mmbase.bridge.*;
14 import org.mmbase.util.logging.*;
15 /**
16  * Sample cron jobs shows ho to create a cronjob.
17  * @author Kees Jongenburger
18  */

19 //The cronjobs is the code that will get run when a cronentry gets "kicked"
20
//you are allowed to create a cronjob by only extending from thread
21
//MyJob implements Runnable{ public void run(){}}
22
//but sometimes it beter to implement the Cronjob interface in order to get additional information
23
//the AbstractCronJob helps to implement the Cronjob interface
24
public class SampleCronJob extends AbstractCronJob implements CronJob {
25     
26     private static Logger log = Logging.getLoggerInstance(SampleCronJob.class);
27
28     public SampleCronJob() {
29         log.info("The constructor of a cronjob is only called once");
30     }
31
32     public void run() {
33         log.info("The job has been started by the cronEntry" + cronEntry);
34         log.info("the entry has this configuration " + cronEntry.getConfiguration());
35         log.info("the entry has this id " + cronEntry.getId());
36         
37         //when running jobs you often need a cloud object.
38
//the best way to get it is using class security
39
Cloud cloud = ContextProvider.getDefaultCloudContext().getCloud("mmbase", "class", null); // testing Class Security
40
//Cloud cloud = ContextProvider.getDefaultCloudContext().getCloud("mmbase", "anonymous", null);
41
log.info("found cloud " + cloud.getUser().getIdentifier() + "/" + cloud.getUser().getRank());
42         log.info("The job has stopped");
43         //cronEntry;
44
}
45 }
46
Popular Tags