/* Copyright 1999-2008 Acelet.org. All rights reserved. GPL v2 license */
/** @author Wei Jiang */
package com.acelet.s.watchdog;
import java.io.*;
import java.sql.*;
import java.util.*;
import com.acelet.lib.LogAgent;
import com.acelet.lib.Phrase;
import com.acelet.s.chore.Chore;
import com.acelet.s.chore.ChoreProcess;
/**
* Copyright Acelet Corp. 2001 - 2003. All rights reserved
* <p>
* The <code>WatchdogControl</code> is a utility class for SuperWatchdog.
* It is used for control watchdog
* and chores from Java program, either from EJB or other Java application.
* <br>
* The methods are very simple, powerful and less error prone.
* <br>
* @version 1.10, 2003.01.20
*/
public class WatchdogControl {
/**
* <code>STATUS_SUSPENDED</code> is an int for using as status value.
*/
public static final int STATUS_STANDBY = Chore.STATUS_STANDBY;
/**
* <code>STATUS_SUSPENDED</code> is an int for using as status value.
*/
public static final int STATUS_SUSPENDED = Chore.STATUS_SUSPENDED;
/**
* <code>VERSION</code> is the version number for this class.
*/
final String VERSION = "1.3";
ChoreProcess choreProcess;
Connection choreConnection;
/**
* Constructor for <code>WatchdogControl</code>.
* <p>
*
* @param choreConnection The connection to chore database. <br>
* @param logAgent The LogAgent.
* @see com.acelet.lib.LogAgent
* It should be set as auto-commit <br>
* @exception Exception.
*/
public WatchdogControl(LogAgent logAgent, Connection choreConnection) throws Exception{
this.choreConnection = choreConnection;
choreProcess = new ChoreProcess(choreConnection);
choreProcess.setLogAgent(logAgent);
}
/**
* <code>changeChoreStatus</code> changed the status for a chore.
* It takes effect immediately. There will be a log message
* recording the change.
* <br>
* @param choreName the name of the chore.
* @param newStatus the new status. It can be either
* <code>STATUS_STANDBY</code> or <code>STATUS_SUSPENDED</code>
* @exception Exception.
* @return the number of rows changed. It is 1, if successful, 0 otherwise.
*/
public int changeChoreStatus(String choreName, int newStatus) throws Exception {
return choreProcess.changeChoreStatus(choreName, newStatus);
}
/**
* <code>deleteChore</code> deletes the chore from chore database.
* It takes effect immediately. There will be a log message
* recording the change.
* <br>
* @param choreName the name of the chore.
* @exception Exception.
* @return the number of rows deleted. It is 1, if successful, 0 otherwise.
*/
public int deleteChore(String choreName) throws Exception {
return choreProcess.deleteChore(choreName);
}
/**
* <code>requestRunChore</code> request SuperWatchdog to run the chore.
* A Doer will take the request and run the chore.
* @param choreName the name of the chore.
* @exception Exception.
*/
public void requestRunChore(String choreName) throws Exception {
choreProcess.insertCandidateChore(choreName);
}
}