Package com.redwood.scheduler.api.job
Interface UserJobContext
- 
- All Superinterfaces:
- ConfigurableSchedulerSessionSource,- com.redwood.scheduler.api.session.RestrictedSchedulerSessionSupport,- SchedulerSessionSource
 
 public interface UserJobContext extends ConfigurableSchedulerSessionSource, com.redwood.scheduler.api.session.RestrictedSchedulerSessionSupport Job context for user defined jobs.
- 
- 
Method SummaryAll Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description booleanaddToCloseList(AutoCloseable o, String name, boolean log)Close the object when the job completes.voidbecomeResilient()When called, the current running Process (jcsJob) is fetched using a newly created session and set to CompletionStrategy Resilient.voidbecomeResilient(SchedulerSession session)Deprecated.This method runs the the risk of the persist failing with a NoRowsUpdatedException in unexpected and non-reproducible ways when the job is also modified in another session.SchedulerSessioncreateSchedulerSession()Create a new SchedulerSession.voidforceCloseListLogging()Force logging of all objects in close list.CompletionStrategyTypegetCompletionStrategy()Get the current completion strategy for this job.JobLoggergetErrorLogger()Get a Logger to log error messages to.PrintWritergetErrorWriter()Get the PrintWriter to write errors to.LonggetJobId()Get the Job Id of the Job.LonggetJobUniqueId()Get the Unique Id of the Job, this is not the same as the JobId.JobLoggergetOutputLogger()Get a Logger to log output messages to.PrintWritergetOutputWriter()Get the PrintWriter to write output to.StringgetSystemId()Get the current system id.Map<String,Object>getThreadState()Get the ThreadState map shared between REL and RedwoodScript during the execution of this job.voidkillJobWithParent(Job job)When this method is called, the child jobs will be killed when the given parent job is killed (the default is not).default Iterable<Job>loopOverNextJobChainStep(SchedulerSession session, RTXProducer producer)Loop over the next step in the current job chain.default Iterable<Job>loopOverNextJobChainStep(SchedulerSession session, RTXProducer producer, String jobDescription)Loop over the next step in the current job chain.default Iterable<Job>loopOverNextJobChainStep(SchedulerSession session, RTXProducer producer, Predicate<RTXRow> filter)Loop over the next step in the current job chain.Iterable<Job>loopOverNextJobChainStep(SchedulerSession session, RTXProducer producer, Predicate<RTXRow> filter, String jobDescription)Loop over the next step in the current job chain.default Iterable<Job>loopOverNextJobChainStep(SchedulerSession session, RTXReader reader)default Iterable<Job>loopOverNextJobChainStep(SchedulerSession session, RTXReader reader, Predicate<RTXRow> filter)voidoperatorMessage(SchedulerSession session, String message)Insert an operator message in the operator messages table Note that persist() will be calledStringoperatorMessage(SchedulerSession session, String message, String replyExpression)Insert an operator message in the operator messages table and wait until a reply is given.voidoperatorMessage(String message)Insert an operator message in the operator messages tableStringoperatorMessage(String message, String replyExpression)Insert an operator message in the operator messages table and wait until a reply is given.<T extends Exception>
 voidperformUnitOfWork(SchedulerSessionUnitOfWork<T> uow)Perform a unit of work, by calling it with a new session.voidsetCompletionStrategy(CompletionStrategyType newStrategy)Set the completion strategy for this job.voidsetJobOutputParameter(String name, Object value)Set the current (in-memory) value of an output parameter.voidsetMaxRetries(int newMaxRetries)Deprecated.This can be configured with the UnitOfWorkConfig and should not be used.voidsetMaxSpins(int newMaxSpins)Deprecated.This can be configured with the UnitOfWorkConfig and should not be used.voidsetReturnCode(long newReturnCode)Set the job return code.voidsetReturnCode(Long newReturnCode)Set the job return code.voidwaitForAllChildJobsExternalCompletionStrategy()The current job will have its strategy set to external and will remain running until its child jobs finish.voidwaitForAllChildren(SchedulerSession session)Wait for all children to finish.voidwaitForJob(SchedulerSession session, Job job)Wait for another job to finish.voidwaitForJobs(SchedulerSession session, Job[] jobs)Wait for all the specified jobs to finish.voidwaitForJobs(SchedulerSession session, Job[] jobs, JobStatus[] statuses, long maxWait)Wait for jobs to reach the specified statuses, with a maximum wait time.StringwaitForReply(OperatorMessage om)Wait for a reply to an operator message raised by this job.- 
Methods inherited from interface com.redwood.scheduler.api.uow.ConfigurableSchedulerSessionSourcegetMaxRetries, getMaxSpins
 
- 
 
- 
- 
- 
Method Detail- 
createSchedulerSessionSchedulerSession createSchedulerSession() Create a new SchedulerSession.- Specified by:
- createSchedulerSessionin interface- SchedulerSessionSource
- Returns:
- a new Scheduler Session.
 
 - 
getOutputLoggerJobLogger getOutputLogger() Get a Logger to log output messages to. Avoid mixing this with calls to the PrintWriter returned by getLogWriter.- Returns:
- a logger.
 
 - 
getOutputWriterPrintWriter getOutputWriter() Get the PrintWriter to write output to.- Returns:
- the PrintWriter.
 
 - 
getErrorLoggerJobLogger getErrorLogger() Get a Logger to log error messages to. Avoid mixing this with calls to the PrintWriter returned by getLogWriter.- Returns:
- a logger.
 
 - 
getErrorWriterPrintWriter getErrorWriter() Get the PrintWriter to write errors to.- Returns:
- the PrintWriter.
 
 - 
operatorMessagevoid operatorMessage(SchedulerSession session, String message) throws com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException Insert an operator message in the operator messages table Note that persist() will be called- Parameters:
- session- the SchedulerSession
- message- the message to the operator
- Throws:
- com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException- if the message could not be written
 
 - 
operatorMessagevoid operatorMessage(String message) throws com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException Insert an operator message in the operator messages table- Parameters:
- message- the message to the operator
- Throws:
- com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException- if the message could not be written
 
 - 
operatorMessageString operatorMessage(SchedulerSession session, String message, String replyExpression) throws com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException, InterruptedException Insert an operator message in the operator messages table and wait until a reply is given. Note that persist() will be called- Parameters:
- session- the SchedulerSession
- message- the message to the operator
- replyExpression- a regular expression to which the reply should match, or null for any reply
- Returns:
- the reply
- Throws:
- InterruptedException- if the thread is interrupted
- com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException- if the message could not be written
 
 - 
operatorMessageString operatorMessage(String message, String replyExpression) throws com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException, InterruptedException Insert an operator message in the operator messages table and wait until a reply is given.- Parameters:
- message- the message to the operator
- replyExpression- a regular expression to which the reply should match, or null for any reply
- Returns:
- the reply
- Throws:
- InterruptedException- if the thread is interrupted
- com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException- if the message could not be written
 
 - 
waitForReplyString waitForReply(OperatorMessage om) throws com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException, InterruptedException Wait for a reply to an operator message raised by this job.- Parameters:
- om- the operator message to wait for.
- Returns:
- the reply
- Throws:
- com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException- if the job could not be set to Console
- InterruptedException- if the thread is interrupted
 
 - 
setReturnCodevoid setReturnCode(Long newReturnCode) Set the job return code. This will be set regardless of the final state of the job (Completed or Error).- Parameters:
- newReturnCode- the new value for return code. Set to null not to set a return code.
 
 - 
setReturnCodevoid setReturnCode(long newReturnCode) Set the job return code. This will be set regardless of the final state of the job (Completed or Error).- Parameters:
- newReturnCode- the new value for return code. Set to null not to set a return code.
 
 - 
waitForJobvoid waitForJob(SchedulerSession session, Job job) Wait for another job to finish. This may be implemented by the dispatcher (ie. more efficient than a busy wait).- Parameters:
- session- the session the jobs came from.
- job- the job to wait for.
 
 - 
waitForJobsvoid waitForJobs(SchedulerSession session, Job[] jobs) Wait for all the specified jobs to finish. This may be implemented by the dispatcher (ie. more efficient than a busy wait).- Parameters:
- session- the session the jobs came from.
- jobs- the jobs to wait for.
 
 - 
waitForJobsvoid waitForJobs(SchedulerSession session, Job[] jobs, JobStatus[] statuses, long maxWait) Wait for jobs to reach the specified statuses, with a maximum wait time. This will always be implemented as a busy wait.- Parameters:
- session- the session to use for waiting (to refresh objects).
- jobs- the jobs to wait for, must be from session.
- statuses- the statuses to wait for.
- maxWait- the maximum time (in milliseconds) to wait.
 
 - 
waitForAllChildrenvoid waitForAllChildren(SchedulerSession session) Wait for all children to finish. This may be implemented by the dispatcher (ie. more efficient than a busy wait).- Parameters:
- session- the session the jobs came from.
 
 - 
setCompletionStrategyvoid setCompletionStrategy(CompletionStrategyType newStrategy) Set the completion strategy for this job. The default completion strategy is to set the job into Completed or Error depending on the return code and whether the job throws an exception. Other completion strategies allow for an external entity to set the final status of the job, after the job's thread has finished. This call should be made at the end of the job.- Parameters:
- newStrategy- the completion strategy to use.
 
 - 
getCompletionStrategyCompletionStrategyType getCompletionStrategy() Get the current completion strategy for this job. This will returnCompletionStrategyType.Defaultif no specific completion strategy has been set, otherwise the value last set bysetCompletionStrategy(CompletionStrategyType).- Returns:
- the current completion strategy.
 
 - 
setJobOutputParametervoid setJobOutputParameter(String name, Object value) Set the current (in-memory) value of an output parameter. This value will be written to the database when the job completes.- Parameters:
- name- the parameter name
- value- the value
 
 - 
getJobUniqueIdLong getJobUniqueId() Get the Unique Id of the Job, this is not the same as the JobId.- Returns:
- the Unique Id of the job.
 
 - 
getJobIdLong getJobId() Get the Job Id of the Job.- Returns:
- the Unique Id of the job.
 
 - 
addToCloseListboolean addToCloseList(AutoCloseable o, String name, boolean log) Close the object when the job completes.- Parameters:
- o- the object to close.
- name- the name of the object.
- log- should information about this object be logged by default.
- Returns:
- true if the object was added, false if it was not closable.
 
 - 
forceCloseListLoggingvoid forceCloseListLogging() Force logging of all objects in close list.
 - 
getSystemIdString getSystemId() Get the current system id.- Returns:
- the current system id.
 
 - 
setMaxRetries@Deprecated void setMaxRetries(int newMaxRetries) Deprecated.This can be configured with the UnitOfWorkConfig and should not be used.Set the maximum number of retries for units of work.- Parameters:
- newMaxRetries- the new maximum number of retries, must be > 1.
 
 - 
setMaxSpins@Deprecated void setMaxSpins(int newMaxSpins) Deprecated.This can be configured with the UnitOfWorkConfig and should not be used.Set the maximum number of spins for units of work.- Parameters:
- newMaxSpins- the new maximum number of spins, must be > 1.
 
 - 
performUnitOfWork<T extends Exception> void performUnitOfWork(SchedulerSessionUnitOfWork<T> uow) throws com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException, T extends Exception Perform a unit of work, by calling it with a new session. If the initial call fails with a no rows updated exception, call it again with a new session. If it fails with any other exception, or fails too many times with no rows updated, throw the last exception thrown. Retries can be configured withsetMaxRetries(int).- Parameters:
- uow- the unit of work to perform. Generic in the type of Exception its performWork method it throws. See- SchedulerSessionUnitOfWorkfor the problems with using a raw type here.
- Throws:
- com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException- if the unit of work fails with a no rows updated exception maxretries times.
- T- if the unit of work throws an exception.
- T extends Exception
 
 - 
waitForAllChildJobsExternalCompletionStrategyvoid waitForAllChildJobsExternalCompletionStrategy() The current job will have its strategy set to external and will remain running until its child jobs finish. When the children are completed (or any other final state) the current job will finish (to completed if all children are completed or error for any other final state of a child). This method will return immediately. This call is only usable within RedwoodScript and must be the *last* statement of the script.
 - 
killJobWithParentvoid killJobWithParent(Job job) When this method is called, the child jobs will be killed when the given parent job is killed (the default is not). Make sure to persist after to have the change applied.- Parameters:
- job- The parent job to apply this to
 
 - 
becomeResilientvoid becomeResilient() throws com.redwood.scheduler.api.exception.SchedulerAPIPersistenceExceptionWhen called, the current running Process (jcsJob) is fetched using a newly created session and set to CompletionStrategy Resilient. This session is then persisted using a UnitOfWork, meaning it will retry in case of failure due to a concurrent change to the Process. Because the persist happens in a session created in this method, callers need to refresh jcsJob *after* this call or will run into NoRowsUpdatedExceptions.- Throws:
- com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException- On failure of persist
 
 - 
becomeResilient@Deprecated void becomeResilient(SchedulerSession session) throws com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException Deprecated.This method runs the the risk of the persist failing with a NoRowsUpdatedException in unexpected and non-reproducible ways when the job is also modified in another session. UsebecomeResilient(), which doesn't take a session argument and persists using a UnitOfWork in its own session, instead.When called, it sets the current running Process (jcsJob) to CompletionStrategy Resilient, this uses passed-in session to persist.- Parameters:
- session- the session to use.
- Throws:
- com.redwood.scheduler.api.exception.SchedulerAPIPersistenceException- On failure of persist
 
 - 
loopOverNextJobChainStepIterable<Job> loopOverNextJobChainStep(SchedulerSession session, RTXProducer producer, Predicate<RTXRow> filter, String jobDescription) throws Exception Loop over the next step in the current job chain. The following preconditions must be true:- The current job is in a job chain, and must be the only job in its step.
- The next step must have exactly one job in it.
- The producermust return at least one row, after being filtered byfilter.
 - Confirm the current job and the next step in the chain meet the preconditions.
- The first row in the producerwill be mapped onto the first job in the next step.
- Additional jobs will be created based on the first job for subsequent rows from the producer.
 - Parameters:
- session- the session to use.
- producer- the reader to get data from.
- filter- a filter for the rows, returns true to process the current row, may change state from- getThreadState().
- jobDescription- optional RTXRow REL Expression, if supplied will define the description of the looped jobs.
- Returns:
- the jobs in the next step.
- Throws:
- Exception- if an error occurs.
 
 - 
loopOverNextJobChainStepdefault Iterable<Job> loopOverNextJobChainStep(SchedulerSession session, RTXProducer producer, Predicate<RTXRow> filter) throws Exception Loop over the next step in the current job chain. The following preconditions must be true:- The current job is in a job chain, and must be the only job in its step.
- The next step must have exactly one job in it.
- The producermust return at least one row, after being filtered byfilter.
 - Confirm the current job and the next step in the chain meet the preconditions.
- The first row in the producerwill be mapped onto the first job in the next step.
- Additional jobs will be created based on the first job for subsequent rows from the producer.
 - Parameters:
- session- the session to use.
- producer- the reader to get data from.
- filter- a filter for the rows, returns true to process the current row, may change state from- getThreadState().
- Returns:
- the jobs in the next step.
- Throws:
- Exception- if an error occurs.
 
 - 
loopOverNextJobChainStepdefault Iterable<Job> loopOverNextJobChainStep(SchedulerSession session, RTXProducer producer, String jobDescription) throws Exception Loop over the next step in the current job chain. The following preconditions must be true:- The current job is in a job chain, and must be the only job in its step.
- The next step must have exactly one job in it.
- The producermust return at least one row, after being filtered byfilter.
 - Confirm the current job and the next step in the chain meet the preconditions.
- The first row in the producerwill be mapped onto the first job in the next step.
- Additional jobs will be created based on the first job for subsequent rows from the producer.
 - Parameters:
- session- the session to use.
- producer- the reader to get data from.
- jobDescription- optional RTXRow REL Expression, if supplied will define the description of the looped jobs.
- Returns:
- the jobs in the next step.
- Throws:
- Exception- if an error occurs.
 
 - 
loopOverNextJobChainStepdefault Iterable<Job> loopOverNextJobChainStep(SchedulerSession session, RTXProducer producer) throws Exception Loop over the next step in the current job chain. The following preconditions must be true:- The current job is in a job chain, and must be the only job in its step.
- The next step must have exactly one job in it.
- The producermust return at least one row, after being filtered byfilter.
 - Confirm the current job and the next step in the chain meet the preconditions.
- The first row in the producerwill be mapped onto the first job in the next step.
- Additional jobs will be created based on the first job for subsequent rows from the producer.
 - Parameters:
- session- the session to use.
- producer- the reader to get data from.
- Returns:
- the jobs in the next step.
- Throws:
- Exception- if an error occurs.
 
 - 
loopOverNextJobChainStepdefault Iterable<Job> loopOverNextJobChainStep(SchedulerSession session, RTXReader reader) throws Exception - Parameters:
- session-
- reader-
- Returns:
- the jobs in the next step.
- Throws:
- Exception
- See Also:
- loopOverNextJobChainStep(SchedulerSession, RTXProducer)
 
 - 
loopOverNextJobChainStepdefault Iterable<Job> loopOverNextJobChainStep(SchedulerSession session, RTXReader reader, Predicate<RTXRow> filter) throws Exception - Parameters:
- session- the session to use.
- reader- the reader to get data from.
- filter- a filter for the rows, returns true to process the current row, may change state from- getThreadState().
- Returns:
- the jobs in the next step.
- Throws:
- Exception- if an error occurs.
- Exception
- See Also:
- loopOverNextJobChainStep(SchedulerSession, RTXProducer, Predicate)
 
 
- 
 
-