[cvs] expresso/expresso-web/expresso/doc/edg edg_jobcontrol.html jobcontrol.xml

JCorporate Ltd jcorp at jcorp2.servlets.net
Wed May 12 04:08:33 PDT 2004


Update of /home/javacorp/.cvs/expresso/expresso/expresso-web/expresso/doc/edg
In directory jcorp2.servlets.net:/tmp/cvs-serv20916

Modified Files:
	edg_jobcontrol.html jobcontrol.xml 
Log Message:
fixed programlisting formatting


Index: edg_jobcontrol.html
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/expresso/doc/edg/edg_jobcontrol.html,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** edg_jobcontrol.html	10 May 2004 00:04:27 -0000	1.31
--- edg_jobcontrol.html	12 May 2004 11:08:23 -0000	1.32
***************
*** 1,4 ****
! <html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter&nbsp;26.&nbsp;Jobs Expresso</title><link href="docbook.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.62.4" name="generator"><link rel="home" href="edg_index.html" title="Expresso Developer's Guide"><link rel="up" href="edg_index.html" title="Expresso Developer's Guide"><link rel="previous" href="edg_healthcheck.html" title="Chapter&nbsp;25.&nbsp;Healthcheck Monitoring and Application Performance"><link rel="next" href="edg_reporting.html" title="Chapter&nbsp;27.&nbsp;Reporting System"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">Chapter&nbsp;26.&nbsp;Jobs Expresso</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="edg_healthcheck.html">Prev</a>&nbsp;</td><th align="center" width="60%">&nbsp;</th><td align="right" width="20%">&nbsp;<a accesskey="n" href="edg_reporting.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="jobcontrol"></a>Chapter&nbsp;26.&nbsp;Jobs Expresso</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="edg_jobcontrol.html#N12B08">Introduction</a></span></dt><dd><dl><dt><span class="sect2"><a href="edg_jobcontrol.html#N12B1E">Job Queue</a></span></dt><dt><span class="sect2"><a href="edg_jobcontrol.html#N12B23">Job Handler</a></span></dt><dt><span class="sect2"><a href="edg_jobcontrol.html#N12B2C">Job Order</a></span></dt></dl></dd><dt><span class="sect1"><a href="edg_jobcontrol.html#N12B31">Creating a job</a></span></dt><dt><span class="sect1"><a href="edg_jobcontrol.html#N12B71">Submitting A Job</a></span></dt><dt><span class="sect1"><a href="edg_jobcontrol.html#N12B9F">Job Parameters</a></span></dt><dd><dl><dt><span class="sect2"><a href="edg_jobcontrol.html#N12BA4">Defining the Job Parameters</a></span></dt><dt><span class="sect2"><a href="edg_jobcontrol.html#N12BAD">Adding parameters to a job</a></span></dt><dt><span class="sect2"><a href="edg_jobcontrol.html#N12BB8">Accessing the parameters within the Job itself</a></span></dt></dl></dd><dt><span class="sect1"><a href="edg_jobcontrol.html#N12BC1">Job Handling and Management</a></span></dt><dd><dl><dt><span class="sect2"><a href="edg_jobcontrol.html#N12BC4">Starting the
!   Job Handler</a></span></dt><dt><span class="sect2"><a href="edg_jobcontrol.html#N12BD5">Job Scheduling Features</a></span></dt></dl></dd><dt><span class="sect1"><a href="edg_jobcontrol.html#N12BE9">Cron Jobs</a></span></dt><dd><dl><dt><span class="sect2"><a href="edg_jobcontrol.html#N12BEC">Theory and Implementation</a></span></dt><dt><span class="sect2"><a href="edg_jobcontrol.html#N12C7B">Some Cron parameter examples</a></span></dt></dl></dd><dt><span class="sect1"><a href="edg_jobcontrol.html#N12C92">Conclusion</a></span></dt><dd><dl><dt><span class="sect2"><a href="edg_jobcontrol.html#N12C95">Contributors</a></span></dt></dl></dd></dl></div><p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p> If you find this EDG documentation helpful please
    consider <a href="edg_jobcontrol.html#donate_jobcontrol">DONATING</a>! to keep the doc
    alive and current. </p></div></p><p><div class="informaltable"><table width="100%" border="0"><colgroup><col align="left"><col align="right"></colgroup><tbody><tr><td align="left"><span class="bold"><b>Version:</b></span><span class="version">Expresso 5.5</span></td><td align="right"><span class="bold"><b>Maintainer:</b></span><a href="mailto:dlloyd at jgroup.net?Subject=EDG" target="_top"><span class="maintainer">David
--- 1,4 ----
! <html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter&nbsp;26.&nbsp;Jobs Expresso</title><link href="docbook.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.62.4" name="generator"><link rel="home" href="edg_index.html" title="Expresso Developer's Guide"><link rel="up" href="edg_index.html" title="Expresso Developer's Guide"><link rel="previous" href="edg_healthcheck.html" title="Chapter&nbsp;25.&nbsp;Healthcheck Monitoring and Application Performance"><link rel="next" href="edg_reporting.html" title="Chapter&nbsp;27.&nbsp;Reporting System"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">Chapter&nbsp;26.&nbsp;Jobs Expresso</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="edg_healthcheck.html">Prev</a>&nbsp;</td><th align="center" width="60%">&nbsp;</th><td align="right" width="20%">&nbsp;<a accesskey="n" href="edg_reporting.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="jobcontrol"></a>Chapter&nbsp;26.&nbsp;Jobs Expresso</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="edg_jobcontrol.html#N12AB9">Introduction</a></span></dt><dd><dl><dt><span class="sect2"><a href="edg_jobcontrol.html#N12ACF">Job Queue</a></span></dt><dt><span class="sect2"><a href="edg_jobcontrol.html#N12AD4">Job Handler</a></span></dt><dt><span class="sect2"><a href="edg_jobcontrol.html#N12ADD">Job Order</a></span></dt></dl></dd><dt><span class="sect1"><a href="edg_jobcontrol.html#N12AE2">Creating a job</a></span></dt><dt><span class="sect1"><a href="edg_jobcontrol.html#N12B22">Submitting A Job</a></span></dt><dt><span class="sect1"><a href="edg_jobcontrol.html#N12B50">Job Parameters</a></span></dt><dd><dl><dt><span class="sect2"><a href="edg_jobcontrol.html#N12B55">Defining the Job Parameters</a></span></dt><dt><span class="sect2"><a href="edg_jobcontrol.html#N12B5E">Adding parameters to a job</a></span></dt><dt><span class="sect2"><a href="edg_jobcontrol.html#N12B69">Accessing the parameters within the Job itself</a></span></dt></dl></dd><dt><span class="sect1"><a href="edg_jobcontrol.html#N12B72">Job Handling and Management</a></span></dt><dd><dl><dt><span class="sect2"><a href="edg_jobcontrol.html#N12B75">Starting the
!   Job Handler</a></span></dt><dt><span class="sect2"><a href="edg_jobcontrol.html#N12B86">Job Scheduling Features</a></span></dt></dl></dd><dt><span class="sect1"><a href="edg_jobcontrol.html#N12B9A">Cron Jobs</a></span></dt><dd><dl><dt><span class="sect2"><a href="edg_jobcontrol.html#N12B9D">Theory and Implementation</a></span></dt><dt><span class="sect2"><a href="edg_jobcontrol.html#N12C2C">Some Cron parameter examples</a></span></dt></dl></dd><dt><span class="sect1"><a href="edg_jobcontrol.html#N12C43">Conclusion</a></span></dt><dd><dl><dt><span class="sect2"><a href="edg_jobcontrol.html#N12C46">Contributors</a></span></dt></dl></dd></dl></div><p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p> If you find this EDG documentation helpful please
    consider <a href="edg_jobcontrol.html#donate_jobcontrol">DONATING</a>! to keep the doc
    alive and current. </p></div></p><p><div class="informaltable"><table width="100%" border="0"><colgroup><col align="left"><col align="right"></colgroup><tbody><tr><td align="left"><span class="bold"><b>Version:</b></span><span class="version">Expresso 5.5</span></td><td align="right"><span class="bold"><b>Maintainer:</b></span><a href="mailto:dlloyd at jgroup.net?Subject=EDG" target="_top"><span class="maintainer">David
***************
*** 7,11 ****
    according to entries in a job queue. These jobs may be run sequentially
    (single threaded) or in parallel (multi threaded), depending on the nature
!   of the job.</b></span></span></i><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12B08"></a>Introduction</h2></div></div><div></div></div><p>As a server side process, a job can
    be queued by means of a user request (by a servlet) or by means of a simple
    batch file, which can be triggered by an operating system scheduler to
--- 7,11 ----
    according to entries in a job queue. These jobs may be run sequentially
    (single threaded) or in parallel (multi threaded), depending on the nature
!   of the job.</b></span></span></i><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12AB9"></a>Introduction</h2></div></div><div></div></div><p>As a server side process, a job can
    be queued by means of a user request (by a servlet) or by means of a simple
    batch file, which can be triggered by an operating system scheduler to
***************
*** 20,28 ****
    is practical for an interactive session, such as a complex calculation, a
    data load from a legacy system, or the running of a group of long reports or
!   analyses.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12B1E"></a>Job Queue</h3></div></div><div></div></div><p>The basic mechanism
    involved is a "job queue". A job is queued by creating a new entry
    in the job queue and marking it as "available". A job can also have
    parameters associated with it to control it's functions, much like
!   arguments to a method.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12B23"></a>Job Handler</h3></div></div><div></div></div><p>There
    are one or more "job handler" objects running on the server side,
    waiting for jobs to enter the queue - when they do, a job handler picks up
--- 20,28 ----
    is practical for an interactive session, such as a complex calculation, a
    data load from a legacy system, or the running of a group of long reports or
!   analyses.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12ACF"></a>Job Queue</h3></div></div><div></div></div><p>The basic mechanism
    involved is a "job queue". A job is queued by creating a new entry
    in the job queue and marking it as "available". A job can also have
    parameters associated with it to control it's functions, much like
!   arguments to a method.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12AD4"></a>Job Handler</h3></div></div><div></div></div><p>There
    are one or more "job handler" objects running on the server side,
    waiting for jobs to enter the queue - when they do, a job handler picks up
***************
*** 43,52 ****
    processing, and sends email notifications when it is complete. This allows
    your application to request tasks that would take longer than a few moments
!   as a background job. </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12B2C"></a>Job Order</h3></div></div><div></div></div><p>Jobs
    are handled in priority order, and a job can be suspended and it's
    priority changed even once it has begun running. Certain jobs can be set to
    process at only specified times, deferring process-intensive tasks until
    off-peak hours if so desired. Jobs frequently trigger event notifications
!   when they are complete or when problems occur. </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12B31"></a>Creating a job</h2></div></div><div></div></div><p>
    <span class="inlinemediaobject"><img src="../images/edg/Jobs.png"></span> </p><p> Expresso Framework has the ability
    process tasks asynchronously. You might want to a task that takes a
--- 43,52 ----
    processing, and sends email notifications when it is complete. This allows
    your application to request tasks that would take longer than a few moments
!   as a background job. </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12ADD"></a>Job Order</h3></div></div><div></div></div><p>Jobs
    are handled in priority order, and a job can be suspended and it's
    priority changed even once it has begun running. Certain jobs can be set to
    process at only specified times, deferring process-intensive tasks until
    off-peak hours if so desired. Jobs frequently trigger event notifications
!   when they are complete or when problems occur. </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12AE2"></a>Creating a job</h2></div></div><div></div></div><p>
    <span class="inlinemediaobject"><img src="../images/edg/Jobs.png"></span> </p><p> Expresso Framework has the ability
    process tasks asynchronously. You might want to a task that takes a
***************
*** 59,73 ****
    simple job you must extend the standard class <span class="emphasis"><em>com.jcorporate.expresso.core.job.Job</em></span>
    and implement the method <span class="emphasis"><em>run</em></span>. </p><p>
!   <pre class="programlisting">package org.fooey.testapp.job; import
!   com.jcorporate.expresso.core.job.Job; import
!   com.jcorporate.expresso.services.dbobj.JobQueue; import
!   com.jcorporate.expresso.services.dbobj.JobQueueParam; public class
!   PrimeNumberSearch extends Job { public PrimeNumberSearch() { super(); } /**
!   Return a string for the security admininistration screens. */ public String
!   getTitle() { return new String("Prime Number Search"); } /** The run
!   methods should process the long running task */ public void run() { try {
!   doCalculation(); finish( "Successfully calculation in
!   database:`"+getDBName()+"'" ); } catch (Exception e) {
!   finish("Abnormal termination of calculation", e); } } }</pre>
    </p><p> The <span class="emphasis"><em>run()</em></span> should be very familiar to
    programmers who have experience of multi-thread Java applications. In fact
--- 59,92 ----
    simple job you must extend the standard class <span class="emphasis"><em>com.jcorporate.expresso.core.job.Job</em></span>
    and implement the method <span class="emphasis"><em>run</em></span>. </p><p>
!   <pre class="programlisting">
! 
! package org.fooey.testapp.job;
! 
! import com.jcorporate.expresso.core.job.Job;
! import com.jcorporate.expresso.services.dbobj.JobQueue;
! import com.jcorporate.expresso.services.dbobj.JobQueueParam; 
! 
! public class PrimeNumberSearch extends Job {
!   public PrimeNumberSearch() { 
!     super();
!   }
! 
!   /**
!     Return a string for the security admininistration screens. 
!   */
!   public String getTitle() {
!     return new String("Prime Number Search";);
!   }
!  
!   /** The run methods should process the long running task */ 
!   public void run() {
!     try {
!       doCalculation();
!       finish( "Successfully calculation in database:'"+getDBName()+"'" );
!     } catch (Exception e) {
!       finish("Abnormal termination of calculation", e);
!     }
!   }
! }</pre>
    </p><p> The <span class="emphasis"><em>run()</em></span> should be very familiar to
    programmers who have experience of multi-thread Java applications. In fact
***************
*** 87,99 ****
    Administration pages and defining a valid email address for the setup code
    <span class="emphasis"><em>MAILFrom</em></span>. For example set up the email address to
!   "yourusername at localhost". </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12B71"></a>Submitting A Job</h2></div></div><div></div></div><p> To submit a job you need to be
    familiar with <span class="emphasis"><em>JobQueue</em></span> objects. Job queue object are
!   database objects, you create them with system privileges like so. </p><p> <pre class="programlisting">JobQueue jq = new
!   JobQueue(SecuredDBObject.SYSTEM_ACCOUNT);</pre> </p><p> Once you create a job queue object you must associate it with an user
    id, the job class, and a status. </p><p>
!   <pre class="programlisting">jq.setField(JobQueue.FLD_UID, requestContext.getUid());
!   jq.setField(JobQueue.FLD_JOBCODE,
!   org.fooey.testapp.job.PrimeNumberSearch.class.getName());
!   jq.setField(JobQueue.FLD_STATUS_CODE, JobQueue.JOB_STATUS_NEW);</pre>
    </p><p> As with an DBObject you need to insert into the data store,
    so likewise with a job queue. </p><p>
--- 106,118 ----
    Administration pages and defining a valid email address for the setup code
    <span class="emphasis"><em>MAILFrom</em></span>. For example set up the email address to
!   "yourusername at localhost". </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12B22"></a>Submitting A Job</h2></div></div><div></div></div><p> To submit a job you need to be
    familiar with <span class="emphasis"><em>JobQueue</em></span> objects. Job queue object are
!   database objects, you create them with system privileges like so. </p><p> <pre class="programlisting">
! JobQueue jq = new JobQueue(SecuredDBObject.SYSTEM_ACCOUNT);</pre> </p><p> Once you create a job queue object you must associate it with an user
    id, the job class, and a status. </p><p>
!   <pre class="programlisting">
! jq.setField(JobQueue.FLD_UID, requestContext.getUid());
! jq.setField(JobQueue.FLD_JOBCODE, org.fooey.testapp.job.PrimeNumberSearch.class.getName());
! jq.setField(JobQueue.FLD_STATUS_CODE, JobQueue.JOB_STATUS_NEW);</pre>
    </p><p> As with an DBObject you need to insert into the data store,
    so likewise with a job queue. </p><p>
***************
*** 104,169 ****
    then you must set the status to <span class="emphasis"><em>JobQueue.JOB_STATUS_AV AVAILABLE</em></span>,
    then the handler will pick it up on its next scheduled loop and execute it.
!   </p><p> <pre class="programlisting">jq.setField(JobQueue.FLD_STATUS_CODE,
!   JobQueue.JOB_STATUS_AVAILABLE); jq.update();</pre> </p><p> Why have these two difference status levels? The answer is that job
    queue may have associated job queue parameters. When you create job queue
    parameter you need to already have a job queue in existence. Therefore there
!   has be intermediate state between a new creation and activation. </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12B9F"></a>Job Parameters</h2></div></div><div></div></div><p> Many jobs need parameters of
    some sort to execute. For example, the job described above, might want to
    have prime numbers calculated up to x many digits. You can use the
    parameters defined in the job to customize your job for specific tasks, and
!   to provide a means to reuse the job code with different parameters. </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12BA4"></a>Defining the Job Parameters</h3></div></div><div></div></div><p> You can define a
    job parameters in the constructor of the job if you want to be able to set
    values via the Job GUI in the admin pages, or retrieve a list of all
    possible parameter names. The first argument is the real name of the
    parameter. The second is the 'friendly' name that is displayed by
!   JobQueue UI. <pre class="programlisting">public class PrimeNumberSearch extends Job {
!   public static final DIGIT_PARAM = "digits"; public
!   PrimeNumberSearch() { // optional: this allows job and UI to know about
!   param, for setting value via UI, // or returning via
!   "getParameterNamesAndDescriptions()" addParameter(DIGIT_PARAM,
!   "Number of digits in prime to find"); } ..... }</pre>
!   </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12BAD"></a>Adding parameters to a job</h3></div></div><div></div></div><p> In the method below, we queue a job just like you would with a normal
    JobQueueEntry. But we add parameters, name/value pairs, that are associated
!   with the job. </p><p> For example: <pre class="programlisting">//Create a new
!   connection and turn off autocommit for a transaction DBConnection connection
!   = DBConnectionPool.getInstance("default").getConnection();
!   connection.setAutoCommit(false); try { // Create the jobqueue entry and add
!   it as before JobQueue jq = new JobQueue(SecuredDBObject.SYSTEM_ACCOUNT); //
!   Set the connection so it will use the same transaction system // as the
!   other dbobjects jq.setConnection(connection); jq.setField(JobQueue.FLD_UID,
!   requestContext.getUid()); jq.setField(JobQueue.FLD_JOBCODE,
!   org.fooey.testapp.job.PrimeNumberSearch.class.getName());
!   jq.setJobStatus(JobQueue.JOB_STATUS_AVAILABLE); // jq.setCronParams(-1, -1,
!   -1, -1, -1, -1); // for testing jq.setField(JobQueue.FLD_SERVERID, 0);
    jq.setField(JobQueue.FLD_STATUS_CODE, JobQueue.JOB_STATUS_NEW);
!   jq.addOrUpdate(); // // Now create a JobQueueParameter dbobject //
    JobQueueParam jobParam = new JobQueueParam(SecuredDBObject.SYSTEM_ACCOUNT);
    // Likewise set the connection so it's part of the same transaction
!   jobParam.setConnection(connection); // Set the field number based to the job
!   number that we now have from adding the job above
!   jobParam.setField(JobQueueParam.FLD_JOB_NUMBER,
!   jq.getField(JobQueue.FLD_JOBNUMBER)); // Arbitrary param number... just must
!   be unique for each parameter
!   jobParam.setField(JobQueueParam.FLD_PARAM_NUMBER,"1"); // Set the
!   parameter code in this case digits
!   jobParam.setField(JobQueueParam.FLD_PARAM_CODE,
!   PrimeNumberSearch.DIGIT_PARAM); //Set the digits parameter to 85
!   jobParam.setField(JobQueueParam.FLD_PARAM_VALUE,"85"); // Now add
!   the object and commit the entire transaction jobParam.addOrUpdate();
!   connection.commit(); } catch (DBException ex) { // Rollback the transaction
!   if we have an exception connection.rollback(); } finally { // Finally
!   release the entire database connection if (connection != null) {
!   connection.release(); } }</pre> </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12BB8"></a>Accessing the parameters within the Job itself</h3></div></div><div></div></div><p> You use
    the function getJobParameter(name) to access the actual parameters that are
!   passed to the job itself. <pre class="programlisting">public void run() { try { String
!   digitParam = (String)getJobParameter(PrimeNumberSearch.DIGIT_PARAM); if
!   (digitParam == null ) throw new IllegalArgumentException("Digits
!   parameter must be &gt; 0"); int numDigits = Integer.parseInt(
!   digitParam ); if (numDigits &lt;= 0) throw new
!   IllegalArgumentException("Digits parameter must be integer &gt;
!   0"); doCalculation(numDigits); finish( "Successfully calculation in
!   database: '"+getDBName()+"'" ); } catch (Exception e) {
!   finish("Abnormal termination of calculation", e); } }</pre>
!   </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12BC1"></a>Job Handling and Management</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12BC4"></a>Starting the
    Job Handler</h3></div></div><div></div></div><p>Normally the JobHandler is run as a separate thread
    in your application server's JVM by adding the
--- 123,221 ----
    then you must set the status to <span class="emphasis"><em>JobQueue.JOB_STATUS_AV AVAILABLE</em></span>,
    then the handler will pick it up on its next scheduled loop and execute it.
!   </p><p> <pre class="programlisting">
! jq.setField(JobQueue.FLD_STATUS_CODE, JobQueue.JOB_STATUS_AVAILABLE);
! jq.update();</pre> </p><p> Why have these two difference status levels? The answer is that job
    queue may have associated job queue parameters. When you create job queue
    parameter you need to already have a job queue in existence. Therefore there
!   has be intermediate state between a new creation and activation. </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12B50"></a>Job Parameters</h2></div></div><div></div></div><p> Many jobs need parameters of
    some sort to execute. For example, the job described above, might want to
    have prime numbers calculated up to x many digits. You can use the
    parameters defined in the job to customize your job for specific tasks, and
!   to provide a means to reuse the job code with different parameters. </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12B55"></a>Defining the Job Parameters</h3></div></div><div></div></div><p> You can define a
    job parameters in the constructor of the job if you want to be able to set
    values via the Job GUI in the admin pages, or retrieve a list of all
    possible parameter names. The first argument is the real name of the
    parameter. The second is the 'friendly' name that is displayed by
!   JobQueue UI. <pre class="programlisting">
! public class PrimeNumberSearch extends Job {
!   public static final DIGIT_PARAM = "digits";
!   public PrimeNumberSearch() { 
!     // optional: this allows job and UI to know about param, for setting value via UI,
!     // or returning via 'getParameterNamesAndDescriptions()'
!     addParameter(DIGIT_PARAM, "Number of digits in prime to find");
!   }
!   .....
! }</pre>
!   </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12B5E"></a>Adding parameters to a job</h3></div></div><div></div></div><p> In the method below, we queue a job just like you would with a normal
    JobQueueEntry. But we add parameters, name/value pairs, that are associated
!   with the job. </p><p> For example: <pre class="programlisting">
! //Create a new connection and turn off autocommit for a transaction 
! DBConnection connection = DBConnectionPool.getInstance("default").getConnection();
! connection.setAutoCommit(false); 
! try { 
!   // Create the jobqueue entry and add it as before 
!   JobQueue jq = new JobQueue(SecuredDBObject.SYSTEM_ACCOUNT);
! 
!   // Set the connection so it will use the same transaction system 
!   // as the other dbobjects 
!   jq.setConnection(connection);
!   jq.setField(JobQueue.FLD_UID, requestContext.getUid());
!   jq.setField(JobQueue.FLD_JOBCODE, org.fooey.testapp.job.PrimeNumberSearch.class.getName());
!   jq.setJobStatus(JobQueue.JOB_STATUS_AVAILABLE); 
!   // jq.setCronParams(-1, -1, -1, -1, -1, -1); 
!   // for testing jq.setField(JobQueue.FLD_SERVERID, 0);
    jq.setField(JobQueue.FLD_STATUS_CODE, JobQueue.JOB_STATUS_NEW);
!   jq.addOrUpdate(); 
! 
!   //
!   // Now create a JobQueueParameter dbobject
!   //
    JobQueueParam jobParam = new JobQueueParam(SecuredDBObject.SYSTEM_ACCOUNT);
+ 
    // Likewise set the connection so it's part of the same transaction
!   jobParam.setConnection(connection);
! 
!   // Set the field number based to the job number that we now have from adding the job above
!   jobParam.setField(JobQueueParam.FLD_JOB_NUMBER, jq.getField(JobQueue.FLD_JOBNUMBER));
! 
!   // Arbitrary param number... just must be unique for each parameter
!   jobParam.setField(JobQueueParam.FLD_PARAM_NUMBER,"1");
! 
!   // Set the parameter code in this case digits
!   jobParam.setField(JobQueueParam.FLD_PARAM_CODE, PrimeNumberSearch.DIGIT_PARAM);
! 
!   //Set the digits parameter to 85
!   jobParam.setField(JobQueueParam.FLD_PARAM_VALUE,&amp;#34;85&amp;#34;);
! 
!   // Now add the object and commit the entire transaction
!   jobParam.addOrUpdate();
! 
!   connection.commit();
! } catch (DBException ex) {
!   // Rollback the transaction if we have an exception
!   connection.rollback();
! } finally {
!   // Finally release the entire database connection 
!   if (connection != null) {
!     connection.release();
!   } 
! }</pre> </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12B69"></a>Accessing the parameters within the Job itself</h3></div></div><div></div></div><p> You use
    the function getJobParameter(name) to access the actual parameters that are
!   passed to the job itself. <pre class="programlisting">
! public void run() {
!   try {
!     String digitParam = (String)getJobParameter(PrimeNumberSearch.DIGIT_PARAM);
!     if (digitParam == null )
!       throw new IllegalArgumentException("Digits parameter must be &gt; 0");
!     int numDigits = Integer.parseInt( digitParam );
!     if (numDigits &lt;= 0)
!       throw new IllegalArgumentException("Digits parameter must be integer &gt; 0");
!     doCalculation(numDigits);
!     finish( "Successfully calculation in database: '"+getDBName()+"'" );
!   } catch (Exception e) {
!     finish("Abnormal termination of calculation", e);
!   }
! }</pre>
!   </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12B72"></a>Job Handling and Management</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12B75"></a>Starting the
    Job Handler</h3></div></div><div></div></div><p>Normally the JobHandler is run as a separate thread
    in your application server's JVM by adding the
***************
*** 188,207 ****
    and broken into multiple lines if desired.</p><p>The Job Handler is
    ordinarily left running whenever the server is up, so that Jobs receive
!   immediate consideration based on their priorities.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12BD5"></a>Job Scheduling Features</h3></div></div><div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="N12BD8"></a>Submit New Job</h4></div></div><div></div></div><p> <pre class="programlisting"> // allocate empty slot for new job JobQueue oneJob =
!   new JobQueue(); // this job should be executed on "Unix" systems
!   Only. // the valid options are: MSWIN, Unix, any or Specific OS as returned
!   by System.getProperty("java.os")
!   oneJob.setJobOSName("Unix"); // execute this job at specified by
!   cron parameters time. oneJob.setJobCronParams(minute, hour, dayOfMonth,
!   month, dayOfWeek, year); // set job code to execute
!   oneJob.setJobCode("com.jcorporate.expresso.utils.TestJob"); // set
!   the owner of this job oneJob.setUserName("root") // job is ready for
!   execution oneJob.setJobStatus(JobQueue.JOB_STATUS_AVAILABLE) // Add
!   parameters associated with this job (same as before) // submit job
!   oneJob.add(); </pre> </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="N12BE1"></a>Controlling
!   jobs</h4></div></div><div></div></div><p> <pre class="programlisting"> JobHandlerControl jobControl = new
!   JobHandlerControl(); String jobID = "10"; // stop job
!   jobControl.setCmdStopJob(jobID); jobControl.add(); // restart job
!   jobControl.setCmdRestartJob(jobID); jobControl.add(); </pre></p></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12BE9"></a>Cron Jobs</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12BEC"></a>Theory and Implementation</h3></div></div><div></div></div><p> When the JobHandler searches for jobs in the queue, it only picks up
    jobs that are set to status = JOB_STATUS_AVAILABLE and server id = 0. I
    believe the server id is a reference to the jobhandler in jobhandlerregistry
--- 240,278 ----
    and broken into multiple lines if desired.</p><p>The Job Handler is
    ordinarily left running whenever the server is up, so that Jobs receive
!   immediate consideration based on their priorities.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12B86"></a>Job Scheduling Features</h3></div></div><div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="N12B89"></a>Submit New Job</h4></div></div><div></div></div><p> <pre class="programlisting">
! // allocate empty slot for new job 
! JobQueue oneJob = new JobQueue(); 
! 
! // this job should be executed on 'Unix' systems Only. 
! // the valid options are: MSWIN, Unix, any or Specific OS 
! // as returned by System.getProperty("java.os")
! oneJob.setJobOSName("Unix"); 
! 
! // execute this job at specified by cron parameters time. 
! oneJob.setJobCronParams(minute, hour, dayOfMonth, month, dayOfWeek, year); 
! 
! // set job code to execute 
! oneJob.setJobCode("com.jcorporate.expresso.utils.TestJob"); 
! 
! // set the owner of this job 
! oneJob.setUserName("root");
! 
! // job is ready for execution 
! oneJob.setJobStatus(JobQueue.JOB_STATUS_AVAILABLE); 
! 
! // Add parameters associated with this job (same as before) 
! // submit job
! oneJob.add();</pre> </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="N12B92"></a>Controlling
!   jobs</h4></div></div><div></div></div><p> <pre class="programlisting">
! JobHandlerControl jobControl = new JobHandlerControl();
! String jobID = "10"; 
! 
! // stop job 
! jobControl.setCmdStopJob(jobID); 
! jobControl.add(); 
! 
! // restart job
! jobControl.setCmdRestartJob(jobID); 
! jobControl.add();</pre></p></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12B9A"></a>Cron Jobs</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12B9D"></a>Theory and Implementation</h3></div></div><div></div></div><p> When the JobHandler searches for jobs in the queue, it only picks up
    jobs that are set to status = JOB_STATUS_AVAILABLE and server id = 0. I
    believe the server id is a reference to the jobhandler in jobhandlerregistry
***************
*** 222,226 ****
    The easiest way is to pick out a job that you have already executed once
    that you wish to submit to the cron manager. </p><p> In the entries
!   parameters enter the following values: <div class="table"><a name="N12C03"></a><p class="title"><b>Table&nbsp;26.1.&nbsp;Job Queue
    Entry Parameters</b></p><table summary="Job Queue
    Entry Parameters" border="1"><colgroup><col><col></colgroup><thead><tr><th align="left">Entry Name</th><th align="left">Value</th></tr></thead><tbody><tr><td align="left">Job Serial Number</td><td align="left">Leave Alone Since it
--- 293,297 ----
    The easiest way is to pick out a job that you have already executed once
    that you wish to submit to the cron manager. </p><p> In the entries
!   parameters enter the following values: <div class="table"><a name="N12BB4"></a><p class="title"><b>Table&nbsp;26.1.&nbsp;Job Queue
    Entry Parameters</b></p><table summary="Job Queue
    Entry Parameters" border="1"><colgroup><col><col></colgroup><thead><tr><th align="left">Entry Name</th><th align="left">Value</th></tr></thead><tbody><tr><td align="left">Job Serial Number</td><td align="left">Leave Alone Since it
***************
*** 241,249 ****
    seconds, the JobHandler will pick up the job. If there are cron parameters
    associated with it, it will be sent to the crontab for time management.
!   </p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="N12C3E"></a>Meaning of the cron
    parameters</h4></div><div><div class="author"><h3 class="author"><span class="firstname">Eddie</span> <span class="surname">Lewis</span></h3></div></div></div><div></div></div><p>The setJobCronParams method as was mentioned
    earlier, should be 6 comma-delimited integer values like so:
    -1,-1,-1,-1,-1,-1 . Each item corresponds to a different time slot. The
!   meanings are: </p><div class="table"><a name="N12C49"></a><p class="title"><b>Table&nbsp;26.2.&nbsp;Job Scheduling Parameters</b></p><table summary="Job Scheduling Parameters" border="1"><colgroup><col><col></colgroup><tbody><tr><td><span class="bold"><b>Parameter</b></span></td><td><span class="bold"><b>Description</b></span></td></tr><tr><td>minute</td><td>the
    'minute' number when the cron should be executed. Standard useful
    values are 0-59. Set to zero if you want the cron to execute at the top of
--- 312,320 ----
    seconds, the JobHandler will pick up the job. If there are cron parameters
    associated with it, it will be sent to the crontab for time management.
!   </p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="N12BEF"></a>Meaning of the cron
    parameters</h4></div><div><div class="author"><h3 class="author"><span class="firstname">Eddie</span> <span class="surname">Lewis</span></h3></div></div></div><div></div></div><p>The setJobCronParams method as was mentioned
    earlier, should be 6 comma-delimited integer values like so:
    -1,-1,-1,-1,-1,-1 . Each item corresponds to a different time slot. The
!   meanings are: </p><div class="table"><a name="N12BFA"></a><p class="title"><b>Table&nbsp;26.2.&nbsp;Job Scheduling Parameters</b></p><table summary="Job Scheduling Parameters" border="1"><colgroup><col><col></colgroup><tbody><tr><td><span class="bold"><b>Parameter</b></span></td><td><span class="bold"><b>Description</b></span></td></tr><tr><td>minute</td><td>the
    'minute' number when the cron should be executed. Standard useful
    values are 0-59. Set to zero if you want the cron to execute at the top of
***************
*** 274,283 ****
    restart the server, you need to make sure, during initialization, that any
    repeating cron job has its status set to "available" and server = 0.
!   </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12C7B"></a>Some Cron parameter examples</h3></div></div><div></div></div><div class="itemizedlist"><ul type="disc"><li><p>Execute at midnight every day:
    0,0,-1,-1,-1,-1</p></li><li><p> Execute at half past
    every hour: 30,-1,-1,-1,-1,-1 </p></li><li><p> Execute
    at December 31, 11:59 every year: 59,23,31,11,-1,-1 </p></li><li><p> Execute at 3:00 a.m., the first of every month:
    0,3,1,-1,-1,-1 </p></li><li><p> Execute at June 1, 2:30
!   a.m., 2006 AD only: 30,2,1,5,-1,2006 </p></li><li><p>Execute all the time: -1,-1,-1,-1,-1,-1</p></li></ul></div></div></div><p></p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12C92"></a>Conclusion</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12C95"></a>Contributors</h3></div></div><div></div></div><p> The following persons have contributed their time to this chapter:
    <div class="itemizedlist"><ul type="bullet"><li style="list-style-type: disc"><p> Larry Hamel <a href="edg_intro.html#jgroup" title="Jcorporate's JGroup Services">(JGroup Expert)</a> </p></li><li style="list-style-type: disc"><p>Peter Pilgrim</p></li><li style="list-style-type: disc"><p>Mike
    Rimov</p></li><li style="list-style-type: disc"><p> Mike Traum <a href="edg_intro.html#jgroup" title="Jcorporate's JGroup Services">(JGroup
--- 345,354 ----
    restart the server, you need to make sure, during initialization, that any
    repeating cron job has its status set to "available" and server = 0.
!   </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12C2C"></a>Some Cron parameter examples</h3></div></div><div></div></div><div class="itemizedlist"><ul type="disc"><li><p>Execute at midnight every day:
    0,0,-1,-1,-1,-1</p></li><li><p> Execute at half past
    every hour: 30,-1,-1,-1,-1,-1 </p></li><li><p> Execute
    at December 31, 11:59 every year: 59,23,31,11,-1,-1 </p></li><li><p> Execute at 3:00 a.m., the first of every month:
    0,3,1,-1,-1,-1 </p></li><li><p> Execute at June 1, 2:30
!   a.m., 2006 AD only: 30,2,1,5,-1,2006 </p></li><li><p>Execute all the time: -1,-1,-1,-1,-1,-1</p></li></ul></div></div></div><p></p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N12C43"></a>Conclusion</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N12C46"></a>Contributors</h3></div></div><div></div></div><p> The following persons have contributed their time to this chapter:
    <div class="itemizedlist"><ul type="bullet"><li style="list-style-type: disc"><p> Larry Hamel <a href="edg_intro.html#jgroup" title="Jcorporate's JGroup Services">(JGroup Expert)</a> </p></li><li style="list-style-type: disc"><p>Peter Pilgrim</p></li><li style="list-style-type: disc"><p>Mike
    Rimov</p></li><li style="list-style-type: disc"><p> Mike Traum <a href="edg_intro.html#jgroup" title="Jcorporate's JGroup Services">(JGroup

Index: jobcontrol.xml
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/expresso/doc/edg/jobcontrol.xml,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** jobcontrol.xml	26 Apr 2004 17:29:58 -0000	1.19
--- jobcontrol.xml	12 May 2004 11:08:30 -0000	1.20
***************
*** 1,3 ****
! <?xml version="1.0" encoding="UTF-8"?>
  <chapter id="jobcontrol" xreflabel="Editing The EDG">
    <title>Jobs Expresso</title>
--- 1,3 ----
! <?xml version="1.0" encoding="UTF-8"?>
  <chapter id="jobcontrol" xreflabel="Editing The EDG">
    <title>Jobs Expresso</title>
***************
*** 79,93 ****
    simple job you must extend the standard class <emphasis>com.jcorporate.expresso.core.job.Job</emphasis>
    and implement the method <emphasis>run</emphasis>. </para> <para>
!   <programlisting>package org.fooey.testapp.job; import
!   com.jcorporate.expresso.core.job.Job; import
!   com.jcorporate.expresso.services.dbobj.JobQueue; import
!   com.jcorporate.expresso.services.dbobj.JobQueueParam; public class
!   PrimeNumberSearch extends Job { public PrimeNumberSearch() { super(); } /**
!   Return a string for the security admininistration screens. */ public String
!   getTitle() { return new String(&#34;Prime Number Search&#34;); } /** The run
!   methods should process the long running task */ public void run() { try {
!   doCalculation(); finish( &#34;Successfully calculation in
!   database:`&#34;+getDBName()+&#34;&#39;&#34; ); } catch (Exception e) {
!   finish(&#34;Abnormal termination of calculation&#34;, e); } } }</programlisting>
    </para> <para> The <emphasis>run()</emphasis> should be very familiar to
    programmers who have experience of multi-thread Java applications. In fact
--- 79,112 ----
    simple job you must extend the standard class <emphasis>com.jcorporate.expresso.core.job.Job</emphasis>
    and implement the method <emphasis>run</emphasis>. </para> <para>
!   <programlisting>
! <![CDATA[
! package org.fooey.testapp.job;
! 
! import com.jcorporate.expresso.core.job.Job;
! import com.jcorporate.expresso.services.dbobj.JobQueue;
! import com.jcorporate.expresso.services.dbobj.JobQueueParam; 
! 
! public class PrimeNumberSearch extends Job {
!   public PrimeNumberSearch() { 
!     super();
!   }
! 
!   /**
!     Return a string for the security admininistration screens. 
!   */
!   public String getTitle() {
!     return new String("Prime Number Search";);
!   }
!  
!   /** The run methods should process the long running task */ 
!   public void run() {
!     try {
!       doCalculation();
!       finish( "Successfully calculation in database:'"+getDBName()+"'" );
!     } catch (Exception e) {
!       finish("Abnormal termination of calculation", e);
!     }
!   }
! }]]></programlisting>
    </para> <para> The <emphasis>run()</emphasis> should be very familiar to
    programmers who have experience of multi-thread Java applications. In fact
***************
*** 113,124 ****
    familiar with <emphasis>JobQueue</emphasis> objects. Job queue object are
    database objects, you create them with system privileges like so. </para>
!   <para> <programlisting>JobQueue jq = new
!   JobQueue(SecuredDBObject.SYSTEM_ACCOUNT);</programlisting> </para>
    <para> Once you create a job queue object you must associate it with an user
    id, the job class, and a status. </para> <para>
!   <programlisting>jq.setField(JobQueue.FLD_UID, requestContext.getUid());
!   jq.setField(JobQueue.FLD_JOBCODE,
!   org.fooey.testapp.job.PrimeNumberSearch.class.getName());
!   jq.setField(JobQueue.FLD_STATUS_CODE, JobQueue.JOB_STATUS_NEW);</programlisting>
    </para> <para> As with an DBObject you need to insert into the data store,
    so likewise with a job queue. </para> <para>
--- 132,143 ----
    familiar with <emphasis>JobQueue</emphasis> objects. Job queue object are
    database objects, you create them with system privileges like so. </para>
!   <para> <programlisting><![CDATA[
! JobQueue jq = new JobQueue(SecuredDBObject.SYSTEM_ACCOUNT);]]></programlisting> </para>
    <para> Once you create a job queue object you must associate it with an user
    id, the job class, and a status. </para> <para>
!   <programlisting><![CDATA[
! jq.setField(JobQueue.FLD_UID, requestContext.getUid());
! jq.setField(JobQueue.FLD_JOBCODE, org.fooey.testapp.job.PrimeNumberSearch.class.getName());
! jq.setField(JobQueue.FLD_STATUS_CODE, JobQueue.JOB_STATUS_NEW);]]></programlisting>
    </para> <para> As with an DBObject you need to insert into the data store,
    so likewise with a job queue. </para> <para>
***************
*** 129,134 ****
    then you must set the status to <emphasis>JobQueue.JOB_STATUS_AV AVAILABLE</emphasis>,
    then the handler will pick it up on its next scheduled loop and execute it.
!   </para> <para> <programlisting>jq.setField(JobQueue.FLD_STATUS_CODE,
!   JobQueue.JOB_STATUS_AVAILABLE); jq.update();</programlisting> </para>
    <para> Why have these two difference status levels? The answer is that job
    queue may have associated job queue parameters. When you create job queue
--- 148,154 ----
    then you must set the status to <emphasis>JobQueue.JOB_STATUS_AV AVAILABLE</emphasis>,
    then the handler will pick it up on its next scheduled loop and execute it.
!   </para> <para> <programlisting><![CDATA[
! jq.setField(JobQueue.FLD_STATUS_CODE, JobQueue.JOB_STATUS_AVAILABLE);
! jq.update();]]></programlisting> </para>
    <para> Why have these two difference status levels? The answer is that job
    queue may have associated job queue parameters. When you create job queue
***************
*** 146,199 ****
    possible parameter names. The first argument is the real name of the
    parameter. The second is the &#39;friendly&#39; name that is displayed by
!   JobQueue UI. <programlisting>public class PrimeNumberSearch extends Job {
!   public static final DIGIT_PARAM = &#34;digits&#34;; public
!   PrimeNumberSearch() { // optional: this allows job and UI to know about
!   param, for setting value via UI, // or returning via
!   &#34;getParameterNamesAndDescriptions()&#34; addParameter(DIGIT_PARAM,
!   &#34;Number of digits in prime to find&#34;); } ..... }</programlisting>
    </para> </sect2> <sect2> <title>Adding parameters to a job</title>
    <para> In the method below, we queue a job just like you would with a normal
    JobQueueEntry. But we add parameters, name/value pairs, that are associated
!   with the job. </para> <para> For example: <programlisting>//Create a new
!   connection and turn off autocommit for a transaction DBConnection connection
!   = DBConnectionPool.getInstance(&#34;default&#34;).getConnection();
!   connection.setAutoCommit(false); try { // Create the jobqueue entry and add
!   it as before JobQueue jq = new JobQueue(SecuredDBObject.SYSTEM_ACCOUNT); //
!   Set the connection so it will use the same transaction system // as the
!   other dbobjects jq.setConnection(connection); jq.setField(JobQueue.FLD_UID,
!   requestContext.getUid()); jq.setField(JobQueue.FLD_JOBCODE,
!   org.fooey.testapp.job.PrimeNumberSearch.class.getName());
!   jq.setJobStatus(JobQueue.JOB_STATUS_AVAILABLE); // jq.setCronParams(-1, -1,
!   -1, -1, -1, -1); // for testing jq.setField(JobQueue.FLD_SERVERID, 0);
    jq.setField(JobQueue.FLD_STATUS_CODE, JobQueue.JOB_STATUS_NEW);
!   jq.addOrUpdate(); // // Now create a JobQueueParameter dbobject //
    JobQueueParam jobParam = new JobQueueParam(SecuredDBObject.SYSTEM_ACCOUNT);
!   // Likewise set the connection so it&#39;s part of the same transaction
!   jobParam.setConnection(connection); // Set the field number based to the job
!   number that we now have from adding the job above
!   jobParam.setField(JobQueueParam.FLD_JOB_NUMBER,
!   jq.getField(JobQueue.FLD_JOBNUMBER)); // Arbitrary param number... just must
!   be unique for each parameter
!   jobParam.setField(JobQueueParam.FLD_PARAM_NUMBER,&#34;1&#34;); // Set the
!   parameter code in this case digits
!   jobParam.setField(JobQueueParam.FLD_PARAM_CODE,
!   PrimeNumberSearch.DIGIT_PARAM); //Set the digits parameter to 85
!   jobParam.setField(JobQueueParam.FLD_PARAM_VALUE,&#34;85&#34;); // Now add
!   the object and commit the entire transaction jobParam.addOrUpdate();
!   connection.commit(); } catch (DBException ex) { // Rollback the transaction
!   if we have an exception connection.rollback(); } finally { // Finally
!   release the entire database connection if (connection != null) {
!   connection.release(); } }</programlisting> </para> </sect2> <sect2>
    <title>Accessing the parameters within the Job itself</title> <para> You use
    the function getJobParameter(name) to access the actual parameters that are
!   passed to the job itself. <programlisting>public void run() { try { String
!   digitParam = (String)getJobParameter(PrimeNumberSearch.DIGIT_PARAM); if
!   (digitParam == null ) throw new IllegalArgumentException(&#34;Digits
!   parameter must be &#62; 0&#34;); int numDigits = Integer.parseInt(
!   digitParam ); if (numDigits &#60;= 0) throw new
!   IllegalArgumentException(&#34;Digits parameter must be integer &#62;
!   0&#34;); doCalculation(numDigits); finish( &#34;Successfully calculation in
!   database: &#39;&#34;+getDBName()+&#34;&#39;&#34; ); } catch (Exception e) {
!   finish(&#34;Abnormal termination of calculation&#34;, e); } }</programlisting>
    </para> </sect2></sect1>
  
--- 166,251 ----
    possible parameter names. The first argument is the real name of the
    parameter. The second is the &#39;friendly&#39; name that is displayed by
!   JobQueue UI. <programlisting><![CDATA[
! public class PrimeNumberSearch extends Job {
!   public static final DIGIT_PARAM = "digits";
!   public PrimeNumberSearch() { 
!     // optional: this allows job and UI to know about param, for setting value via UI,
!     // or returning via 'getParameterNamesAndDescriptions()'
!     addParameter(DIGIT_PARAM, "Number of digits in prime to find");
!   }
!   .....
! }]]></programlisting>
    </para> </sect2> <sect2> <title>Adding parameters to a job</title>
    <para> In the method below, we queue a job just like you would with a normal
    JobQueueEntry. But we add parameters, name/value pairs, that are associated
!   with the job. </para> <para> For example: <programlisting><![CDATA[
! //Create a new connection and turn off autocommit for a transaction 
! DBConnection connection = DBConnectionPool.getInstance("default").getConnection();
! connection.setAutoCommit(false); 
! try { 
!   // Create the jobqueue entry and add it as before 
!   JobQueue jq = new JobQueue(SecuredDBObject.SYSTEM_ACCOUNT);
! 
!   // Set the connection so it will use the same transaction system 
!   // as the other dbobjects 
!   jq.setConnection(connection);
!   jq.setField(JobQueue.FLD_UID, requestContext.getUid());
!   jq.setField(JobQueue.FLD_JOBCODE, org.fooey.testapp.job.PrimeNumberSearch.class.getName());
!   jq.setJobStatus(JobQueue.JOB_STATUS_AVAILABLE); 
!   // jq.setCronParams(-1, -1, -1, -1, -1, -1); 
!   // for testing jq.setField(JobQueue.FLD_SERVERID, 0);
    jq.setField(JobQueue.FLD_STATUS_CODE, JobQueue.JOB_STATUS_NEW);
!   jq.addOrUpdate(); 
! 
!   //
!   // Now create a JobQueueParameter dbobject
!   //
    JobQueueParam jobParam = new JobQueueParam(SecuredDBObject.SYSTEM_ACCOUNT);
! 
!   // Likewise set the connection so it's part of the same transaction
!   jobParam.setConnection(connection);
! 
!   // Set the field number based to the job number that we now have from adding the job above
!   jobParam.setField(JobQueueParam.FLD_JOB_NUMBER, jq.getField(JobQueue.FLD_JOBNUMBER));
! 
!   // Arbitrary param number... just must be unique for each parameter
!   jobParam.setField(JobQueueParam.FLD_PARAM_NUMBER,"1");
! 
!   // Set the parameter code in this case digits
!   jobParam.setField(JobQueueParam.FLD_PARAM_CODE, PrimeNumberSearch.DIGIT_PARAM);
! 
!   //Set the digits parameter to 85
!   jobParam.setField(JobQueueParam.FLD_PARAM_VALUE,&#34;85&#34;);
! 
!   // Now add the object and commit the entire transaction
!   jobParam.addOrUpdate();
! 
!   connection.commit();
! } catch (DBException ex) {
!   // Rollback the transaction if we have an exception
!   connection.rollback();
! } finally {
!   // Finally release the entire database connection 
!   if (connection != null) {
!     connection.release();
!   } 
! }]]></programlisting> </para> </sect2> <sect2>
    <title>Accessing the parameters within the Job itself</title> <para> You use
    the function getJobParameter(name) to access the actual parameters that are
!   passed to the job itself. <programlisting><![CDATA[
! public void run() {
!   try {
!     String digitParam = (String)getJobParameter(PrimeNumberSearch.DIGIT_PARAM);
!     if (digitParam == null )
!       throw new IllegalArgumentException("Digits parameter must be > 0");
!     int numDigits = Integer.parseInt( digitParam );
!     if (numDigits <= 0)
!       throw new IllegalArgumentException("Digits parameter must be integer > 0");
!     doCalculation(numDigits);
!     finish( "Successfully calculation in database: '"+getDBName()+"'" );
!   } catch (Exception e) {
!     finish("Abnormal termination of calculation", e);
!   }
! }]]></programlisting>
    </para> </sect2></sect1>
  
***************
*** 223,242 ****
    immediate consideration based on their priorities.</para></sect2>
    <sect2> <title>Job Scheduling Features</title> <sect3> <title>Submit New Job</title>
!   <para> <programlisting> // allocate empty slot for new job JobQueue oneJob =
!   new JobQueue(); // this job should be executed on &#34;Unix&#34; systems
!   Only. // the valid options are: MSWIN, Unix, any or Specific OS as returned
!   by System.getProperty(&#34;java.os&#34;)
!   oneJob.setJobOSName(&#34;Unix&#34;); // execute this job at specified by
!   cron parameters time. oneJob.setJobCronParams(minute, hour, dayOfMonth,
!   month, dayOfWeek, year); // set job code to execute
!   oneJob.setJobCode(&#34;com.jcorporate.expresso.utils.TestJob&#34;); // set
!   the owner of this job oneJob.setUserName(&#34;root&#34;) // job is ready for
!   execution oneJob.setJobStatus(JobQueue.JOB_STATUS_AVAILABLE) // Add
!   parameters associated with this job (same as before) // submit job
!   oneJob.add(); </programlisting> </para></sect3> <sect3> <title>Controlling
!   jobs</title> <para> <programlisting> JobHandlerControl jobControl = new
!   JobHandlerControl(); String jobID = &#34;10&#34;; // stop job
!   jobControl.setCmdStopJob(jobID); jobControl.add(); // restart job
!   jobControl.setCmdRestartJob(jobID); jobControl.add(); </programlisting></para></sect3></sect2></sect1>
  
    <sect1><title>Cron Jobs</title> <sect2> <title>Theory and Implementation</title>
--- 275,313 ----
    immediate consideration based on their priorities.</para></sect2>
    <sect2> <title>Job Scheduling Features</title> <sect3> <title>Submit New Job</title>
!   <para> <programlisting><![CDATA[
! // allocate empty slot for new job 
! JobQueue oneJob = new JobQueue(); 
! 
! // this job should be executed on 'Unix' systems Only. 
! // the valid options are: MSWIN, Unix, any or Specific OS 
! // as returned by System.getProperty("java.os")
! oneJob.setJobOSName("Unix"); 
! 
! // execute this job at specified by cron parameters time. 
! oneJob.setJobCronParams(minute, hour, dayOfMonth, month, dayOfWeek, year); 
! 
! // set job code to execute 
! oneJob.setJobCode("com.jcorporate.expresso.utils.TestJob"); 
! 
! // set the owner of this job 
! oneJob.setUserName("root");
! 
! // job is ready for execution 
! oneJob.setJobStatus(JobQueue.JOB_STATUS_AVAILABLE); 
! 
! // Add parameters associated with this job (same as before) 
! // submit job
! oneJob.add();]]></programlisting> </para></sect3> <sect3> <title>Controlling
!   jobs</title> <para> <programlisting><![CDATA[
! JobHandlerControl jobControl = new JobHandlerControl();
! String jobID = "10"; 
! 
! // stop job 
! jobControl.setCmdStopJob(jobID); 
! jobControl.add(); 
! 
! // restart job
! jobControl.setCmdRestartJob(jobID); 
! jobControl.add();]]></programlisting></para></sect3></sect2></sect1>
  
    <sect1><title>Cron Jobs</title> <sect2> <title>Theory and Implementation</title>



More information about the cvs mailing list