com.equilibrium.util.api
Class MGBatch

java.lang.Object
  extended by com.equilibrium.util.api.MGBatch

public class MGBatch
extends java.lang.Object

Handle creation and submission of Batches. A batch is a sequence of MediaRich requests called Jobs. Each batch is assigned a unique id, the BatchId. Each job within a batch is also assigned a JobId.

Additionally, the MGBatch object can submit an ErrorJob. This job consists of a script to be executed whenever an uncaught exception is thrown within any job.

Media Script

As part of the execution of such a batch a MediaScript may wish to access special batch related methods of the MediaScript req object such as getJobId, getJobTempDir, getBatchId and getBatchTempDir. Those methods are documented in the MediaRich Programmers Guide.

As mentioned above as part of an ErrorJob an error script may be executed. This script is passed all of the parameters of the job that had an error, prefixed with "ScriptParam_".

The file parameter paths are passed to the error script, prefixed with "FileParam_".

The following parameters are also passed:

All of these parameters may be accessed using the getParameter method of the MediaScript req object.


Method Summary
 void commit()
          Commit the batch after all jobs have been submitted.
 MGRequest createErrorScriptRequest()
          Create a request for an error job for this batch.
 MGRequest createJobRequest()
          Create a normal job request.
 MGRequest createJobRequest(boolean block, boolean waitPrev, boolean holdSub)
          Return a new job request, specifying if the job should block the thread, wait for previous jobs to complete or hold subsequent jobs until this job completes.
 MGRequest createPostscriptRequest()
          Create a postscript job request.
 MGRequest createPrescriptRequest()
          Create a prescript request.
 void discard()
          Discard this batch.
 int getID()
          Return the batch id for this batch.
 long getMgSessionId()
          Return the MG Session ID for this batch
 MGFileResponse requestFile(java.lang.String path)
          Request a file generated during this batch.
 void setBatchInfo(java.lang.String info)
          Set an info string for this batch.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getID

public int getID()
Return the batch id for this batch.

Returns:
id

getMgSessionId

public long getMgSessionId()
Return the MG Session ID for this batch

Returns:
id

createErrorScriptRequest

public MGRequest createErrorScriptRequest()
                                   throws java.io.IOException,
                                          MGException
Create a request for an error job for this batch. This must be done prior to creating any job requests. The error job is invoked whenever an uncaught exception is thrown during the execution of any other job in this batch.

Returns:
The request object for the error script.
Throws:
java.io.IOException
MGException

createPrescriptRequest

public MGRequest createPrescriptRequest()
                                 throws java.io.IOException,
                                        MGException
Create a prescript request. This specifies a job that must complete prior to the execution of any other job in this batch.

Returns:
The prescript request object.
Throws:
java.io.IOException
MGException

createJobRequest

public MGRequest createJobRequest()
                           throws java.io.IOException,
                                  MGException
Create a normal job request. These jobs will execute in approximately the order in which they were submitted.

Returns:
request for a batch job.
Throws:
java.io.IOException
MGException

createJobRequest

public MGRequest createJobRequest(boolean block,
                                  boolean waitPrev,
                                  boolean holdSub)
                           throws java.io.IOException,
                                  MGException
Return a new job request, specifying if the job should block the thread, wait for previous jobs to complete or hold subsequent jobs until this job completes.

Parameters:
block - set true for the commit for this request to block the thread until the job completes.
waitPrev - set true to cause this job to wait until all previous jobs have completed prior to executing.
holdSub - set true to hold all subsequently submitted jobs until this job completes.
Returns:
The request.
Throws:
java.io.IOException
MGException

createPostscriptRequest

public MGRequest createPostscriptRequest()
                                  throws java.io.IOException,
                                         MGException
Create a postscript job request. This job will not execute until all other submitted jobs in the batch have completed and will block on commit.

Returns:
the request.
Throws:
java.io.IOException
MGException

setBatchInfo

public void setBatchInfo(java.lang.String info)
                  throws java.io.IOException,
                         MGException
Set an info string for this batch. This string is returned as the BatchInfo parameter of the Batch status.

Parameters:
info - The info string to assign to this batch.
Throws:
java.io.IOException
MGException

requestFile

public MGFileResponse requestFile(java.lang.String path)
                           throws java.io.IOException,
                                  MGException
Request a file generated during this batch. The file path must be in one of the virtual filesystems specified in the LookupFilesystems property of the global.properties file. Any non-committed request or response objects will be invalidated by this call.

Parameters:
path - virtual path of requested file.
Returns:
file response.
Throws:
java.io.IOException
MGException

discard

public void discard()
             throws java.io.IOException
Discard this batch. This will discard any uncommitted jobs.

Throws:
java.io.IOException

commit

public void commit()
            throws java.io.IOException,
                   MGException
Commit the batch after all jobs have been submitted. This tell the server to not expect (or accept) any additional jobs for this batch.

Throws:
java.io.IOException
MGException