com.wm.app.tn.delivery
Class GuaranteedJob

java.lang.Object
  extended by com.wm.app.tn.util.TNFixedData
      extended by com.wm.app.tn.delivery.GuaranteedJob
All Implemented Interfaces:
com.wm.data.IData, java.lang.Cloneable
Direct Known Subclasses:
DeliveryJob, RoutingJob

public abstract class GuaranteedJob
extends TNFixedData

A GuaranteedJob represents one unit of work for the task manager. It can be subclassed to reliably deliver documents, to guarantee the execution of async routing services, etc.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.wm.app.tn.util.TNFixedData
TNFixedData.TreeCursor
 
Field Summary
static int DELIVERING
           
static int DONE
           
static int FAILED
           
static int HELD
           
static int NEW
           
static java.lang.String NO_JOB_ID
           
static int PENDING
           
static int QUEUED
           
static java.lang.String[] STATUS_STRINGS
           
static int STOPPED
           
 
Constructor Summary
GuaranteedJob()
          No-arg constructor needed for subclasses of TNFixedData.
GuaranteedJob(java.lang.String jobId, java.lang.String serverId, DeliveryService service, BizDocEnvelope bizdoc, com.wm.data.IData svcInput, long ttw, int retryLimit, int retryFactor)
          Define a new Job
 
Method Summary
abstract  void addActivityEntry(int type, java.lang.String brief, java.lang.String full)
          Adds an activity log entry.
 boolean attempted()
           
static int codeForMsg(java.lang.String msg)
           
 void delivering()
          Mark job DELIVERING and update timestamp.
 void done()
          Mark job DONE and update timestamp.
 void enqueue(java.lang.String queue)
          Places the job on a virtual queue.
 boolean exceedsRetries()
           
 void fail()
          Mark job as FAILED (due to hitting retry limit or exceeding ttw).
 BizDocEnvelope getBizDocEnvelope()
           
abstract  java.lang.String getClassification()
          This method should return the job "classification" which is a String representing an abbreviated name for the class.
abstract  com.wm.data.IData getDBIData()
          This method will be used by the DB operations when storing jobs by binary encoding the information.
 DeliveryService getDeliveryService()
           
 com.wm.data.IData getInputData()
           
 java.lang.String getInvokeAsUser()
          For internal use only.
 java.lang.String getJobId()
           
 com.wm.data.IData getOutputData()
           
 java.lang.String getQueueName()
           
 int getRetries()
           
 int getRetryFactor()
           
 int getRetryLimit()
           
 java.lang.String getServerId()
           
 DeliveryService getService()
           
 java.lang.String getStatus()
           
 java.lang.String getStatusMsg()
           
 int getStatusVal()
           
 long getTimeCreated()
           
 long getTimeUpdated()
           
 java.lang.String getTransportStatus()
           
 java.lang.String getTransportStatusMessage()
           
 long getTransportTime()
           
 long getTTW()
           
static java.lang.Object[][] GuaranteedJobSchema()
           
 void hold()
          Mark job HELD.
 void invoke()
          Processes the job by invoking the associated service and interprets the return values to determine the job status.
 boolean isActive()
           
 boolean isComplete()
           
 boolean isDelivering()
           
 boolean isDone()
           
 boolean isExpired()
           
 boolean isFailed()
           
 boolean isHeld()
           
 boolean isNew()
           
 boolean isPending()
           
 boolean isProcessing()
           
 boolean isQueued()
           
 boolean isRetry()
           
 boolean isStopped()
           
 boolean readyToRun()
          Determines whether or not the job is ready to run.
 void reset()
          Restore job to pending or queued and timestamp status change.
 boolean retriesReached()
           
 void retryFailed()
          Update the retry count and timestamp.
 boolean save()
          Save the job in the database.
 void setActive(boolean active)
          Make this job active.
 void setAttempted(boolean attempted)
          Make this job active.
 void setBizDocEnvelope(BizDocEnvelope bizdoc)
           
abstract  void setDBIData(com.wm.data.IData data)
          This method will be used by the DB operations when restoring jobs from the database.
 void setDefaultServerId()
          Sets the id of the server that this job should run on to the hostid of the current thread.
 void setInputData(com.wm.data.IData inputData)
          Set any additional service input data.
 void setInvokeAsUser(java.lang.String invokeAsUser)
          For internal use only.
 void setJobId(java.lang.String id)
          This should only be used by the database code when restoring from the DB.
 void setOutputData(com.wm.data.IData outputData)
          This should only be used by the database code when restoring from the DB.
 void setProcessing(boolean proc)
          Sets the processing flag to prevent multiple threads from processing the same job simultaneously.
 void setQueueName(java.lang.String queue)
          Sets the queue name.
 void setRetries(int retries)
          This should only be used by the database code when restoring from the DB.
 void setRetryFactor(int factor)
          Set the retry factor for this job.
 void setRetryLimit(int limit)
          Set the retry limit for this job.
 void setServerId(java.lang.String id)
          Set the id of the server that this job should run on.
 void setService(DeliveryService service)
          Set the transport service to be invoked when processing this job.
 void setStatus(int status)
          This should only be used by the database code when restoring from the DB.
 void setTimeCreated(long time)
          Set the time this job was created.
 void setTimeUpdated(long time)
          Sets the time this job was last updated.
 void setTransportStatus(java.lang.String status)
          Internal use only.
 void setTransportStatusMessage(java.lang.String message)
          Set the transport status message return from the transport service.
 void setTransportTime(long time)
          Set the transport time return from the transport service.
 void setTTW(long ttw)
          Set the time to wait (in milliseconds) between retry attempts if the job fails.
 void start()
          Mark status as PENDING to indicate delivery in progress and timestamp status change.
 void stop()
          Add mark STOPPED and timestamp status change.
 java.lang.String toString()
          Default toString implementation returns class name followed by contents.
 
Methods inherited from class com.wm.app.tn.util.TNFixedData
clone, dataSize, get, get, getCursor, getHashCursor, getIndexCursor, getKey, getSharedCursor, getTreeCursor, indexOf, merge, set, set
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_JOB_ID

public static java.lang.String NO_JOB_ID

NEW

public static final int NEW
See Also:
Constant Field Values

PENDING

public static final int PENDING
See Also:
Constant Field Values

DONE

public static final int DONE
See Also:
Constant Field Values

FAILED

public static final int FAILED
See Also:
Constant Field Values

STOPPED

public static final int STOPPED
See Also:
Constant Field Values

QUEUED

public static final int QUEUED
See Also:
Constant Field Values

DELIVERING

public static final int DELIVERING
See Also:
Constant Field Values

HELD

public static final int HELD
See Also:
Constant Field Values

STATUS_STRINGS

public static final java.lang.String[] STATUS_STRINGS
Constructor Detail

GuaranteedJob

public GuaranteedJob()
No-arg constructor needed for subclasses of TNFixedData. Don't forget to provide a create() method also.


GuaranteedJob

public GuaranteedJob(java.lang.String jobId,
                     java.lang.String serverId,
                     DeliveryService service,
                     BizDocEnvelope bizdoc,
                     com.wm.data.IData svcInput,
                     long ttw,
                     int retryLimit,
                     int retryFactor)
              throws DeliveryException
Define a new Job

Parameters:
jobId - job id
serverId - server id job will be run on
service - service to be invoked when running this job
bizdoc - document associated with this job (if any)
svcInput - service inputs
ttw - Time-to-wait (in milliseconds)
retryLimit - max number of retry attempts
retryFactor - factor used to increase the time between retries
Throws:
DeliveryException
Method Detail

codeForMsg

public static final int codeForMsg(java.lang.String msg)

GuaranteedJobSchema

public static java.lang.Object[][] GuaranteedJobSchema()

invoke

public void invoke()
Processes the job by invoking the associated service and interprets the return values to determine the job status. Internal use only.


readyToRun

public boolean readyToRun()
Determines whether or not the job is ready to run. Internal use only.


getClassification

public abstract java.lang.String getClassification()
This method should return the job "classification" which is a String representing an abbreviated name for the class. It is used in the UI.

Returns:
the classification

getBizDocEnvelope

public BizDocEnvelope getBizDocEnvelope()
Returns:
associated bizdoc

getDeliveryService

public DeliveryService getDeliveryService()
Returns:
the delivery service

getOutputData

public com.wm.data.IData getOutputData()
Returns:
the output data returned from the service

getRetries

public int getRetries()
Returns:
the number of retry attempts

getRetryFactor

public int getRetryFactor()
Returns:
the retry factor

getRetryLimit

public int getRetryLimit()
Returns:
the max number of retry attempts allowed

getInputData

public com.wm.data.IData getInputData()
Returns:
delivery service input

getStatusVal

public int getStatusVal()
Returns:
the integer status of the job

getStatus

public java.lang.String getStatus()
Returns:
the text status of the job

getStatusMsg

public java.lang.String getStatusMsg()
Returns:
the status message returned by the transport service

getTransportStatus

public java.lang.String getTransportStatus()
Returns:
the status returned by the transport service

getTransportStatusMessage

public java.lang.String getTransportStatusMessage()
Returns:
the status message returned by the transport service

getTransportTime

public long getTransportTime()
Returns:
the time (in milliseconds) it took the transport service to deliver the document

getTTW

public long getTTW()
Returns:
the time-to-wait between retry attempts

getTimeCreated

public long getTimeCreated()
Returns:
the time this job was created

getTimeUpdated

public long getTimeUpdated()
Returns:
the last time this job was updated

getJobId

public java.lang.String getJobId()
Returns:
the job Id

getServerId

public java.lang.String getServerId()
Returns:
the server Id

getService

public DeliveryService getService()
Returns:
the delivery service

getQueueName

public java.lang.String getQueueName()
Returns:
the queue name

exceedsRetries

public boolean exceedsRetries()
Returns:
whether or not this job has exceeded it's retry limit

retriesReached

public boolean retriesReached()

isActive

public boolean isActive()
Returns:
whether or not the job is active

isProcessing

public boolean isProcessing()
Returns:
whether or not the job is being processed

isRetry

public boolean isRetry()
Returns:
whether or not this job has a retryLimit

isNew

public boolean isNew()
Returns:
whether or not the job status is NEW

isPending

public boolean isPending()
Returns:
whether or not the job status is PENDING

isDone

public boolean isDone()
Returns:
whether or not the job status is DONE

isFailed

public boolean isFailed()
Returns:
whether or not the job status is FAIL

isStopped

public boolean isStopped()
Returns:
whether or not the job status is STOPPED

isQueued

public boolean isQueued()
Returns:
whether or not the job status is QUEUED

isDelivering

public boolean isDelivering()
Returns:
whether or not the job status is DELIVERING

isComplete

public boolean isComplete()
Returns:
whether or not the job status is FAIL, DONE, or STOPPED

isHeld

public boolean isHeld()
Returns:
whether or not the job status is QUEUED

isExpired

public boolean isExpired()
Returns:
whether or not enough time has expired between retries

addActivityEntry

public abstract void addActivityEntry(int type,
                                      java.lang.String brief,
                                      java.lang.String full)
Adds an activity log entry.

Parameters:
type - activity log type
brief - brief message to insert
full - full message to insert

setActive

public void setActive(boolean active)
Make this job active. Internal use only.


setAttempted

public void setAttempted(boolean attempted)
Make this job active. Internal use only.


attempted

public boolean attempted()
Returns:
whether or not the job has been run yet Internal use only.

setBizDocEnvelope

public void setBizDocEnvelope(BizDocEnvelope bizdoc)
Parameters:
bizdoc - the document associated with this job

setInputData

public void setInputData(com.wm.data.IData inputData)
Set any additional service input data.

Parameters:
inputData -

setJobId

public void setJobId(java.lang.String id)
This should only be used by the database code when restoring from the DB.

Parameters:
id - Id of the job

setOutputData

public void setOutputData(com.wm.data.IData outputData)
This should only be used by the database code when restoring from the DB.

Parameters:
outputData - data passed from the service

setRetries

public void setRetries(int retries)
This should only be used by the database code when restoring from the DB.

Parameters:
retries - number of retries attempted

setRetryFactor

public void setRetryFactor(int factor)
Set the retry factor for this job. The retry factor must be 1 or greater. If not, it is defaulted to 1.

Parameters:
factor - retry factor

setRetryLimit

public void setRetryLimit(int limit)
Set the retry limit for this job.

Parameters:
limit - maximum retry limit

setServerId

public void setServerId(java.lang.String id)
Set the id of the server that this job should run on.

Parameters:
id - Id of the server for this job to run on

setDefaultServerId

public void setDefaultServerId()
Sets the id of the server that this job should run on to the hostid of the current thread.


setService

public void setService(DeliveryService service)
Set the transport service to be invoked when processing this job.

Parameters:
service - associated service

setStatus

public void setStatus(int status)
This should only be used by the database code when restoring from the DB.

Parameters:
status -

setTimeCreated

public void setTimeCreated(long time)
Set the time this job was created.

Parameters:
time -

setTimeUpdated

public void setTimeUpdated(long time)
Sets the time this job was last updated. Calculates and sets the time this job is due to run next.

Parameters:
time - a timestamp

setTransportStatus

public void setTransportStatus(java.lang.String status)
Internal use only. Set the transport status returned from the transport service.

Parameters:
status -

setTransportStatusMessage

public void setTransportStatusMessage(java.lang.String message)
Set the transport status message return from the transport service. Internal use only.

Parameters:
message -

setTransportTime

public void setTransportTime(long time)
Set the transport time return from the transport service. Internal use only.

Parameters:
time - transport time

setTTW

public void setTTW(long ttw)
Set the time to wait (in milliseconds) between retry attempts if the job fails.

Parameters:
ttw - time to wait between retries

setProcessing

public void setProcessing(boolean proc)
Sets the processing flag to prevent multiple threads from processing the same job simultaneously. Internal use only.

Parameters:
proc - indicates whether the job is being processed

setQueueName

public void setQueueName(java.lang.String queue)
Sets the queue name.

Parameters:
queue - name of the queue

enqueue

public void enqueue(java.lang.String queue)
Places the job on a virtual queue. Sets the queueName and changes the status to QUEUED.

Parameters:
queue - name of the queue

delivering

public void delivering()
Mark job DELIVERING and update timestamp. This status indicates that a batch delivery service is in the process of delivering the document contained by the delivery job. Internal use only.


start

public void start()
Mark status as PENDING to indicate delivery in progress and timestamp status change. Internal use only.


reset

public void reset()
Restore job to pending or queued and timestamp status change. Internal use only.


stop

public void stop()
Add mark STOPPED and timestamp status change. Internal use only.


done

public void done()
Mark job DONE and update timestamp. Internal use only.


fail

public void fail()
Mark job as FAILED (due to hitting retry limit or exceeding ttw). Internal use only.


hold

public void hold()
Mark job HELD. Internal use only.


retryFailed

public void retryFailed()
Update the retry count and timestamp. Internal use only.


getInvokeAsUser

public java.lang.String getInvokeAsUser()
For internal use only.


setInvokeAsUser

public void setInvokeAsUser(java.lang.String invokeAsUser)
For internal use only. This sets the current user into job object so that initial/retry attempts can be performed using the same userId.


save

public boolean save()
Save the job in the database. If there is a DB exception then an ActivityLog entry is created.


getDBIData

public abstract com.wm.data.IData getDBIData()
This method will be used by the DB operations when storing jobs by binary encoding the information. Use it to store subclass specific information. Note that a key of "javaclass" must be present and contain the name of the subclass. If not the object will not get created as the the appropriate subclass.


setDBIData

public abstract void setDBIData(com.wm.data.IData data)
This method will be used by the DB operations when restoring jobs from the database. Use it to set subclass specific information.

Parameters:
data - data to set

toString

public java.lang.String toString()
Description copied from class: TNFixedData
Default toString implementation returns class name followed by contents.

Overrides:
toString in class TNFixedData
Returns:
a String representation of a GuaranteedJob