com.ibm.commerce.scheduler.commands
Class AddJobCmdImpl

java.lang.Object
  |
  +--CacheableCommandImpl
        |
        +--com.ibm.commerce.command.AbstractECTargetableCommand
              |
              +--com.ibm.commerce.command.ControllerCommandImpl
                    |
                    +--com.ibm.commerce.scheduler.commands.AddJobCmdImpl
All Implemented Interfaces:
AccCommand, AddJobCmd, ControllerCommand, ECCommand, ECTargetableCommand
Direct Known Subclasses:
AddBroadcastJobCmdImpl, ContractDeployCmdImpl, EditJobCmdImpl

public class AddJobCmdImpl
extends ControllerCommandImpl
implements AddJobCmd

Add a job to the Commance Server's scheduler.

The parameters passed to the command are:

The command will verify the value specified for the schedule job. If any value is missing or incorrect, an exception is thrown. If the values are okay, the new schedule job is added by adding a record to the SCHCONFIG and SCHACTIVE table. The information found in the SCHCONFIG table contains the configuration information when executing the schedule job and the record in the SCHACTIVE record will determine when to execute the job next.

See Also:
Serialized Form

Field Summary
static java.lang.String COPYRIGHT
          IBM copyright notice field.
 
Fields inherited from class com.ibm.commerce.command. ControllerCommandImpl
requestProperties, responseProperties, retriable, viewReqProperties
 
Fields inherited from class com.ibm.commerce.command. AbstractECTargetableCommand
commandContext
 
Fields inherited from interface com.ibm.commerce.scheduler.commands. AddJobCmd
defaultCommandClassName, NAME
 
Constructor Summary
AddJobCmdImpl()
          Creates the AddJob command object.
 
Method Summary
protected static java.sql.Timestamp convertTime(java.lang.String time)
          Convert the input time value to a java.sql.Timestamp object.
 java.lang.String getApplicationType()
          Gets the application type for the job to be added.
 java.lang.Integer getAttempts()
          Gets the number of re-attempts when error occurs.
 java.lang.Integer getCheckCommandId()
          Gets the id of the check command.
 java.lang.Integer getDelay()
          Gets the delay time between re-attempts when error occurs.
protected  java.lang.String getEndTime()
          Gets the timestamp for the end time for the request.
protected  java.lang.String getErrorUrl()
          Gets the error URL to be redirected to at the end of the command in case of an error.
 java.lang.String getHost()
          Gets the scheduler instance name that unique identifies scheduler for a JVM of the Commerce instance.
 java.lang.String getInterfaceName()
          Gets the interface name of the task command with will determine whether the job needs to be executed.
protected  java.lang.Integer getInterval()
          Gets the interval between each run of the job.
 java.lang.Long getJobId()
          Gets the job's reference number.
 java.lang.Long getJobInstanceId()
          Gets the job's instance number.
protected  java.lang.String getName()
          Gets the user identity of the job.
protected  java.lang.String getPathInfo()
          Gets the command name of the job to execute.
protected  java.lang.Integer getPriority()
          Gets the priority of the job.
protected  java.lang.String getQueryString()
          Gets the parameters when executing the job.
  AccessVector getResources()
          Returns the resources when creating the schedule job.
protected  java.lang.Integer getSequence()
          Gets the sequence of the schedule job.
protected  java.sql.Timestamp getStartTime()
          Gets the preferred start time for executing the schedule job.
 java.lang.Integer getStoreId()
          Gets the store which this schedule job will run for.
protected  java.lang.String getStringEndTime()
          Gets the string value for the end time.
protected  java.lang.String getStringStartTime()
          Gets the string value for the start time.
protected  java.lang.String getUrl()
          Gets the URL to be redirected to at the end of the command.
 java.lang.Long getUserRefNum()
          Gets the user reference number of the user identity of the scheduler job.
 void performExecute()
          Adds a new schedule job to the Commerce's Scheduler.
 void setApplicationType(java.lang.String ApplicationType)
          Sets the job's application type.
 void setAttempts(java.lang.Integer attempts)
          Sets the number of retry attempts.
 void setCheckCommandId(java.lang.Integer chkCmdId)
          Sets the id of the check command defined in the CHKCMD table.
 void setDelay(java.lang.Integer delay)
          Sets the delay time between re-attempts.
 void setEndTime(java.sql.Timestamp endTime)
          Sets the end time of the job.
 void setErrorUrl(java.lang.String url)
          Sets the URL to be redirected to at the end of the command.
 void setHost(java.lang.String host)
          Sets the name of the scheduler instance that should run the schedule job.
 void setInterfaceName(java.lang.String interfaceName)
          Sets the interface name of the task command which will determine whether the job needs executing or not.
 void setInterval(java.lang.Integer interval)
          Sets the frequency to re-execute the schedule job.
 void setJobId(java.lang.Long newJobId)
          Sets the job id.
 void setJobInfo( TypedProperty property)
          Sets the job information and adds the new schedule job.
 void setName(java.lang.String name)
          Sets the user identity to run the schedule job.
 void setPathInfo(java.lang.String command)
          Sets the name of the command to be added to the scheduler.
 void setPriority(java.lang.Integer priority)
          Sets the priority of the job.
 void setQueryString(java.lang.String parameters)
          Sets the query string associated with the job.
 void setRequestProperties( TypedProperty reqParms)
          This method extracts the required parameters from the request properties and sets it locally in the command.
 void setSequence(java.lang.Integer policy)
          Sets the sequence.
 void setStartTime(java.sql.Timestamp startTime)
          Sets the start time to execute the schedule job.
 void setStoreId(java.lang.Integer storeId)
          Sets the store id of the schedule job.
 void setStringEndTime(java.lang.String endTime)
          Sets the job's end time.
 void setStringStartTime(java.lang.String startTime)
          Sets the job's start time.
 void setUrl(java.lang.String url)
          Sets the URL to be redirected to at the end of the command.
 void setUserRefNum(java.lang.Long refnum)
          Sets the user reference number that represents the job's user identity.
 void validateParameters()
          Checks the validity of the parameters.
 
Methods inherited from class com.ibm.commerce.command. ControllerCommandImpl
checkPermission, fulfills, getForUserId, getGeneric, getOwner, getRequestProperties, getResolvedRequestProperties, getResourceOwners, getResponseProperties, getRetriable, getViewInputProperties, isGeneric, isRetriable, mergeProperties, setForUserId, setGeneric, setOwner, setResponseProperties, setRetriable, setViewInputProperties
 
Methods inherited from class com.ibm.commerce.command. AbstractECTargetableCommand
accessControlCheck, checkIsAllowed, checkParameters, checkResourcePermission, createCommandExecutionEvent, execute, finalize, getAccCheck, getCommandContext, getCommandIfName, getCommandName, getCommandStoreId, getDefaultProperties, getUser, getUserId, isReadyToCallExecute, reset, setAccCheck, setCommandContext, setCommandIfName, setCommandStoreId, setDefaultProperties
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.ibm.commerce.command. ControllerCommand
checkPermission, execute, getGeneric, getRequestProperties, getResolvedRequestProperties, getResponseProperties, getRetriable, getViewInputProperties, isGeneric, isRetriable, mergeProperties, setGeneric, setRetriable, setViewInputProperties
 
Methods inherited from interface com.ibm.commerce.command. AccCommand
accessControlCheck, getAccCheck, getForUserId, getResourceOwners, setAccCheck, setForUserId, setOwner
 
Methods inherited from interface com.ibm.commerce.command. ECCommand
checkIsAllowed, checkResourcePermission, createCommandExecutionEvent, getCommandContext, getCommandIfName, getCommandName, getCommandStoreId, getDefaultProperties, getUser, getUserId, setCommandContext, setCommandIfName, setCommandStoreId, setDefaultProperties
 

Field Detail
public static final java.lang.String COPYRIGHT
IBM copyright notice field.
See Also:
Constant Field Values
Constructor Detail

AddJobCmdImpl

public AddJobCmdImpl()
Creates the AddJob command object.
Method Detail

convertTime

protected static java.sql.Timestamp convertTime(java.lang.String time)
                                         throws ECException
Convert the input time value to a java.sql.Timestamp object.
Parameters:
time - input time value
Returns:
The java.sql.Timestamp representation of the specified time.
Throws:
ECException

getApplicationType

public java.lang.String getApplicationType()
Gets the application type for the job to be added.
Returns:
The application type of the job.

getAttempts

public java.lang.Integer getAttempts()
Gets the number of re-attempts when error occurs.
Returns:
The number of attempts to execute the job successfully.

getCheckCommandId

public java.lang.Integer getCheckCommandId()
Gets the id of the check command. This is found in the CHKCMD table.
Returns:
The id of the check task command.

getDelay

public java.lang.Integer getDelay()
Gets the delay time between re-attempts when error occurs.
Returns:
The delay time in seconds when to re-execute the job in the case of a failed run.

getEndTime

protected java.lang.String getEndTime()
Gets the timestamp for the end time for the request.
Returns:
The end time of the job.

getErrorUrl

protected java.lang.String getErrorUrl()
Gets the error URL to be redirected to at the end of the command in case of an error.
Returns:
The URL to be redirected to incase there was an error executing the command.

getHost

public java.lang.String getHost()
Gets the scheduler instance name that unique identifies scheduler for a JVM of the Commerce instance.
Returns:
The scheduler instance name.

getInterfaceName

public java.lang.String getInterfaceName()
Gets the interface name of the task command with will determine whether the job needs to be executed.
Returns:
The interface name of the task command.

getInterval

protected java.lang.Integer getInterval()
Gets the interval between each run of the job.
Returns:
The time in seconds to wait before executing the job again.

getJobId

public java.lang.Long getJobId()
Gets the job's reference number.
Specified by:
getJobId in interface AddJobCmd
Returns:
The job reference number.

getJobInstanceId

public java.lang.Long getJobInstanceId()
Gets the job's instance number.
Specified by:
getJobInstanceId in interface AddJobCmd
Returns:
The job instance number.

getName

protected java.lang.String getName()
Gets the user identity of the job.
Returns:
The user identity of the job.

getPathInfo

protected java.lang.String getPathInfo()
Gets the command name of the job to execute.
Returns:
The job's command name.

getPriority

protected java.lang.Integer getPriority()
Gets the priority of the job.
Returns:
The job's priority.

getQueryString

protected java.lang.String getQueryString()
Gets the parameters when executing the job. This will be in the form of a Query String.
Returns:
The job's parameters.

getResources

public AccessVector getResources()
                          throws ECException
Returns the resources when creating the schedule job. The two possible resources are the store which the job will on behalf of and the user identity of the job.
Specified by:
getResources in interface ECCommand
Overrides:
getResources in class AbstractECTargetableCommand
Returns:
The resources of the schedule job that will need some access control verification.
Throws:
ECException - if there is any problem obtaining the resources.

getSequence

protected java.lang.Integer getSequence()
Gets the sequence of the schedule job.
Returns:
The job's sequence.

getStartTime

protected java.sql.Timestamp getStartTime()
Gets the preferred start time for executing the schedule job.
Returns:
The job's start time.

getStoreId

public java.lang.Integer getStoreId()
Gets the store which this schedule job will run for.
Specified by:
getStoreId in interface ECCommand
Overrides:
getStoreId in class AbstractECTargetableCommand
Returns:
The job's store identity.

getStringEndTime

protected java.lang.String getStringEndTime()
Gets the string value for the end time.
Returns:
The java.lang.String representation of the job's end time.

getStringStartTime

protected java.lang.String getStringStartTime()
Gets the string value for the start time.
Returns:
The java.lang.String representation of the job's start time.

getUrl

protected java.lang.String getUrl()
Gets the URL to be redirected to at the end of the command.
Returns:
The URL to redirect to after the command successfully completes.

getUserRefNum

public java.lang.Long getUserRefNum()
Gets the user reference number of the user identity of the scheduler job.
Returns:
The user reference number of the job's user identity.

performExecute

public void performExecute()
                    throws ECException

Adds a new schedule job to the Commerce's Scheduler. This is done by adding a record to the SCHCONFIG table and SCHACTIVE table. The entry in the SCHCONFIG table will contain the configuration for executing the job and the record in the SCHACTIVE table will contain the information when to execute the job. After the two records are created, the local Commerce scheduler will be notified that a new job was added incase it may need wake up ealier to process the newly added job.

The response properties will contain the required information to redirect to the specified URL.

Specified by:
performExecute in interface ECCommand
Overrides:
performExecute in class AbstractECTargetableCommand
Throws:
ECException - If there are any problems adding the records to the scheduler tables or notifying the scheduler about the newly added job.

setApplicationType

public void setApplicationType(java.lang.String ApplicationType)
Sets the job's application type.
Specified by:
setApplicationType in interface AddJobCmd

setAttempts

public void setAttempts(java.lang.Integer attempts)
Sets the number of retry attempts.
Specified by:
setAttempts in interface AddJobCmd
Parameters:
attempts - the number of attempts to successfully execute the job.

setCheckCommandId

public void setCheckCommandId(java.lang.Integer chkCmdId)
Sets the id of the check command defined in the CHKCMD table. This is the command that will determine whether the job needs executing or not.
Parameters:
chkCmdId - the id of the check command.

setDelay

public void setDelay(java.lang.Integer delay)
Sets the delay time between re-attempts.
Specified by:
setDelay in interface AddJobCmd
Parameters:
delay - the delay in seconds before re-execute the job because of a fail run.

setEndTime

public void setEndTime(java.sql.Timestamp endTime)
Sets the end time of the job.

setErrorUrl

public void setErrorUrl(java.lang.String url)
Sets the URL to be redirected to at the end of the command.
Parameters:
url - the URL to redirect to.

setHost

public void setHost(java.lang.String host)
Sets the name of the scheduler instance that should run the schedule job.
Specified by:
setHost in interface AddJobCmd
Parameters:
host - the name of the scheduler instance.

setInterfaceName

public void setInterfaceName(java.lang.String interfaceName)
Sets the interface name of the task command which will determine whether the job needs executing or not.
Parameters:
interfaceName - the interface name of the check command.

setInterval

public void setInterval(java.lang.Integer interval)
Sets the frequency to re-execute the schedule job.
Specified by:
setInterval in interface AddJobCmd
Parameters:
interval - the interval in seconds to wait before re-executing the job. 0 means the job will only be executed once.

setJobId

public void setJobId(java.lang.Long newJobId)
Sets the job id.
Parameters:
newJobId - the jobs id.

setJobInfo

public void setJobInfo(TypedProperty property)
                throws ECException
Sets the job information and adds the new schedule job.
Parameters:
property - the parameters when calling the AddJob command.
Throws:
ECException - if there is a problem with either the parameters passed to create the schedule job or with the actual creation of the schedule job.

setName

public void setName(java.lang.String name)
Sets the user identity to run the schedule job.
Specified by:
setName in interface AddJobCmd
Parameters:
name - the logon id of the job's user identity.

setPathInfo

public void setPathInfo(java.lang.String command)
Sets the name of the command to be added to the scheduler.
Specified by:
setPathInfo in interface AddJobCmd
Parameters:
command - the command to be executed.

setPriority

public void setPriority(java.lang.Integer priority)
Sets the priority of the job.
Parameters:
priority - the job's priority.

setQueryString

public void setQueryString(java.lang.String parameters)
Sets the query string associated with the job. This will be translated into parameters passed to the command when executing. The format is similar to a URL querystring which means that n1=v1&n2=v2 means two parameters will be passed to the command, one being n1 with a value of v1 and the other n2 with a value of v2.
Specified by:
setQueryString in interface AddJobCmd
Parameters:
parameters - the parameters passed to the command when executing.

setRequestProperties

public void setRequestProperties(TypedProperty reqParms)
                          throws ECException
This method extracts the required parameters from the request properties and sets it locally in the command. It throws an ECApplicationException if a required parameter is missing.
Specified by:
setRequestProperties in interface ControllerCommand
Overrides:
setRequestProperties in class ControllerCommandImpl
Parameters:
reqParms - the parameters when executing the command.
Throws:
ECException - if any parameters are missing.

setSequence

public void setSequence(java.lang.Integer policy)
Sets the sequence. The policy for handling missed runs. The default is 0, meaning that missed job will all be skipped except for one.
Specified by:
setSequence in interface AddJobCmd
Parameters:
policy - the job's sequence. This value should either be 0 or 1.

setStartTime

public void setStartTime(java.sql.Timestamp startTime)
Sets the start time to execute the schedule job.
Specified by:
setStartTime in interface AddJobCmd
Parameters:
startTime - the start time of the job.

setStoreId

public void setStoreId(java.lang.Integer storeId)
Sets the store id of the schedule job.
Parameters:
storeId - the id of the store to whose behalf the job will be executed.

setStringEndTime

public void setStringEndTime(java.lang.String endTime)
Sets the job's end time.

setStringStartTime

public void setStringStartTime(java.lang.String startTime)
Sets the job's start time.
Parameters:
startTime - the job's start time.

setUrl

public void setUrl(java.lang.String url)
Sets the URL to be redirected to at the end of the command.
Specified by:
setUrl in interface AddJobCmd
Parameters:
url - the URL to redirect to.

setUserRefNum

public void setUserRefNum(java.lang.Long refnum)
Sets the user reference number that represents the job's user identity.
Specified by:
setUserRefNum in interface AddJobCmd
Parameters:
refnum - the user reference number.

validateParameters

public void validateParameters()
                        throws ECException
Checks the validity of the parameters. It checks for the presence or absence of parameters and the range of values.
Specified by:
validateParameters in interface ECCommand
Overrides:
validateParameters in class AbstractECTargetableCommand
Throws:
ECException - if either a require parameter was not specified or a specified parameter has an invalid value.