KickJava   Java API By Example, From Geeks To Geeks.

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


1 package de.webman.util.scheduler;
2
3 import java.util.Date JavaDoc;
4 import java.util.Calendar JavaDoc;
5
6 /**
7  * this service entry represents a service which is called once only at a
8  * given point in time. The service is deregistered after execution.
9  *
10  * @author <a HREF="mailto:gregor@webman.de">Gregor Klinke</a>
11  * @version $Revision: 1.2 $
12  **/

13 class OneTimeService
14     extends ServiceEntry
15 {
16     /* $Id: OneTimeService.java,v 1.2 2002/04/12 12:45:53 gregor Exp $ */
17     
18     /**
19      * if this service has been executed
20      **/

21     private boolean executed = false;
22
23     /**
24      * constructor, only to be used by the schedule manager
25      * @param _id the identification string of the service
26      * @param _start_at start the service at this point, must not be
27      * <code>null</code>
28      * @param _factory an instance of the service to execute
29      **/

30     OneTimeService(String JavaDoc _id,
31                    Date JavaDoc _start_at,
32                    SchedulerServiceFactory _factory)
33     {
34         init(_id, _start_at, null, 0, 0, _factory);
35     }
36
37
38
39     /**
40      * returns <code>true</code> if the service is due to be executed
41      * @param ref the reference date to check for
42      * @return <code>true</code> if it is due
43      **/

44     boolean isDue(Date JavaDoc ref) {
45         return ref.after(start_at);
46     }
47     
48     /**
49      * returns <code>true</code> if this service is outdated
50      * @param ref the reference date to check for
51      * @return <code>true</code> if it is outdated
52      **/

53     boolean isOutdated(Date JavaDoc ref) {
54         return executed;
55     }
56
57
58     /**
59      * starts a service, by allocating a new service instance and starting
60      * it of in a new thread ({@link
61      * de.webman.util.scheduler.ServiceThread})
62      **/

63     void executeNewService() {
64         execute();
65         executed = true;
66     }
67     
68 }
69
70
Popular Tags