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 protected Context
_context
The contextprotected CurrentUserProvider
_currentUserProvider
The provider of current userprotected ServiceManager
_manager
The service managerprotected RightManager
_rightManager
The rights managerprotected RunnableExtensionPoint
_runnableEP
The extension point forRunnable
sprotected SchedulableExtensionPoint
_schedulableEP
The extension point forSchedulable
sprotected Scheduler
_scheduler
The Quartz schedulerprotected SourceResolver
_sourceResolver
The source resolverprotected SQLDatabaseTypeExtensionPoint
_sqlDatabaseTypeEP
The sql database type epprotected SQLDataSourceManager
_sqlDataSourceManager
The manager for SQL datasourcesprotected UserHelper
_userHelper
The user helperprotected UserManager
_userManager
The user managerstatic String
DATASOURCE_CONFIG_NAME
Name of the parameter holding the datasource id for Quartzstatic String
JOB_GROUP
The group name for jobsstatic String
KEY_RUNNABLE_CRON
The key for the runnable cron expressionstatic String
KEY_RUNNABLE_DEACTIVATABLE
The key for the runnable deactivatable propertystatic String
KEY_RUNNABLE_DESCRIPTION
The key for the runnable descriptionstatic String
KEY_RUNNABLE_FIRE_PROCESS
The key for the runnable fire process propertystatic String
KEY_RUNNABLE_ID
The key for the runnable idstatic String
KEY_RUNNABLE_LABEL
The key for the runnable labelstatic String
KEY_RUNNABLE_MODIFIABLE
The key for the runnable modifiable propertystatic String
KEY_RUNNABLE_REMOVABLE
The key for the runnable removable propertystatic String
KEY_RUNNABLE_STARTUP_COMPLETED
The key for 'run at startup' jobs indicating if the job has already been executed and is now completedstatic String
KEY_RUNNABLE_USERIDENTITY
The key to retrieve theUserIdentity
static String
KEY_RUNNABLE_VOLATILE
The key for the runnable volatile propertystatic String
KEY_SCHEDULABLE_ID
The key for the id of the schedulable to executestatic String
PARAM_VALUES_PREFIX
The prefix for the parameter values of the runnable job in the job data mapstatic String
ROLE
The Avalon Rolestatic String
TRIGGER_GROUP
The group name for triggers
-
Constructor Summary
Constructors Constructor Description Scheduler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.void
contextualize(Context context)
void
dispose()
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)Scheduler
getScheduler()
Get the Quartz schedulerList<Map<String,Object>>
getTasksAsJson()
Gets all the scheduled tasksList<Map<String,Object>>
getTasksInformation(List<String> taskIds)
Gets tasks informationvoid
initialize()
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 tasksvoid
scheduleJob(Runnable runnable)
Schedules a jobvoid
service(ServiceManager manager)
void
start()
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
-
_manager
protected ServiceManager _manager
The service manager
-
_runnableEP
protected RunnableExtensionPoint _runnableEP
The extension point forRunnable
s
-
_schedulableEP
protected SchedulableExtensionPoint _schedulableEP
The extension point forSchedulable
s
-
_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:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
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
-
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.
-
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
-
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
-
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
-
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:
dispose
in interfaceDisposable
-
-