Class 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
    • Constructor Summary

      Constructors 
      Constructor Description
      CronJob​(CronDefinition def)
      Asynchronous constructor on a new job instance of Object and Grant
      CronJob​(ObjectDB object, Action action, Grant grant, java.util.Map<java.lang.String,​java.lang.String> params)
      Job constructor
    • 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 cache
      java.lang.String getJobId()
      Standard row_id of the Job
      java.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 thread
      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
      static java.lang.String getStatus​(ObjectDB obj)
      Get the status of the current CronJob thread
      static java.lang.String getStatus​(java.lang.String jobId)
      Get the status of the current CronJob thread
      void launch()
      Launch the Job
      void setCallback​(CronJob.JobCallback<java.lang.Boolean,​java.lang.String> callback)
      Set the callback when the job is done
      static void setStatus​(ObjectDB obj, java.lang.String status)
      Set the status of the current CronJob thread
      static java.lang.String updateStatus​(java.lang.String jobRowId, java.lang.String status)
      Update the AsyncJob status and the start/end dates
      • Methods inherited from class com.simplicite.util.engine.JobQueue.Job

        getId, getName, getPriority, getThread, setName, setPriority, setRunnable
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
      • CronJob

        public CronJob​(ObjectDB object,
                       Action action,
                       Grant grant,
                       java.util.Map<java.lang.String,​java.lang.String> params)
        Job constructor
        Parameters:
        object - Object
        action - Action to call in a new thread
        grant - User rights
        params - Optional parameters
    • 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 Id
        status - 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 class com.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 - Object
        status - 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