Expresso 5-6

com.jcorporate.expresso.core.utility
Class JobHandler

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.jcorporate.expresso.core.registry.ExpressoThread
          extended bycom.jcorporate.expresso.core.utility.JobHandler
All Implemented Interfaces:
Runnable

public class JobHandler
extends com.jcorporate.expresso.core.registry.ExpressoThread

The JobHandler is an object which runs constantly on the server side, looking periodically in a job queue for work to do. If it finds work to do, it spawns a new server object as specified in the queue. It may either wait for that object to complete or spawn it as a seperate thread, depending on setup options for the object being spawned

Author:
Michael Nash

Field Summary
protected static org.apache.log4j.Logger log
          The log4j Logger
protected  Crontab m_cronMgr
          The crontab for this job handler
protected  String m_jobHandlerStatus
          Current handler status
protected  long m_serverID
          The server id
protected  boolean running
          Status flag for if the server is running
protected static Vector serverList
          The list of JobHandler servers
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
JobHandler(String dbName)
          Constructor
 
Method Summary
 Crontab getCronManager()
          Retrieve the crontab for this job handler.
 long getID()
          Retrieve the server id
 Vector getServerList()
          Return a list of current Job objects
 String getStatus()
          Useful for determining current state from the outside.
static void main(String[] args)
          Main method so that JobHandler can be launched from a command line
 void registerJobHandler()
          Register JobHandler in the DataBase.
protected  void resetCurrentJobs()
          Marks all current running jobs as "Available"
static void resetQ(String dbName)
          Resets any 'running' jobs on startup to available.
 void run()
          Main thread process of the JobHandler process
 void setDataContext(String newDBName)
          Sets the Job Handler's data context
 void setID(long num)
          Sets the Job Handler Id
 void shutDown()
          mark thread for shutdown and interrupt
 
Methods inherited from class com.jcorporate.expresso.core.registry.ExpressoThread
getThreadContext
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serverList

protected static Vector serverList
The list of JobHandler servers


log

protected static final org.apache.log4j.Logger log
The log4j Logger


m_cronMgr

protected Crontab m_cronMgr
The crontab for this job handler


m_jobHandlerStatus

protected String m_jobHandlerStatus
Current handler status


running

protected boolean running
Status flag for if the server is running


m_serverID

protected long m_serverID
The server id

Constructor Detail

JobHandler

public JobHandler(String dbName)
           throws DBException,
                  ServerException
Constructor

Parameters:
dbName - The data context for this job handler to run in.
Throws:
DBException - If the database cannot be contacted
ServerException - If another uncaught exception occurs
Method Detail

setDataContext

public void setDataContext(String newDBName)
Sets the Job Handler's data context

Parameters:
newDBName - The new data context name

setID

public void setID(long num)
Sets the Job Handler Id

Parameters:
num - long integer.

getID

public long getID()
Retrieve the server id

Returns:
The Job Handler Server ID Number

getCronManager

public Crontab getCronManager()
Retrieve the crontab for this job handler. Excessive use of this function may not be threadsafe. Use only for necessary management of the cron handler and sychronize all modification acccess against the instance.

Returns:
Crontab instance.

getServerList

public Vector getServerList()
                     throws ServerException
Return a list of current Job objects

Returns:
Vector A list of the currently executing jobs
Throws:
ServerException - If the list cannot be obtained

main

public static void main(String[] args)
Main method so that JobHandler can be launched from a command line

Parameters:
args - Command line arguments to supply the information to connect to the database

resetQ

public static void resetQ(String dbName)
                   throws DBException
Resets any 'running' jobs on startup to available.

Parameters:
dbName - The data context to reset.
Throws:
DBException - upon error updating the appropriate fields

getStatus

public String getStatus()
Useful for determining current state from the outside. Not thread safe! Use it for debug purposes only, don't actually base decisions to start or stop the job handler based upon this.

Returns:
the current status code of the JobHandler.

registerJobHandler

public void registerJobHandler()
Register JobHandler in the DataBase.


run

public void run()
Main thread process of the JobHandler process


shutDown

public void shutDown()
mark thread for shutdown and interrupt


resetCurrentJobs

protected void resetCurrentJobs()
                         throws DBException
Marks all current running jobs as "Available"

Throws:
DBException - upon data access error

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.