Package org.lsst.ccs.services
Class AgentPeriodicTaskService
java.lang.Object
org.lsst.ccs.services.AgentPeriodicTaskService
- All Implemented Interfaces:
HasLifecycle,ServiceLifecycle,AgentService
public final class AgentPeriodicTaskService
extends Object
implements ServiceLifecycle, HasLifecycle, AgentService
A service to schedule periodic tasks. This service is responsible to manage
the Agent's periodic tasks: - allow components to schedule periodic tasks -
starts all the scheduled tasks once the Agent has started - stops the tasks
upon shutdown
It also provides utility methods to set/get the period of a task.
- Author:
- The LSST CCS Team
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbuild()First lifecycle hook.createScheduler(String name, int nThreads) Create a scheduler by name and the default number of threads.Get the list of names of the scheduled tasks.Get the name of this service.getPeriodicTaskPeriod(String taskName) Get the period of a PeriodicTaks.voidinit()Called from the enclosingSubsystemat initialization phase.voidpreBuild()voidpreInit()voidSchedule a PeriodicTask.voidscheduleAgentPeriodicTask(AgentPeriodicTask task, String schedulerName) voidsetPeriodicTaskPeriod(String taskName, Duration period) Change the period of a PeriodicTask.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.lsst.ccs.services.AgentService
startForAgentMethods inherited from interface org.lsst.ccs.framework.HasLifecycle
postBuild, postInit, postShutdown, postStart, shutdown, startMethods inherited from interface org.lsst.ccs.ServiceLifecycle
afterBuild, afterInit, afterStart, preShutdown, preStart
-
Constructor Details
-
AgentPeriodicTaskService
public AgentPeriodicTaskService()
-
-
Method Details
-
getAgentServiceName
Description copied from interface:AgentServiceGet the name of this service. This name will be used to add the given service to the lookup tree.- Specified by:
getAgentServiceNamein interfaceAgentService- Returns:
- the AgentService name.
-
preBuild
public void preBuild()- Specified by:
preBuildin interfaceServiceLifecycle
-
build
public void build()Description copied from interface:HasLifecycleFirst lifecycle hook. Modification of the component tree is allowed at this stage. After this stage the tree of component cannot be modified anymore. This is where agent periodic tasks should be scheduled.- Specified by:
buildin interfaceHasLifecycle
-
preInit
public void preInit()- Specified by:
preInitin interfaceServiceLifecycle
-
init
public void init()Description copied from interface:HasLifecycleCalled from the enclosingSubsystemat initialization phase.This method is called before the children components of this object have their
initmethod called.At the time it is called, connection to the messaging layer is not yet done, so there should be no attempt to send messages in the body of this method. Configuration for message listening can nevertheless be done here, such as adding
MessageListenerobjects.It is unnecessary to call
super.init()- Specified by:
initin interfaceHasLifecycle
-
createScheduler
Create a scheduler by name and the default number of threads. This scheduler can be then used to schedule periodic tasks. The number of threads allocated for this scheduler can be changed via a configuration parameter.- Parameters:
name-nThreads-
-
scheduleAgentPeriodicTask
Schedule a PeriodicTask. Any CCS component can schedule an AgentPeriodicTask for execution. This method is available only during the build period of . Any invocation of this method at a later stage will result in a RuntimeException.- Parameters:
task- The PeriodicTask to schedule
-
scheduleAgentPeriodicTask
-
getPeriodicTaskPeriod
Get the period of a PeriodicTaks.- Parameters:
taskName- The name of the task- Returns:
- The periodic task period in milliseconds.
-
setPeriodicTaskPeriod
Change the period of a PeriodicTask. This method results in a configuration change.- Parameters:
taskName- The name of the taskperiod- The period Duration
-
getAgentPeriodicTaskNames
@Command(name="getAgentPeriodicTaskNames", description="Get the list of the names of the scheduled tasks", type=QUERY, category=SYSTEM) public List<String> getAgentPeriodicTaskNames()Get the list of names of the scheduled tasks.- Returns:
- the Enumeration of task names.
-