Class BaseScheduler
java.lang.Object
ortus.boxlang.runtime.async.tasks.BaseScheduler
- All Implemented Interfaces:
IScheduler
- Direct Known Subclasses:
BoxScheduler
The Async Scheduler is in charge of registering scheduled tasks, starting them, monitoring them and shutting them down if needed.
Each scheduler is bound to an scheduled executor class.
The scheduled executor will be named
{name}-scheduler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AsyncService
The async service we are bound toprotected IBoxContext
The request context that started this schedulerprotected ExecutorRecord
The Scheduled Executor we are bound toprotected final BoxLangLogger
Loggerprotected String
The name of this schedulerprotected Boolean
Is the scheduler started?protected Instant
When the scheduler was startedprotected LinkedHashMap
<String, TaskRecord> An ordered struct of all the tasks this scheduler managesprotected ZoneId
The timezone for the scheduler and the tasks it creates and manages -
Constructor Summary
ConstructorsConstructorDescriptionZero arg constructor with basic defaults: Auto-generated name, system default timezone and the default async serviceBaseScheduler
(String name) Create a new scheduler with a name and the default system timezone.BaseScheduler
(String name, ZoneId timezone) Create a new scheduler with a name and a specific timezoneBaseScheduler
(String name, ZoneId timezone, IBoxContext context) Create a new scheduler with a name and a specific timezoneBaseScheduler
(String name, IBoxContext context) Create a new scheduler with a name and the default system timezone. -
Method Summary
Modifier and TypeMethodDescriptionvoid
afterAnyTask
(ScheduledTask task, Optional<?> result) Called after ANY task runsvoid
beforeAnyTask
(ScheduledTask task) Called before ANY task runsClear all tasks from the scheduler.void
Usually where concrete implementations add their tasks and configsGet the Aysnc ServiceGet the scheduler contextGet the executor recordGet the loggerGet an array of all the tasks managed by this schedulerGet the scheduler nameGet when it was started.getTaskRecord
(String name) Get's a task record from the collection by namegetTasks()
Get the registered tasks in this schedulerBuilds out a report for all the registered tasks in this scheduler.Get the timezoneHas this scheduler been started?boolean
Check if a task is registered in this schedulerIs it running: Alias to hasStarted()void
onAnyTaskError
(ScheduledTask task, Exception exception) Called whenever ANY task failsvoid
onAnyTaskSuccess
(ScheduledTask task, Optional<?> result) Called whenever ANY task succeedsvoid
Called before the scheduler is going to be shutdownvoid
Called after the scheduler has registered all schedulesremoveTask
(String name) Removes a task from the scheduler.restart
(boolean force, long timeout) Restart the scheduler by shutting it down and starting it up againsetContext
(IBoxContext context) Set the scheduler context manuallySet the default timezone into the tasksetExecutor
(ExecutorRecord executor) Set the exectutor record for this schedulersetSchedulerName
(String name) Set the scheduler namesetTimezone
(String timezone) Set the scheduler's timezone as a string, we will convert it to a ZoneId objectsetTimezone
(ZoneId timezone) Set the scheduler's timezoneshutdown()
Shutdown this scheduler by calling the executor to shutdown and disabling all tasks We do not force and we use the default timeoutshutdown
(boolean force) Shutdown this scheduler by calling the executor to shutdown and disabling all tasks using the default timeoutshutdown
(boolean force, long timeout) Shutdown this scheduler by calling the executor to shutdown and disabling all tasksstartup()
Startup this scheduler and all of it's scheduled tasksstartupTask
(String taskName) Startup a specific task by namestartupTask
(ScheduledTask task) Startup manullay the passed in taskRegister a new task in this scheduler that will be executed once the `startup()` is fired or manually via the run() method of the task.Register a new task in this scheduler that will be executed once the `startup()` is fired or manually via the run() method of the task.Register a new task in this scheduler but disable it immediately.Register a new task in this scheduler but disable it immediately.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ortus.boxlang.runtime.async.tasks.IScheduler
getSchedulerNameAsKey
-
Field Details
-
tasks
An ordered struct of all the tasks this scheduler manages -
executor
The Scheduled Executor we are bound to -
timezone
The timezone for the scheduler and the tasks it creates and manages -
asyncService
The async service we are bound to -
started
Is the scheduler started? -
startedAt
When the scheduler was started -
name
The name of this scheduler -
logger
Logger -
context
The request context that started this scheduler
-
-
Constructor Details
-
BaseScheduler
public BaseScheduler()Zero arg constructor with basic defaults: Auto-generated name, system default timezone and the default async service -
BaseScheduler
Create a new scheduler with a name and the default system timezone.- Parameters:
name
- The name of the scheduler
-
BaseScheduler
Create a new scheduler with a name and the default system timezone.- Parameters:
name
- The name of the schedulercontext
- The context that started this scheduler
-
BaseScheduler
Create a new scheduler with a name and a specific timezone- Parameters:
name
- The name of the schedulertimezone
- The timezone for the scheduler and the tasks it creates and manages
-
BaseScheduler
Create a new scheduler with a name and a specific timezone- Parameters:
name
- The name of the schedulertimezone
- The timezone for the scheduler and the tasks it creates and managescontext
- The context that started this scheduler
-
-
Method Details
-
setContext
Set the scheduler context manually -
getContext
Get the scheduler context -
configure
public void configure()Usually where concrete implementations add their tasks and configs- Specified by:
configure
in interfaceIScheduler
-
xtask
Register a new task in this scheduler but disable it immediately. This is useful when debugging tasks and have the easy ability to disable them.- Parameters:
name
- The name of this task- Returns:
- The registered and disabled Scheduled Task
-
xtask
Register a new task in this scheduler but disable it immediately. This is useful when debugging tasks and have the easy ability to disable them.- Parameters:
name
- The name of this taskgroup
- The group of this task- Returns:
- The registered and disabled Scheduled Task
-
task
Register a new task in this scheduler that will be executed once the `startup()` is fired or manually via the run() method of the task. The group will be empty.- Parameters:
name
- The name of this task- Returns:
- a ScheduledTask object so you can work on the registration of the task
-
task
Register a new task in this scheduler that will be executed once the `startup()` is fired or manually via the run() method of the task.- Parameters:
name
- The name of this task- Returns:
- a ScheduledTask object so you can work on the registration of the task
-
startup
Startup this scheduler and all of it's scheduled tasks- Specified by:
startup
in interfaceIScheduler
-
restart
Restart the scheduler by shutting it down and starting it up again- Specified by:
restart
in interfaceIScheduler
- Parameters:
force
- If true, it forces all shutdowns this is usually true when doing reinitstimeout
- The timeout in seconds to wait for the shutdown of all tasks, defaults to 30 or whatever you set using the setShutdownTimeout()- Returns:
-
clearTasks
Clear all tasks from the scheduler. Usually done by a restart- Returns:
- The scheduler object
-
startupTask
Startup manullay the passed in task- Parameters:
task
- The task to startup- Returns:
- The task record
-
startupTask
Startup a specific task by name- Parameters:
taskName
- The name of the task- Returns:
- The task record
-
shutdown
Shutdown this scheduler by calling the executor to shutdown and disabling all tasks- Specified by:
shutdown
in interfaceIScheduler
- Parameters:
force
- If true, it forces all shutdowns this is usually true when doing reinitstimeout
- The timeout in seconds to wait for the shutdown of all tasks, defaults to 30 or whatever you set using the setShutdownTimeout() method
-
shutdown
Shutdown this scheduler by calling the executor to shutdown and disabling all tasks using the default timeout- Specified by:
shutdown
in interfaceIScheduler
- Parameters:
force
- If true, it forces all shutdowns this is usually true when doing reinits- Returns:
- The scheduler object
-
shutdown
Shutdown this scheduler by calling the executor to shutdown and disabling all tasks We do not force and we use the default timeout- Specified by:
shutdown
in interfaceIScheduler
- Returns:
- The scheduler object
-
onShutdown
public void onShutdown()Called before the scheduler is going to be shutdown- Specified by:
onShutdown
in interfaceIScheduler
-
onStartup
public void onStartup()Called after the scheduler has registered all schedules- Specified by:
onStartup
in interfaceIScheduler
-
onAnyTaskError
Called whenever ANY task fails- Specified by:
onAnyTaskError
in interfaceIScheduler
- Parameters:
task
- The task that got executedexception
- The exception object
-
onAnyTaskSuccess
Called whenever ANY task succeeds- Specified by:
onAnyTaskSuccess
in interfaceIScheduler
- Parameters:
task
- The task that got executedresult
- The result (if any) that the task produced
-
beforeAnyTask
Called before ANY task runs- Specified by:
beforeAnyTask
in interfaceIScheduler
- Parameters:
task
- The task about to be executed
-
afterAnyTask
Called after ANY task runs- Specified by:
afterAnyTask
in interfaceIScheduler
- Parameters:
task
- The task that got executedresult
- The result (if any) that the task produced
-
getTaskStats
Builds out a report for all the registered tasks in this scheduler. The key is the task name and the value is a struct with the task stats.- Specified by:
getTaskStats
in interfaceIScheduler
- Returns:
- A struct with the report:
{ taskName: { stats } }
-
getRegisteredTasks
Get an array of all the tasks managed by this scheduler -
hasTask
Check if a task is registered in this scheduler- Parameters:
name
- The name of the task- Returns:
- true if registered, false if not
-
getTaskRecord
Get's a task record from the collection by name- Parameters:
name
- The name of the task- Returns:
- The task record object
-
removeTask
Removes a task from the scheduler. It tries to cancel the task first and then removes it from the scheduler. if the task has a future, then it will try to cancel it with interrupt.- Parameters:
name
- The name of the task- Returns:
- The scheduler object
-
getTasks
Get the registered tasks in this scheduler- Returns:
- the tasks
-
hasStarted
Has this scheduler been started?- Specified by:
hasStarted
in interfaceIScheduler
- Returns:
- true if started, false if not
-
isRunning
Is it running: Alias to hasStarted()- Returns:
- true if running, false if not
-
getStartedAt
Get when it was started. If not started, then it will return null -
getSchedulerName
Get the scheduler name- Specified by:
getSchedulerName
in interfaceIScheduler
- Returns:
- the name
-
setSchedulerName
Set the scheduler name- Specified by:
setSchedulerName
in interfaceIScheduler
- Parameters:
name
- the name to set- Returns:
- the scheduler object
-
getTimezone
Get the timezone- Specified by:
getTimezone
in interfaceIScheduler
- Returns:
- the timezone
-
setTimezone
Set the scheduler's timezone- Specified by:
setTimezone
in interfaceIScheduler
- Parameters:
timezone
- the timezone to set- Returns:
- the scheduler object
-
setTimezone
Set the scheduler's timezone as a string, we will convert it to a ZoneId object- Parameters:
timezone
- the timezone to set as a string
-
setDefaultTimezone
Set the default timezone into the task- Returns:
- Scheduler
-
getAsyncService
Get the Aysnc Service- Returns:
- the asyncService
-
setExecutor
Set the exectutor record for this scheduler- Parameters:
executor
- the executor to set- Returns:
- the scheduler object
-
getExecutor
Get the executor record- Returns:
- the executor record
-
getLogger
Get the logger
-