KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > scheduler > FixedDelayTask


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.services.scheduler;
19
20 import java.util.Timer JavaDoc;
21
22 import org.sape.carbon.core.config.InvalidConfigurationException;
23
24 import org.sape.carbon.services.threadpool.ThreadPool;
25
26 /**
27  * Utility class used to interperet FixedDelayTaskConfiguration and
28  * schedule fixed delay tasks.
29  *
30  * Copyright 2002 Sapient
31  * @since carbon 1.0
32  * @author Douglas Voet, June 2002
33  * @version $Revision: 1.13 $($Author: dvoet $ / $Date: 2003/11/20 21:46:15 $)
34  */

35 class FixedDelayTask extends AbstractTask {
36     /** Holds the period of how often the task will execute. */
37     private long period;
38
39     /** Holds the initial delay before the tasks execute. */
40     private long delay;
41
42     /**
43      * Loads and validates configuration information.
44      * @param taskConfiguration configuration for this task
45      */

46     protected FixedDelayTask(
47         FixedDelayTaskConfiguration taskConfiguration,
48         ThreadPool threadPool) {
49             
50         super(taskConfiguration, threadPool);
51
52         this.period = taskConfiguration.getPeriod();
53         this.delay = taskConfiguration.getInitialDelay();
54
55         if (this.period < 0) {
56             throw new InvalidConfigurationException(
57                 this.getClass(),
58                 taskConfiguration.getConfigurationName(),
59                 "Period",
60                 "Period cannot be less than 0");
61         }
62         if (this.delay < 0) {
63             throw new InvalidConfigurationException(
64                 this.getClass(),
65                 taskConfiguration.getConfigurationName(),
66                 "Delay",
67                 "Delay cannot be less than 0");
68         }
69     }
70     
71     /**
72      * @see AbstractTask#schedule(Timer)
73      */

74     public void schedule(Timer JavaDoc timer) {
75         timer.schedule(getTask(), this.delay, this.period);
76     }
77 }
78
79
80
Popular Tags