Class SchedulerService

java.lang.Object
ortus.boxlang.runtime.services.BaseService
ortus.boxlang.runtime.services.SchedulerService
All Implemented Interfaces:
IService

public class SchedulerService extends BaseService
This service manages all schedulers in the system.
  • Field Details

    • DEFAULT_SHUTDOWN_TIMEOUT

      public static final long DEFAULT_SHUTDOWN_TIMEOUT
      The default shutdown timeout for the scheduler service
      See Also:
  • Constructor Details

    • SchedulerService

      public SchedulerService(BoxRuntime runtime)
      Constructor
      Parameters:
      runtime - The BoxRuntime
  • Method Details

    • onConfigurationLoad

      public void onConfigurationLoad()
      The configuration load event is fired when the runtime loads the configuration
      Specified by:
      onConfigurationLoad in interface IService
      Specified by:
      onConfigurationLoad in class BaseService
    • onStartup

      public void onStartup()
      The startup event is fired when the runtime starts up
      Specified by:
      onStartup in interface IService
      Specified by:
      onStartup in class BaseService
    • registerGlobalSchedulers

      public void registerGlobalSchedulers()
      Register all global schedulers found in the boxlang.json config
    • onShutdown

      public void onShutdown(Boolean force)
      The shutdown event is fired when the runtime shuts down
      Specified by:
      onShutdown in interface IService
      Specified by:
      onShutdown in class BaseService
      Parameters:
      force - If true, forces the shutdown of the scheduler
    • startupRegisteredSchedulers

      public SchedulerService startupRegisteredSchedulers()
      Startup all the registered schedulers This is called by the runtime when it starts up
    • startupScheduler

      public SchedulerService startupScheduler(IScheduler scheduler)
      Start a scheduler if not started already
      Parameters:
      scheduler - The scheduler to start
      Returns:
      Scheduler
    • getSchedulers

      public Map<Key,IScheduler> getSchedulers()
      Get all schedulers
      Returns:
      The schedulers
    • getSchedulerNames

      public Array getSchedulerNames()
      Get all the registered scheduler names as a BoxLang Array
    • getScheduler

      public IScheduler getScheduler(Key name)
      Get a scheduler by name
      Parameters:
      name - The name of the scheduler
      Returns:
      The scheduler or null if not found
    • getSchedulerOrFail

      public IScheduler getSchedulerOrFail(Key name)
      Get a scheduler or fail the call with an exception if it does not exist
      Parameters:
      name - The name of the scheduler
      Returns:
      The scheduler
      Throws:
      BoxRuntimeException - If the scheduler is not found
    • getSchedulerStats

      public IStruct getSchedulerStats(Key name)
      Get a single scheduler task stats
      Parameters:
      name - The name of the scheduler
      Returns:
      The scheduler task stats
      Throws:
      BoxRuntimeException - If the scheduler is not found
    • getSchedulerStats

      public IStruct getSchedulerStats()
      Get all scheduler task stats
      Returns:
      A struct with all the scheduler task stats
    • size

      public int size()
      How many schedulers do we have registered
      Returns:
      The number of schedulers
    • hasScheduler

      public boolean hasScheduler(Key name)
      Do we have a scheduler by this name?
      Parameters:
      name - The name of the scheduler
    • registerScheduler

      public IScheduler registerScheduler(IScheduler scheduler)
      Register a scheduler with the service
      Parameters:
      scheduler - The IScheduler to register
      Returns:
      The scheduler
      Throws:
      BoxRuntimeException - If a scheduler with the same name already exists
    • registerAndStartScheduler

      public IScheduler registerAndStartScheduler(IScheduler scheduler, Boolean force)
      Register a scheduler with the service
      Parameters:
      scheduler - The IScheduler to register
      force - If true, forces the registration of the scheduler
      Returns:
      The scheduler
      Throws:
      BoxRuntimeException - If a scheduler with the same name already exists but force is false
    • registerScheduler

      public IScheduler registerScheduler(IScheduler scheduler, Boolean force)
      Register a scheduler with the service
      Parameters:
      scheduler - The IScheduler to register
      force - If true, forces the registration of the scheduler
      Returns:
      The scheduler
      Throws:
      BoxRuntimeException - If a scheduler with the same name already exists but force is false
    • loadScheduler

      public IScheduler loadScheduler(Key name, IScheduler scheduler)
      This method is used to load a scheduler into the service. If the scheduler already exists, it will be replaced. This is usually used from the ModuleService to load a module scheduler
      Parameters:
      name - The name of the scheduler
      scheduler - The IScheduler to load
      Returns:
    • removeScheduler

      public boolean removeScheduler(Key name, boolean force, long timeout)
      Remove a scheduler from the service. This will also shutdown the scheduler.
      Parameters:
      name - The name of the scheduler
      force - If true, forces the shutdown of the scheduler
      timeout - The timeout in milliseconds to wait for the scheduler to shutdown
      Returns:
      True if the scheduler was removed, false if it was not found
    • removeScheduler

      public boolean removeScheduler(Key name)
      Remove a scheduler from the service. This will also shutdown the scheduler gracefully
      Parameters:
      name - The name of the scheduler
      Returns:
      True if the scheduler was removed, false if it was not found
    • clearSchedulers

      public SchedulerService clearSchedulers(Boolean force, Long timeout)
      Clear all schedulers from the service. This will also shutdown all the schedulers
      Parameters:
      force - If true, forces the shutdown of the scheduler
      timeout - The timeout in milliseconds to wait for the scheduler to shutdown
    • restartScheduler

      public SchedulerService restartScheduler(Key name, boolean force, long timeout)
      Restart the scheduler if it exists
      Parameters:
      name - The name of the scheduler
      force - If true, forces the shutdown of the scheduler
      timeout - The timeout in milliseconds to wait for the scheduler to shutdown
      Throws:
      BoxRuntimeException - If the scheduler is not found
    • restartScheduler

      public SchedulerService restartScheduler(Key name)
      Restart the scheduler if it exists. Not forced
      Parameters:
      name - The name of the scheduler
      Throws:
      BoxRuntimeException - If the scheduler is not found
    • shutdownScheduler

      public void shutdownScheduler(IScheduler scheduler, boolean force, long timeout)
      Shutdown the scheduler
      Parameters:
      scheduler - The scheduler to shutdown
      force - If true, forces the shutdown of the scheduler
      timeout - The timeout in seconds to wait for the scheduler to shutdown
    • shutdownScheduler

      public void shutdownScheduler(Key scheduler, boolean force, long timeout)
      Shutdown the scheduler
      Parameters:
      scheduler - The scheduler name to shutdown
      force - If true, forces the shutdown of the scheduler
      timeout - The timeout in seconds to wait for the scheduler to shutdown