Class CronJob

  • All Implemented Interfaces:
    java.lang.Runnable

    public class CronJob
    extends java.lang.Thread
    Job associated with one method of object
    Job is launched by the CronTable or by one asynchronous Action
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • 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)
      Job constructor
      CronJob​(ObjectDB object, Action action, Grant grant, java.util.Map<java.lang.String,​java.lang.String> params)
      Job constructor
    • Method Summary

      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()  
      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.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
      void run()
      Launch the Job
      static void setStatus​(ObjectDB obj, java.lang.String status)
      Set the status of the current CronJob thread
      static java.lang.String updateStatus​(Grant g, java.lang.String jobRowId, java.lang.String status)
      Update the AsyncJob status and the start/end dates
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, 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)
        Job constructor
        Parameters:
        object - Object
        action - Action to call in a new thread
        grant - User rights
      • 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 action parameters
    • Method Detail

      • clearCache

        public static void clearCache()
      • 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
      • updateStatus

        public static java.lang.String updateStatus​(Grant g,
                                                    java.lang.String jobRowId,
                                                    java.lang.String status)
        Update the AsyncJob status and the start/end dates
        Parameters:
        g - Grant
        jobRowId - Job Id
        status - Status
        Returns:
        datetime of update
      • run

        public void run()
        Launch the Job
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • 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 - ObjectDB
        Throws:
        java.lang.InterruptedException - InterruptedException
      • getStatus

        public static java.lang.String getStatus​(ObjectDB obj)
        Get the status of the current CronJob thread
        Parameters:
        obj - ObjectDB
        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 - ObjectDB
        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