Package com.simplicite.util
Class CronJob
- java.lang.Object
-
- com.simplicite.util.engine.JobQueue.Job
-
- com.simplicite.util.CronJob
-
public class CronJob extends com.simplicite.util.engine.JobQueue.Job
Job associated with one method of object
Job is launched by the CronTable or by one asynchronous Action
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CronJob.JobCallback<B,R>
Job callback interface
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
JOB_STATUS_EXCEPTION
Job has terminated throwing exceptionstatic java.lang.String
JOB_STATUS_INITIAL
Initialized statusstatic java.lang.String
JOB_STATUS_INTERRUPT
Interrupt is requestedstatic java.lang.String
JOB_STATUS_PAUSE
Pause is requestedstatic java.lang.String
JOB_STATUS_RESUME
Resume is requestedstatic java.lang.String
JOB_STATUS_RUNNING
Job is runningstatic java.lang.String
JOB_STATUS_SLEEP
Job is sleepingstatic java.lang.String
JOB_STATUS_STOPPED
Stopped thru interruption exceptionstatic java.lang.String
JOB_STATUS_TERMINATED
Job has terminated
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
checkForInterruptAndStop(ObjectDB obj)
To call periodically in the asynchronous method to throw one InterruptedException
when one user has requested it to stop.static void
clearCache()
Clear cachejava.lang.String
getJobId()
Standard row_id of the Jobjava.lang.String
getJobUid()
Unique key in DB as a String: [thread id]-[timestamp in ms]-[job hash]static java.lang.String
getJobUid(java.lang.Thread t)
Get the job UID of a threadstatic java.util.Map<java.lang.String,java.lang.Long>
getRunningJobs(java.lang.String status)
Running jobs by name with duration from beginning in secondsstatic java.lang.String
getStatus(ObjectDB obj)
Get the status of the current CronJob threadstatic java.lang.String
getStatus(java.lang.String jobId)
Get the status of the current CronJob threadvoid
launch()
Launch the Jobvoid
setCallback(CronJob.JobCallback<java.lang.Boolean,java.lang.String> callback)
Set the callback when the job is donestatic void
setStatus(ObjectDB obj, java.lang.String status)
Set the status of the current CronJob threadstatic java.lang.String
updateStatus(java.lang.String jobRowId, java.lang.String status)
Update the AsyncJob status and the start/end dates
-
-
-
Field Detail
-
JOB_STATUS_INITIAL
public static final java.lang.String JOB_STATUS_INITIAL
Initialized status- See Also:
- Constant Field Values
-
JOB_STATUS_RUNNING
public static final java.lang.String JOB_STATUS_RUNNING
Job is running- See Also:
- Constant Field Values
-
JOB_STATUS_TERMINATED
public static final java.lang.String JOB_STATUS_TERMINATED
Job has terminated- See Also:
- Constant Field Values
-
JOB_STATUS_EXCEPTION
public static final java.lang.String JOB_STATUS_EXCEPTION
Job has terminated throwing exception- See Also:
- Constant Field Values
-
JOB_STATUS_INTERRUPT
public static final java.lang.String JOB_STATUS_INTERRUPT
Interrupt is requested- See Also:
- Constant Field Values
-
JOB_STATUS_STOPPED
public static final java.lang.String JOB_STATUS_STOPPED
Stopped thru interruption exception- See Also:
- Constant Field Values
-
JOB_STATUS_PAUSE
public static final java.lang.String JOB_STATUS_PAUSE
Pause is requested- See Also:
- Constant Field Values
-
JOB_STATUS_RESUME
public static final java.lang.String JOB_STATUS_RESUME
Resume is requested- See Also:
- Constant Field Values
-
JOB_STATUS_SLEEP
public static final java.lang.String JOB_STATUS_SLEEP
Job is sleeping- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CronJob
public CronJob(CronDefinition def)
Asynchronous constructor on a new job instance of Object and Grant- Parameters:
def
- Cron job definition
-
-
Method Detail
-
clearCache
public static void clearCache()
Clear cache
-
getJobId
public java.lang.String getJobId()
Standard row_id of the Job- Returns:
- job id
-
getJobUid
public java.lang.String getJobUid()
Unique key in DB as a String: [thread id]-[timestamp in ms]-[job hash]- Returns:
- job Unique id
-
getJobUid
public static java.lang.String getJobUid(java.lang.Thread t)
Get the job UID of a thread- Parameters:
t
- A thread- Returns:
- Job UID if match with a CronJob or null
-
updateStatus
public static java.lang.String updateStatus(java.lang.String jobRowId, java.lang.String status)
Update the AsyncJob status and the start/end dates- Parameters:
jobRowId
- Job Idstatus
- Status- Returns:
- datetime of update
-
setCallback
public void setCallback(CronJob.JobCallback<java.lang.Boolean,java.lang.String> callback)
Set the callback when the job is done- Parameters:
callback
- Callback(ok, result)
-
launch
public void launch()
Launch the Job- Overrides:
launch
in classcom.simplicite.util.engine.JobQueue.Job
-
checkForInterruptAndStop
public static void checkForInterruptAndStop(ObjectDB obj) throws java.lang.InterruptedException
To call periodically in the asynchronous method to throw one InterruptedException
when one user has requested it to stop. If this method is never called,
the thread won't be stopped before its end of execution
even if one interruption has been requested by a user
If the caller needs to end properly (without exception),
use only the checkForInterruptRequest method.- Parameters:
obj
- Object- Throws:
java.lang.InterruptedException
- InterruptedException
-
getStatus
public static java.lang.String getStatus(ObjectDB obj)
Get the status of the current CronJob thread- Parameters:
obj
- Object- Returns:
- Status if exists, or null
-
getStatus
public static java.lang.String getStatus(java.lang.String jobId)
Get the status of the current CronJob thread- Parameters:
jobId
- Job ID- Returns:
- Status if exists, or null
-
setStatus
public static void setStatus(ObjectDB obj, java.lang.String status)
Set the status of the current CronJob thread- Parameters:
obj
- Objectstatus
- Status
-
getRunningJobs
public static java.util.Map<java.lang.String,java.lang.Long> getRunningJobs(java.lang.String status)
Running jobs by name with duration from beginning in seconds
-
-