KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > util > scheduler > ServiceEntry


1 package de.webman.util.scheduler;
2
3 import java.util.Date JavaDoc;
4 import org.apache.log4j.Category;
5
6 /**
7  * The root of all service entry types used by the scheduler system (see
8  * {@link de.webman.util.scheduler.SchedulerMgr} for details).
9  *
10  * @author <a HREF="mailto:gregor@webman.de">Gregor Klinke</a>
11  * @version $Revision: 1.2 $
12  **/

13 public abstract class ServiceEntry
14 {
15     /* $Id: ServiceEntry.java,v 1.2 2002/04/12 12:45:53 gregor Exp $ */
16     /**
17      * logging facility
18      **/

19     private static Category cat = Category.getInstance(ServiceEntry.class);
20
21     /**
22      * the service's id
23      **/

24     String JavaDoc id = null;
25
26     /**
27      * The start date
28      **/

29     Date JavaDoc start_at = null;
30
31     /**
32      * The stop date
33      **/

34     Date JavaDoc stop_at = null;
35
36     /**
37      * the run frequency
38      **/

39     long frequency = 0;
40
41     /**
42      * the start off delay
43      **/

44     long delay = 0;
45
46     /**
47      * The scheduler service to use
48      **/

49     SchedulerServiceFactory factory = null;
50
51     /**
52      * last check time
53      **/

54     long last = 0;
55
56     /**
57      * initializes the fields.
58      * @param _id the service id
59      * @param _start_at the start point
60      * @param _stop_at the stop point
61      * @param _frequency the frequency
62      * @param _delay the start off delay
63      * @param _factory the factory for the service */

64     protected void init(String JavaDoc _id,
65                         Date JavaDoc _start_at,
66                         Date JavaDoc _stop_at,
67                         long _frequency, long _delay,
68                         SchedulerServiceFactory _factory)
69     {
70         id = _id;
71         start_at = _start_at;
72         stop_at = _stop_at;
73         frequency = _frequency;
74         delay = _delay;
75         factory = _factory;
76         last = 0;
77     }
78
79
80     /**
81      * returns <code>true</code> if the service is due to be executed
82      **/

83     abstract boolean isDue(Date JavaDoc ref);
84
85     /**
86      * starts a service, by allocating a new service instance and starting
87      * it of in a new thread ({@link
88      * de.webman.util.scheduler.ServiceThread})
89      **/

90     void executeNewService() {
91         execute();
92     }
93
94     /**
95      * returns <code>true</code> if this service is outdated
96      **/

97     abstract boolean isOutdated(Date JavaDoc ref);
98     
99     protected void execute() {
100         /* and off it goes! */
101         try {
102             new Thread JavaDoc(new ServiceThread(id, factory.newService())).start();
103         }
104         catch (SchedulerException se) {
105             cat.error("starting scheduler exception: '" + id + "' (" + se + ")");
106         }
107     }
108
109 }
110
Popular Tags