Package org.ametys.plugins.core.schedule
Class Scheduler
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.core.schedule.Scheduler
-
- All Implemented Interfaces:
LogEnabled,Disposable,Initializable,Component,Contextualizable,Serviceable
public class Scheduler extends AbstractLogEnabled implements Component, Initializable, Disposable, Serviceable, Contextualizable
The scheduler component
-
-
Field Summary
Fields Modifier and Type Field Description private static String__QUARTZ_CONFIG_FILE_NAMEThe name of the configuration file for Quartzprivate static String__RIGHT_SCHEDULERThe id of the right to execute actions on tasksprotected Context_contextThe contextprotected CurrentUserProvider_currentUserProviderThe provider of current userprotected ServiceManager_managerThe service managerprotected RightManager_rightManagerThe rights managerprotected RunnableExtensionPoint_runnableEPThe extension point forRunnablesprotected SchedulableExtensionPoint_schedulableEPThe extension point forSchedulablesprotected Scheduler_schedulerThe Quartz schedulerprotected SourceResolver_sourceResolverThe source resolverprotected SQLDatabaseTypeExtensionPoint_sqlDatabaseTypeEPThe sql database type epprotected SQLDataSourceManager_sqlDataSourceManagerThe manager for SQL datasourcesprotected UserHelper_userHelperThe user helperprotected UserManager_userManagerThe user managerstatic StringDATASOURCE_CONFIG_NAMEName of the parameter holding the datasource id for Quartzstatic StringJOB_GROUPThe group name for jobsstatic StringKEY_RUNNABLE_CRONThe key for the runnable cron expressionstatic StringKEY_RUNNABLE_DEACTIVATABLEThe key for the runnable deactivatable propertystatic StringKEY_RUNNABLE_DESCRIPTIONThe key for the runnable descriptionstatic StringKEY_RUNNABLE_FIRE_PROCESSThe key for the runnable fire process propertystatic StringKEY_RUNNABLE_IDThe key for the runnable idstatic StringKEY_RUNNABLE_LABELThe key for the runnable labelstatic StringKEY_RUNNABLE_MODIFIABLEThe key for the runnable modifiable propertystatic StringKEY_RUNNABLE_REMOVABLEThe key for the runnable removable propertystatic StringKEY_RUNNABLE_STARTUP_COMPLETEDThe key for 'run at startup' jobs indicating if the job has already been executed and is now completedstatic StringKEY_RUNNABLE_USERIDENTITYThe key to retrieve theUserIdentitystatic StringKEY_RUNNABLE_VOLATILEThe key for the runnable volatile propertystatic StringKEY_SCHEDULABLE_IDThe key for the id of the schedulable to executestatic StringPARAM_VALUES_PREFIXThe prefix for the parameter values of the runnable job in the job data mapstatic StringROLEThe Avalon Rolestatic StringTRIGGER_GROUPThe group name for triggers
-
Constructor Summary
Constructors Constructor Description Scheduler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void_checkAndCreateTables(String dataSourceId)private Map<String,Object>_edit(String id, String label, String description, Runnable.FireProcess fireProcess, String cron, String schedulableId, boolean isVolatile, Map<String,Object> launchUser, Map<String,String> params)private String_generateUniqueId(String label)private String_getDriverDelegateClass(String dbType)private List<JobKey>_getExecutingJobs()private Map<String,Object>_getTypedParams(Map<String,String> params, String schedulableId)private boolean_isRunningJob(JobKey jobKey, List<JobKey> executingJobs)private Map<String,Object>_jobToJson(JobKey jobKey, List<JobKey> executingJobs)private void_removeVolatileJobs()private JobDataMap_runnableToJobDataMap(Runnable runnable)private Map<String,Object>_schedulableToJson(Schedulable schedulable, boolean isEdition)private void_scheduleConfigurableJobs()private void_triggerRunAtStartupJobs()private void_triggerToJson(Trigger trigger, Map<String,Object> result)Map<String,Object>add(String label, String description, String fireProcess, String cron, String schedulableId, Map<String,Object> launchUser, Map<String,String> params)Adds a new task.Map<String,Object>add(String label, String description, String fireProcess, String cron, String schedulableId, Map<String,String> params)Adds a new task.voidcontextualize(Context context)voiddispose()Map<String,Object>edit(String id, String label, String description, String fireProcess, String cron, Map<String,Object> launchUser, Map<String,String> params)Edits the given task.Map<String,Object>enable(String id, boolean enabled)Enables/disables the given task.Map<String,Object>getEditionConfiguration()Gets the configuration for creating/editing a runnable (so returns all the schedulables and their parameters)Set<JobKey>getJobs()Gets the jobs of the Quartz schedulerMap<String,Object>getParameters(String schedulableId)Gets the parameters of a given schedulableMap<String,Object>getParameterValues(String id)Gets the values of the parameters of the given taskList<Map<String,Object>>getSchedulables()Gets all the schedulables (private or not)SchedulergetScheduler()Get the Quartz schedulerList<Map<String,Object>>getTasksAsJson()Gets all the scheduled tasksList<Map<String,Object>>getTasksInformation(List<String> taskIds)Gets tasks informationvoidinitialize()Map<String,Object>isEnabled(String id)Returns the enabled state of the task.Map<String,Object>isModifiable(String id)Returns true if the given task is modifiable.Map<String,Object>isRunning(String id)Returns the running state of the task.Map<String,Object>remove(String id)Removes the given task.List<Map<String,Object>>removeCompletedTasks()Removes the completed tasksvoidscheduleJob(Runnable runnable)Schedules a jobvoidservice(ServiceManager manager)voidstart()Starts the Quartz scheduler.-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
JOB_GROUP
public static final String JOB_GROUP
The group name for jobs- See Also:
- Constant Field Values
-
TRIGGER_GROUP
public static final String TRIGGER_GROUP
The group name for triggers- See Also:
- Constant Field Values
-
KEY_SCHEDULABLE_ID
public static final String KEY_SCHEDULABLE_ID
The key for the id of the schedulable to execute- See Also:
- Constant Field Values
-
KEY_RUNNABLE_ID
public static final String KEY_RUNNABLE_ID
The key for the runnable id- See Also:
- Constant Field Values
-
KEY_RUNNABLE_LABEL
public static final String KEY_RUNNABLE_LABEL
The key for the runnable label- See Also:
- Constant Field Values
-
KEY_RUNNABLE_DESCRIPTION
public static final String KEY_RUNNABLE_DESCRIPTION
The key for the runnable description- See Also:
- Constant Field Values
-
KEY_RUNNABLE_FIRE_PROCESS
public static final String KEY_RUNNABLE_FIRE_PROCESS
The key for the runnable fire process property- See Also:
- Constant Field Values
-
KEY_RUNNABLE_STARTUP_COMPLETED
public static final String KEY_RUNNABLE_STARTUP_COMPLETED
The key for 'run at startup' jobs indicating if the job has already been executed and is now completed- See Also:
- Constant Field Values
-
KEY_RUNNABLE_CRON
public static final String KEY_RUNNABLE_CRON
The key for the runnable cron expression- See Also:
- Constant Field Values
-
KEY_RUNNABLE_REMOVABLE
public static final String KEY_RUNNABLE_REMOVABLE
The key for the runnable removable property- See Also:
- Constant Field Values
-
KEY_RUNNABLE_MODIFIABLE
public static final String KEY_RUNNABLE_MODIFIABLE
The key for the runnable modifiable property- See Also:
- Constant Field Values
-
KEY_RUNNABLE_DEACTIVATABLE
public static final String KEY_RUNNABLE_DEACTIVATABLE
The key for the runnable deactivatable property- See Also:
- Constant Field Values
-
KEY_RUNNABLE_VOLATILE
public static final String KEY_RUNNABLE_VOLATILE
The key for the runnable volatile property- See Also:
- Constant Field Values
-
KEY_RUNNABLE_USERIDENTITY
public static final String KEY_RUNNABLE_USERIDENTITY
The key to retrieve theUserIdentity- See Also:
- Constant Field Values
-
PARAM_VALUES_PREFIX
public static final String PARAM_VALUES_PREFIX
The prefix for the parameter values of the runnable job in the job data map- See Also:
- Constant Field Values
-
DATASOURCE_CONFIG_NAME
public static final String DATASOURCE_CONFIG_NAME
Name of the parameter holding the datasource id for Quartz- See Also:
- Constant Field Values
-
__QUARTZ_CONFIG_FILE_NAME
private static final String __QUARTZ_CONFIG_FILE_NAME
The name of the configuration file for Quartz- See Also:
- Constant Field Values
-
__RIGHT_SCHEDULER
private static final String __RIGHT_SCHEDULER
The id of the right to execute actions on tasks- See Also:
- Constant Field Values
-
_manager
protected ServiceManager _manager
The service manager
-
_runnableEP
protected RunnableExtensionPoint _runnableEP
The extension point forRunnables
-
_schedulableEP
protected SchedulableExtensionPoint _schedulableEP
The extension point forSchedulables
-
_scheduler
protected Scheduler _scheduler
The Quartz scheduler
-
_sqlDataSourceManager
protected SQLDataSourceManager _sqlDataSourceManager
The manager for SQL datasources
-
_sourceResolver
protected SourceResolver _sourceResolver
The source resolver
-
_rightManager
protected RightManager _rightManager
The rights manager
-
_currentUserProvider
protected CurrentUserProvider _currentUserProvider
The provider of current user
-
_sqlDatabaseTypeEP
protected SQLDatabaseTypeExtensionPoint _sqlDatabaseTypeEP
The sql database type ep
-
_userManager
protected UserManager _userManager
The user manager
-
_userHelper
protected UserHelper _userHelper
The user helper
-
-
Constructor Detail
-
Scheduler
public Scheduler()
-
-
Method Detail
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualizein interfaceContextualizable- Throws:
ContextException
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
initialize
public void initialize() throws Exception
- Specified by:
initializein interfaceInitializable- Throws:
Exception
-
_checkAndCreateTables
private void _checkAndCreateTables(String dataSourceId)
-
_getDriverDelegateClass
private String _getDriverDelegateClass(String dbType)
-
start
public void start() throws SchedulerException
Starts the Quartz scheduler. Only call this method once !- Throws:
SchedulerException- if an error occured
-
getScheduler
public Scheduler getScheduler()
Get the Quartz scheduler- Returns:
- the scheduler
-
_removeVolatileJobs
private void _removeVolatileJobs() throws SchedulerException
- Throws:
SchedulerException
-
_scheduleConfigurableJobs
private void _scheduleConfigurableJobs()
-
_triggerRunAtStartupJobs
private void _triggerRunAtStartupJobs() throws SchedulerException
- Throws:
SchedulerException
-
scheduleJob
public void scheduleJob(Runnable runnable) throws SchedulerException
Schedules a job- Parameters:
runnable- The runnable job to schedule- Throws:
SchedulerException- if the Job or Trigger cannot be added to the Scheduler, or there is an internal Scheduler error.
-
_runnableToJobDataMap
private JobDataMap _runnableToJobDataMap(Runnable runnable)
-
getJobs
public Set<JobKey> getJobs() throws SchedulerException
Gets the jobs of the Quartz scheduler- Returns:
- the jobs
- Throws:
SchedulerException- if an error occured
-
getTasksInformation
public List<Map<String,Object>> getTasksInformation(List<String> taskIds) throws SchedulerException
Gets tasks information- Parameters:
taskIds- The ids of the tasks- Returns:
- The tasks information
- Throws:
SchedulerException- if an error occurred
-
getTasksAsJson
public List<Map<String,Object>> getTasksAsJson() throws Exception
Gets all the scheduled tasks- Returns:
- the scheduled tasks
- Throws:
Exception- if an error occured
-
_getExecutingJobs
private List<JobKey> _getExecutingJobs() throws SchedulerException
- Throws:
SchedulerException
-
_jobToJson
private Map<String,Object> _jobToJson(JobKey jobKey, List<JobKey> executingJobs) throws Exception
- Throws:
Exception
-
_isRunningJob
private boolean _isRunningJob(JobKey jobKey, List<JobKey> executingJobs)
-
_triggerToJson
private void _triggerToJson(Trigger trigger, Map<String,Object> result) throws Exception
- Throws:
Exception
-
_schedulableToJson
private Map<String,Object> _schedulableToJson(Schedulable schedulable, boolean isEdition) throws Exception
- Throws:
Exception
-
getEditionConfiguration
public Map<String,Object> getEditionConfiguration() throws Exception
Gets the configuration for creating/editing a runnable (so returns all the schedulables and their parameters)- Returns:
- A map containing information about what is needed to create/edit a runnable
- Throws:
Exception- If an error occurs.
-
getParameters
public Map<String,Object> getParameters(String schedulableId) throws Exception
Gets the parameters of a given schedulable- Parameters:
schedulableId- The id of the schedulable- Returns:
- A map containing parameters (prefixed) of the given schedulable
- Throws:
Exception- If an error occurs.
-
getParameterValues
public Map<String,Object> getParameterValues(String id)
Gets the values of the parameters of the given task- Parameters:
id- The id of the task- Returns:
- The values of the parameters
-
isModifiable
public Map<String,Object> isModifiable(String id) throws SchedulerException
Returns true if the given task is modifiable.- Parameters:
id- The id of the task- Returns:
- true if the given task is modifiable.
- Throws:
SchedulerException- if an error occured
-
add
public Map<String,Object> add(String label, String description, String fireProcess, String cron, String schedulableId, Map<String,String> params) throws SchedulerException
Adds a new task.- Parameters:
label- The labeldescription- The descriptionfireProcess- the fire processcron- The cron expressionschedulableId- The id of the schedulable modelparams- The values of the parameters- Returns:
- A result map
- Throws:
SchedulerException- if an error occured
-
add
public Map<String,Object> add(String label, String description, String fireProcess, String cron, String schedulableId, Map<String,Object> launchUser, Map<String,String> params) throws SchedulerException
Adds a new task.- Parameters:
label- The labeldescription- The descriptionfireProcess- the fire processcron- The cron expressionschedulableId- The id of the schedulable modellaunchUser- The user to launch the taskparams- The values of the parameters- Returns:
- A result map
- Throws:
SchedulerException- if an error occured
-
_generateUniqueId
private String _generateUniqueId(String label) throws SchedulerException
- Throws:
SchedulerException
-
edit
public Map<String,Object> edit(String id, String label, String description, String fireProcess, String cron, Map<String,Object> launchUser, Map<String,String> params) throws SchedulerException
Edits the given task.- Parameters:
id- The id of the tasklabel- The labeldescription- The descriptionfireProcess- the fire processcron- The cron expressionlaunchUser- The user to launch the taskparams- The values of the parameters- Returns:
- A result map
- Throws:
SchedulerException- if an error occured
-
_edit
private Map<String,Object> _edit(String id, String label, String description, Runnable.FireProcess fireProcess, String cron, String schedulableId, boolean isVolatile, Map<String,Object> launchUser, Map<String,String> params)
-
_getTypedParams
private Map<String,Object> _getTypedParams(Map<String,String> params, String schedulableId)
-
remove
public Map<String,Object> remove(String id) throws SchedulerException
Removes the given task.- Parameters:
id- The id of the task- Returns:
- A result map
- Throws:
SchedulerException- if an error occured
-
enable
public Map<String,Object> enable(String id, boolean enabled)
Enables/disables the given task.- Parameters:
id- The id of the taskenabled- true to enable the task, false to disable it.- Returns:
- A result map
-
removeCompletedTasks
public List<Map<String,Object>> removeCompletedTasks() throws SchedulerException
Removes the completed tasks- Returns:
- The information of deleted tasks
- Throws:
SchedulerException- if an error occured
-
isEnabled
public Map<String,Object> isEnabled(String id)
Returns the enabled state of the task.- Parameters:
id- The id of the task- Returns:
- A result map
-
isRunning
public Map<String,Object> isRunning(String id)
Returns the running state of the task.- Parameters:
id- The id of the task- Returns:
- A result map
-
getSchedulables
public List<Map<String,Object>> getSchedulables()
Gets all the schedulables (private or not)- Returns:
- the schedulables
-
dispose
public void dispose()
- Specified by:
disposein interfaceDisposable
-
-