/* Copyright 1999-2008 Acelet.org. All rights reserved. GPL v2 license */
/** @author Wei Jiang */
package com.acelet.s.scheduler;
import java.io.*;
import java.sql.*;
import java.util.*;
import com.acelet.lib.LogAgent;
import com.acelet.lib.Phrase;
import com.acelet.s.task.Task;
import com.acelet.s.task.TaskProcess;
/**
* The <code>SchedulerControl</code> is a utility class for SuperScheduler.
* It is used for control schedule
* and tasks from Java program, either from EJB or other Java application.
* <br>
* The methods are very simple, powerful and less error prone.
* <br>
*/
public class SchedulerControl {
/**
* <code>STATUS_ACTIVE</code> is an int for using as status value.
*/
public static final int STATUS_ACTIVE = Task.STATUS_ACTIVE;
/**
* <code>STATUS_SUSPENDED</code> is an int for using as status value.
*/
public static final int STATUS_SUSPENDED = Task.STATUS_SUSPENDED;
/**
* <code>VERSION</code> is the version number for this class.
*/
final String VERSION = "1.3";
TaskProcess taskProcess;
Connection taskConnection;
/**
* Constructor for <code>SchedulerControl</code>.
* <p>
*
* @param taskConnection The connection to task database. <br>
* @param logAgent The LogAgent.
* @see com.acelet.lib.LogAgent
* It should be set as auto-commit <br>
* @exception Exception.
*/
public SchedulerControl(LogAgent logAgent, Connection taskConnection) throws Exception {
this.taskConnection = taskConnection;
taskProcess = new TaskProcess(taskConnection);
taskProcess.setLogAgent(logAgent);
}
/**
* <code>changeTaskStatus</code> changes the status for a Task.
* <br>
* @param taskName the name of the Task.
* @param newStatus the new status. It can be
* <code>STATUS_ACTIVE</code> or <code>STATUS_SUSPENDED</code>
* @return the number of rows changed. It is 1, if successful, 0 otherwise.
* @exception Exception.
*/
public int changeTaskStatus(String taskName, int newStatus) throws Exception {
return taskProcess.changeTaskStatus(taskName, newStatus);
}
/**
* <code>requestRunTask</code> request SuperScheduler to run the task.
* A Doer will take the request and run the task.
* @param taskName the name of the task.
* @exception Exception.
*/
public void requestRunTask(String taskName) throws Exception {
taskProcess.insertCandidateTask(taskName);
}
}