001: package de.webman.util.scheduler;
002:
003: import java.util.Date;
004: import org.apache.log4j.Category;
005:
006: /**
007: * The root of all service entry types used by the scheduler system (see
008: * {@link de.webman.util.scheduler.SchedulerMgr} for details).
009: *
010: * @author <a href="mailto:gregor@webman.de">Gregor Klinke</a>
011: * @version $Revision: 1.2 $
012: **/
013: public abstract class ServiceEntry {
014: /* $Id: ServiceEntry.java,v 1.2 2002/04/12 12:45:53 gregor Exp $ */
015: /**
016: * logging facility
017: **/
018: private static Category cat = Category
019: .getInstance(ServiceEntry.class);
020:
021: /**
022: * the service's id
023: **/
024: String id = null;
025:
026: /**
027: * The start date
028: **/
029: Date start_at = null;
030:
031: /**
032: * The stop date
033: **/
034: Date stop_at = null;
035:
036: /**
037: * the run frequency
038: **/
039: long frequency = 0;
040:
041: /**
042: * the start off delay
043: **/
044: long delay = 0;
045:
046: /**
047: * The scheduler service to use
048: **/
049: SchedulerServiceFactory factory = null;
050:
051: /**
052: * last check time
053: **/
054: long last = 0;
055:
056: /**
057: * initializes the fields.
058: * @param _id the service id
059: * @param _start_at the start point
060: * @param _stop_at the stop point
061: * @param _frequency the frequency
062: * @param _delay the start off delay
063: * @param _factory the factory for the service */
064: protected void init(String _id, Date _start_at, Date _stop_at,
065: long _frequency, long _delay,
066: SchedulerServiceFactory _factory) {
067: id = _id;
068: start_at = _start_at;
069: stop_at = _stop_at;
070: frequency = _frequency;
071: delay = _delay;
072: factory = _factory;
073: last = 0;
074: }
075:
076: /**
077: * returns <code>true</code> if the service is due to be executed
078: **/
079: abstract boolean isDue(Date ref);
080:
081: /**
082: * starts a service, by allocating a new service instance and starting
083: * it of in a new thread ({@link
084: * de.webman.util.scheduler.ServiceThread})
085: **/
086: void executeNewService() {
087: execute();
088: }
089:
090: /**
091: * returns <code>true</code> if this service is outdated
092: **/
093: abstract boolean isOutdated(Date ref);
094:
095: protected void execute() {
096: /* and off it goes! */
097: try {
098: new Thread(new ServiceThread(id, factory.newService()))
099: .start();
100: } catch (SchedulerException se) {
101: cat.error("starting scheduler exception: '" + id + "' ("
102: + se + ")");
103: }
104: }
105:
106: }
|