/*
* The contents of this file are subject to the Sapient Public License
* Version 1.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://carbon.sf.net/License.html.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is The Carbon Component Framework.
*
* The Initial Developer of the Original Code is Sapient Corporation
*
* Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
*/
package org.sape.carbon.services.scheduler;
import java.util.Timer;
import org.sape.carbon.core.config.InvalidConfigurationException;
import org.sape.carbon.services.threadpool.ThreadPool;
/**
* Utility class used to interperet FixedDelayTaskConfiguration and
* schedule fixed delay tasks.
*
* Copyright 2002 Sapient
* @since carbon 1.0
* @author Douglas Voet, June 2002
* @version $Revision: 1.13 $($Author: dvoet $ / $Date: 2003/11/20 21:46:15 $)
*/
class FixedDelayTask extends AbstractTask {
/** Holds the period of how often the task will execute. */
private long period;
/** Holds the initial delay before the tasks execute. */
private long delay;
/**
* Loads and validates configuration information.
* @param taskConfiguration configuration for this task
*/
protected FixedDelayTask(
FixedDelayTaskConfiguration taskConfiguration,
ThreadPool threadPool) {
super(taskConfiguration, threadPool);
this.period = taskConfiguration.getPeriod();
this.delay = taskConfiguration.getInitialDelay();
if (this.period < 0) {
throw new InvalidConfigurationException(
this.getClass(),
taskConfiguration.getConfigurationName(),
"Period",
"Period cannot be less than 0");
}
if (this.delay < 0) {
throw new InvalidConfigurationException(
this.getClass(),
taskConfiguration.getConfigurationName(),
"Delay",
"Delay cannot be less than 0");
}
}
/**
* @see AbstractTask#schedule(Timer)
*/
public void schedule(Timer timer) {
timer.schedule(getTask(), this.delay, this.period);
}
}
|