Expresso 5-5-0

com.jcorporate.expresso.core.job
Class Job

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.jcorporate.expresso.core.job.Job
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ClearOldValidation, ControllerJob, SendNotice, TestJob, ValidationJob

public abstract class Job
extends Thread

A Job is an asynchronous task who's results will generally be emailed to the user initiating the job. Jobs themselves are executed by JobHandler, and are also capable of getting queued in such a way as to repeatedly execute.

Since:
Expresso 1.0
Author:
Michael Nash
See Also:
JobHandler

Field Summary
static String IS_NOTIFY_ON_JOB_SUCCESS
           
protected static org.apache.log4j.Logger log
          The log4j Logger
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Job()
          Default Constructor
 
Method Summary
protected  void addFunction(String name, String descrip)
          If a job can do more than one distinct function, it registers those functions so that the administration controller can tell the user about them.
protected  void addParameter(String paramCode, String paramDescrip)
          Add a parameter
 void addParamValidValues(String paramCode, Vector paramValidValues)
          Adds a list of valid values for the particular parmeters.
protected  void finish(String msg)
          Finish up the Job, clearing the job queue entry, sending a completion email, flush the queues, etc
protected  void finish(String msg, Throwable t)
          Finish up the Job, clearing the job queue entry, sending a completion email, flush the queues, etc
 CrontabEntry getCronAlarmEntry()
          Retrieve the cron alarm entry
protected  String getDataContext()
          Retrieve the data context of the job
protected  String getDBName()
          Deprecated. since Expresso 5.3 use getDataContext() instead
 Hashtable getFunctions()
          Retrieve the functions the Job Handler can execute
 String getJobNumber()
          Return the jobnumber of this job
protected  String getJobParameter(String paramCode)
          Convenience method to get the job parameters one by one as needed.
protected  List getJobParameterList()
          Returns a List of the parameters given to the job
protected  Vector getJobParameters()
          Deprecated. Use either getJobParametersList or getJobParameter
 JobQueue getJobQueueEntry()
          Return the job queue entry that caused this job to begin
 String getParameter(String paramName)
          Deprecated. use getParameterDescription
 String getParameterDescription(String paramName)
          Get the value of a specified parameter
 Hashtable getParameterNamesAndDescriptions()
          Retreive all parameters
 Hashtable getParameters()
          Deprecated. use getParameterNamesAndDescriptions
 Vector getParamValidValues(String paramCode)
          Retrieve all valid values for the given parameter
protected  String getSchema(String schemaClass)
          Instantiate & return the schema class given in the current parameter BUG BUG: This function isn't right, what was the intention: -MR
protected  String getString(String stringCode)
          Getstring without any substitution capabilities
protected  String getString(String stringCode, Object[] args)
          Pass on a call to retrieve an appropriate localized string from the correct Schema object.
protected  String getString(String stringCode, String arg1)
          Internationalization methods.
protected  String getString(String stringCode, String arg1, String arg2)
          Internationalization methods.
protected  String getString(String stringCode, String arg1, String arg2, String arg3)
          Internationalization methods.
protected  String getString(String stringCode, String arg1, String arg2, String arg3, String arg4)
          Internationalization methods.
 String getTitle()
          Retrieve the title of the job.
 String getUser()
          Return the username who requested this job
protected  boolean hasParameters()
          Does this job have parameters?
static Job instantiate(String className)
          Convenience method to create a Job from it's name
 boolean multiThreaded()
          Implementors of this class must override this to return true if they are multi-threaded, e.g. can be run at the same time as other jobs.
 void run()
          Implement the actual logic for this server object
protected  void sendMail(String subject, String myRecipients, Vector mailMessage)
          Send an e-mail message to a list of recipients
 void setCronAlarmEntry(CrontabEntry obj)
          Sets the cron alarm entry
 void setQueue(JobQueue newJobQueue)
          Set the JobQueue object that created this job.
protected  void setSchema(String schemaClass)
          Tell this Job object what Schema it belongs to.
 void setUseCron(boolean useCron)
          If a job will be executed in cron process - say it
 boolean useCron()
          Should we use Crontab?
 
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

log

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


IS_NOTIFY_ON_JOB_SUCCESS

public static final String IS_NOTIFY_ON_JOB_SUCCESS
See Also:
Constant Field Values
Constructor Detail

Job

public Job()
Default Constructor

Method Detail

addFunction

protected void addFunction(String name,
                           String descrip)
If a job can do more than one distinct function, it registers those functions so that the administration controller can tell the user about them.

Parameters:
name - the name of the function
descrip - the function description

setUseCron

public void setUseCron(boolean useCron)
If a job will be executed in cron process - say it

Parameters:
useCron - true if this job will be executed in cron process

setCronAlarmEntry

public void setCronAlarmEntry(CrontabEntry obj)
Sets the cron alarm entry

Parameters:
obj - the cron alarm entry

getCronAlarmEntry

public CrontabEntry getCronAlarmEntry()
Retrieve the cron alarm entry

Returns:
Object

useCron

public boolean useCron()
Should we use Crontab?

Returns:
true if set

addParameter

protected void addParameter(String paramCode,
                            String paramDescrip)
Add a parameter

Parameters:
paramCode - the actual parameter code, similar to the parameter code for a controller.
paramDescrip - The "user friendly" name of the description.

addParamValidValues

public void addParamValidValues(String paramCode,
                                Vector paramValidValues)
Adds a list of valid values for the particular parmeters. Will be automatically be picked up by the controller that generically launches any jobs.

Parameters:
paramCode - the parameter code
paramValidValues - Vector of valid value objects

finish

protected void finish(String msg)
Finish up the Job, clearing the job queue entry, sending a completion email, flush the queues, etc

Parameters:
msg - the message to send to the queuing user

finish

protected void finish(String msg,
                      Throwable t)
Finish up the Job, clearing the job queue entry, sending a completion email, flush the queues, etc

Parameters:
msg - the message to send to the queuing user
t - The Exception to log in the message

getFunctions

public Hashtable getFunctions()
Retrieve the functions the Job Handler can execute

Returns:
Hashtable

getJobNumber

public String getJobNumber()
Return the jobnumber of this job

Returns:
String

getJobQueueEntry

public JobQueue getJobQueueEntry()
                          throws DBException
Return the job queue entry that caused this job to begin

Returns:
JobQueue A JobQueue object
Throws:
DBException - If the object cannot be returned

getParameters

public Hashtable getParameters()
Deprecated. use getParameterNamesAndDescriptions

Retreive all parameter names

Returns:
hashtable of parameters

getParameter

public String getParameter(String paramName)
Deprecated. use getParameterDescription

Get the description of a specified parameter

Parameters:
paramName - the parameter name
Returns:
java.lang.String the parameter value or null

getParameterNamesAndDescriptions

public Hashtable getParameterNamesAndDescriptions()
Retreive all parameters

Returns:
hashtable of parameters

getParameterDescription

public String getParameterDescription(String paramName)
Get the value of a specified parameter

Parameters:
paramName - the parameter name
Returns:
java.lang.String the parameter value or null

getParamValidValues

public Vector getParamValidValues(String paramCode)
Retrieve all valid values for the given parameter

Parameters:
paramCode - the parameter name
Returns:
a vector of valid value objects

getTitle

public String getTitle()
Retrieve the title of the job. Override in your own job for a descriptive entry

Returns:
java.lang.String

getUser

public String getUser()
Return the username who requested this job

Returns:
String

multiThreaded

public boolean multiThreaded()
Implementors of this class must override this to return true if they are multi-threaded, e.g. can be run at the same time as other jobs.

Returns:
boolean True if this job can be run in parallel with other jobs

run

public void run()
Implement the actual logic for this server object


sendMail

protected void sendMail(String subject,
                        String myRecipients,
                        Vector mailMessage)
Send an e-mail message to a list of recipients

Parameters:
subject - Subject of the message
myRecipients - Recipients of the message
mailMessage - Contents of the message, as strings in a vector

setQueue

public void setQueue(JobQueue newJobQueue)
Set the JobQueue object that created this job. Called by the server when the job is launched, so we have this information available.

Parameters:
newJobQueue - JobQueue object that triggered this job

getDBName

protected String getDBName()
                    throws DBException
Deprecated. since Expresso 5.3 use getDataContext() instead

Retrieve the data context of the job

Returns:
java.lang.String
Throws:
DBException

getDataContext

protected String getDataContext()
                         throws DBException
Retrieve the data context of the job

Returns:
java.lang.String
Throws:
DBException

setSchema

protected void setSchema(String schemaClass)
Tell this Job object what Schema it belongs to. This is used when the Job tries to use it's "getString(String, Object[])" method to prepare internationalized messages - it passes the call along to the appropriate schema which knows how to locate the proper message file.

Parameters:
schemaClass - the schema class name

getString

protected String getString(String stringCode)
Getstring without any substitution capabilities

Parameters:
stringCode -
Returns:
See Also:
Messages.getString(java.lang.String, java.util.Locale, java.lang.String, java.lang.Object[])

getString

protected String getString(String stringCode,
                           String arg1)
Internationalization methods.

Parameters:
stringCode - the string code to look up in the messages bundle
arg1 - Formatting argument
Returns:
java.lang.String the expanded value
Throws:
IllegalArgumentException - if the stringCode cannot be found in the schema's message bundle.
See Also:
Messages.getString(java.lang.String, java.util.Locale, java.lang.String, java.lang.Object[])

getString

protected String getString(String stringCode,
                           String arg1,
                           String arg2)
Internationalization methods.

Parameters:
stringCode - the string code to look up in the messages bundle
arg1 - Formatting argument
arg2 - Formatting argument
Returns:
java.lang.String the expanded value
Throws:
IllegalArgumentException - if the stringCode cannot be found in the schema's message bundle.
See Also:
Messages.getString(java.lang.String, java.util.Locale, java.lang.String, java.lang.Object[])

getString

protected String getString(String stringCode,
                           String arg1,
                           String arg2,
                           String arg3)
Internationalization methods.

Parameters:
stringCode - the string code to look up in the messages bundle
arg1 - Formatting argument
arg2 - Formatting argument
arg3 - Formatting argument
Returns:
java.lang.String the expanded value
Throws:
IllegalArgumentException - if the stringCode cannot be found in the schema's message bundle.
See Also:
Messages.getString(java.lang.String, java.util.Locale, java.lang.String, java.lang.Object[])

getString

protected String getString(String stringCode,
                           String arg1,
                           String arg2,
                           String arg3,
                           String arg4)
Internationalization methods.

Parameters:
stringCode - the string code to look up in the messages bundle
arg1 - Formatting argument
arg2 - Formatting argument
arg3 - Formatting argument
arg4 - Formatting argument
Returns:
java.lang.String the expanded value
Throws:
IllegalArgumentException - if the stringCode cannot be found in the schema's message bundle.
See Also:
Messages.getString(java.lang.String, java.util.Locale, java.lang.String, java.lang.Object[])

getString

protected String getString(String stringCode,
                           Object[] args)
Pass on a call to retrieve an appropriate localized string from the correct Schema object. This is a convenience method that can be used within Job objects to save having to build a long call to the static methods in the Messages object.

Parameters:
stringCode - the string code to look up in the messages bundle
args - the formatting object array
Returns:
java.lang.String the expanded value
Throws:
IllegalArgumentException - if the stringCode cannot be found in the schema's message bundle.

hasParameters

protected boolean hasParameters()
                         throws DBException
Does this job have parameters?

Returns:
true if it does.
Throws:
DBException - upon error

getJobParameters

protected Vector getJobParameters()
                           throws DBException
Deprecated. Use either getJobParametersList or getJobParameter

Returns a Vector of the parameters given to the job

Returns:
A Vector of the parameters or null if there are no parameters for the job.
Throws:
DBException - upon error

getJobParameterList

protected List getJobParameterList()
                            throws DBException
Returns a List of the parameters given to the job

Returns:
A List of the parameters or null if there are no parameters for the job.
Throws:
DBException - upon error

getJobParameter

protected String getJobParameter(String paramCode)
                          throws DBException
Convenience method to get the job parameters one by one as needed.

Parameters:
paramCode - to retrieve.
Returns:
The string of the param value, or null if no such named parameter exists.
Throws:
DBException - if there's an error reading the values.

getSchema

protected String getSchema(String schemaClass)
                    throws ServerException
Instantiate & return the schema class given in the current parameter BUG BUG: This function isn't right, what was the intention: -MR

Parameters:
schemaClass - the schema class to set
Returns:
A Schema object instantiated from the class named by the 'SchemaClass' parameter
Throws:
ServerException

instantiate

public static Job instantiate(String className)
                       throws ServerException
Convenience method to create a Job from it's name

Parameters:
className - the classname to instantiate
Returns:
an instantiated Job
Throws:
ServerException - upon instantiation error

Expresso 5-5-0

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