Class SchedulerService


  • @DeclareRoles("org.imixs.ACCESSLEVEL.MANAGERACCESS")
    @RunAs("org.imixs.ACCESSLEVEL.MANAGERACCESS")
    public class SchedulerService
    extends Object
    The SchedulerService EJB can be used to start, monitor and stop custom scheduler implementation. A Scheduler Implementation must implement the Interface "org.imixs.workflow.engine.scheduler.Scheduler".

    A scheduler definition is stored in a document with the type "scheduler". The document can provide concrete information to process the timer event.

    The TimerService can be started using the method start(). The Methods findTimerDescription and findAllTimerDescriptions are used to lookup enabled and running service instances.

    Each Method expects or generates a TimerDescription Object. This object is an instance of a ItemCollection. To create a new timer the ItemCollection should contain the following attributes:

    • type - fixed to value 'scheduler'
    • _scheduler_definition - the chron/calendar definition for the Java EE timer service.
    • _scheduler_enabled - boolean indicates if the scheduler is enabled/disabled
    • _scheduler_class - class name of the scheduler implementation
    • _scheduelr_log - optional log information

    the following additional attributes are generated by the finder methods and can be used by an application to verfiy the status of a running instance:

    • nextTimeout - Next Timeout - pint of time when the service will be scheduled
    • timeRemaining - Timeout in milliseconds
    • statusmessage - text message
    Version:
    1.0
    Author:
    rsoika
    • Constructor Detail

      • SchedulerService

        public SchedulerService()
    • Method Detail

      • loadConfiguration

        public ItemCollection loadConfiguration​(String name)
        Loads the scheduler configuration entity by name. The method returns null if no scheduler configuration exits.
        Returns:
      • saveConfiguration

        public ItemCollection saveConfiguration​(ItemCollection configItemCollection)
        This method saves the scheduler configuration. The method ensures that the following properties are set to default.
        • type
        • name
        • $writeAccess
        • $readAccess
        The method also updates the timer details of a running timer.
        Returns:
        Throws:
        AccessDeniedException
      • start

        public ItemCollection start​(ItemCollection configuration)
                             throws AccessDeniedException,
                                    ParseException
        Starts a new Timer for the scheduler defined by the Configuration.

        The Timer can be started based on a Calendar setting stored in the property _scheduler_definition.

        The $UniqueID of the configuration entity is the id of the timer to be controlled.

        The method throws an exception if the configuration entity contains invalid attributes or values.

        After the timer was started the configuration is updated with the latest statusmessage. The item _schedueler_enabled will be set to 'true'.

        The method returns the updated configuration. The configuration will not be saved!

        Parameters:
        configuration - - scheduler configuration
        Returns:
        updated configuration
        Throws:
        AccessDeniedException
        ParseException
      • stop

        public ItemCollection stop​(ItemCollection configuration)
        Cancels a running timer instance. After cancel a timer the corresponding timerDescripton (ItemCollection) is no longer valid.

        The method returns the current configuration. The configuration will not be saved!

      • startAllSchedulers

        public void startAllSchedulers()
        This method will start all schedulers which are not yet started. The method is called for example by the SchedulerStartupServlet.
      • findTimer

        public jakarta.ejb.Timer findTimer​(String id)
        This method returns a timer for a corresponding id if such a timer object exists.
        Parameters:
        id -
        Returns:
        Timer
        Throws:
        Exception
      • updateTimerDetails

        public void updateTimerDetails​(ItemCollection configuration)
        Updates the timer details of a running timer service. The method updates the properties netxtTimeout and timeRemaining and store them into the timer configuration.
        Parameters:
        configuration - - the current scheduler configuration to be updated.
      • logMessage

        public void logMessage​(String message,
                               ItemCollection configuration,
                               ItemCollection workitem)
        Creates a new log entry stored in the item _scheduler_log. The log can be writen optional to the scheduler configuration and a workitem.
        Parameters:
        message -
        configuration -
      • logWarning

        public void logWarning​(String message,
                               ItemCollection configuration,
                               ItemCollection workitem)
        Creates a new log entry stored in the item _scheduler_log. The log can be writen optional to the scheduler configuration and a workitem.
        Parameters:
        message -
        configuration -
      • findSchedulerByName

        protected Scheduler findSchedulerByName​(String schedulerClassName)
        This method returns a n injected JobHandler by name or null if no JobHandler with the requested class name is injected.
        Parameters:
        jobHandlerClassName -
        Returns:
        jobHandler class or null if not found
      • onTimeout

        protected void onTimeout​(jakarta.ejb.Timer timer)
        This is the method which processes the timeout event depending on the running timer settings. The method calls the abstract method 'process' which need to be implemented by a subclass.
        Parameters:
        timer -
        Throws:
        Exception
        QueryException
      • createTimerOnCalendar

        protected jakarta.ejb.Timer createTimerOnCalendar​(ItemCollection configItemCollection)
                                                   throws ParseException
        Create a calendar-based timer based on a input schedule expression. The expression will be parsed by this method. Example: second=0 minute=0 hour=* dayOfWeek= dayOfMonth= month= year=*
        Parameters:
        sConfiguation -
        Returns:
        Throws:
        ParseException