Package org.lsst.ccs
Class Agent
java.lang.Object
org.lsst.ccs.Agent
- All Implemented Interfaces:
CommandExecutor,ServiceLifecycle
- Direct Known Subclasses:
DumpCommands,Subsystem
Minimal component able to communicate on the buses.
The following functionality is supported by the Agent:
- Access to the buses through an instance of
AgentMessagingLayer. - A method for publishing arbitrary objects on the status bus.
- Protected methods for checking, modifying, and publishing the Agent state. Access to the state is synchronized so these methods can be called from any thread.
- Command processing.
- Scheduling periodic and delayed tasks.
- Author:
- emarin
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classRepresents a command accepted for execution by thisAgent.static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringprotected final ObjectLock that guards command executor state.protected Agent.RunningCommandCurrently running CONFIGURATION or ACTION command.protected final Set<Agent.RunningCommand>Currently running QUERY commands.protected final Set<Agent.RunningCommand>Currently running SIGNAL commands.protected final AtomicBooleanFlag indicating that shutdownAgent() is being executed in a JVM shutdown hook.protected LogBusHandlerLogging bus handlerprotected AgentStateServiceprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected CommandHelperThis method can be overridden by subclasses of Agent to create a subclass of CommandHelper to be returned byhelper()voidexecuteCommandRequest(CommandRequest request) Executes the received commandReturnsAgentIfnoinstance associated with thisAgent.Get this agent's local persistence service.final <T extends AgentService>
TgetAgentService(Class<T> agentClass) Generic method to access agent services.final List<AgentService>Get the list of available services for this Agent.intgetCommandCount(Command.CommandType... types) Returns the number of currently running commands of given types.Returns handle ofRunningCommandcurrently being executed by this thread.Returns userid of the agent that submitted the command currently being executed by this thread.Deprecated.Use ConfigurationService instead.Deprecated.Use ConfigurationService instead.final ComponentLookupProvides access to the inner modular structure of this Subsystem.Get the current RunningCommand action.Gets the name of the description this subsystem was built from.static AgentLockServicestatic AgentMessagingLayerReturnsAgentMessagingLayerassociated with this JVM.Returns the current logger (use sparingly and prefer your own logger).Get the underlying AgentMessagingLayer instance.final StringgetName()Returns the name of thisAgent.ReturnsSchedulerused by thisAgent.helper()A convenience method for creating a new CommandHelperfinal voidvoidconnects a LogBusHandler to the Log bus.booleanCommand to tell if the subsystem is in Engineering mode.protected final voidSets the component lookup for this Agent.voidpreInit()voidpreStart()Called from the enclosingSubsystemwhenorg.lsst.ccs.Subsystem#start()has been called.Get a representation of the component tree.final voidpublishSubsystemDataOnStatusBus(KeyValueData keyValueData) Publishes the providedKeyValueDataon the Status bus.booleanSends an ACK to the command originator.booleansendNack(Serializable reason) Sends a NACK to the command originator.voidMethod for sending messages on the status bus.final voidsetAgentName(String alias) protected ObjectshutdownAgent(boolean goOffline, int nSeconds) shutdownAgent(int nSeconds) Clean shutdown of subsystem: call stop for hardware stopping before invoking this method.voidStarts this AgentMethod to be overwritten by Agents that wish to veto the transition to NORMAL mode.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.lsst.ccs.ServiceLifecycle
afterBuild, afterInit, afterStart, preBuild, preShutdown
-
Field Details
-
jvmShutdown
Flag indicating that shutdownAgent() is being executed in a JVM shutdown hook. -
logBusHandler
Logging bus handler -
commandExecutorLock
Lock that guards command executor state. -
currentQueries
Currently running QUERY commands. -
currentAction
Currently running CONFIGURATION or ACTION command. -
currentSignals
Currently running SIGNAL commands. -
treeComponentInitialized
protected volatile boolean treeComponentInitialized -
stateService
-
AGENT_RUNTIMEINFO_TASK
- See Also:
-
AGENT_DESCRIPTION
- See Also:
-
-
Constructor Details
-
Agent
Constructs anAgent.- Parameters:
name- name of thisAgent; forCONSOLEandLISTENERagents, the name will be modified to ensure uniqueness.agentType- type of thisAgent.
-
-
Method Details
-
preInit
public void preInit()- Specified by:
preInitin interfaceServiceLifecycle
-
populateComponentLookup
Sets the component lookup for this Agent. This method is meant to be invoked from two places: - a constructor - BootUtils after a Subsystem has been built- Parameters:
lookup- the lookup
-
preStart
public void preStart()Description copied from interface:ServiceLifecycleCalled from the enclosingSubsystemwhenorg.lsst.ccs.Subsystem#start()has been called.The preceding lifecycle step is
HasLifecycle.postInit()The following lifecycle step is
HasLifecycle.start()At the time it is called :-
the
PhaseStateisINITIALIZINGconnection with the messaging layer is effective, the enclosing subsystem has startedStatusHeartBeatpublication- Specified by:
preStartin interfaceServiceLifecycle
-
getAgentServices
Get the list of available services for this Agent.- Returns:
- a List of AgentServices
-
getAgentService
Generic method to access agent services.- Type Parameters:
T- The class of the service to fetch.- Parameters:
agentClass-- Returns:
- The services of the requested type.
-
getComponentLookup
Provides access to the inner modular structure of this Subsystem.- Returns:
- a
ComponentLookupobject.
-
createHelper
This method can be overridden by subclasses of Agent to create a subclass of CommandHelper to be returned byhelper()- Returns:
- The newly created CommandHelper
-
helper
A convenience method for creating a new CommandHelper- Returns:
- The newly created CommandHelper
- See Also:
-
setAgentName
-
initAgent
public final void initAgent() -
startAgent
public void startAgent()Starts this Agent -
shutdownAgent
- Throws:
Exception
-
shutdownAgent
@Command(name="shutdown", description="shutdown", type=ACTION, category=CORE) public Object shutdownAgent(@Argument(description="Seconds before the subsystem is expected to restart",defaultValue="0") int nSeconds) throws Exception Clean shutdown of subsystem: call stop for hardware stopping before invoking this method.- Parameters:
nSeconds- Number of seconds before the system is expected to restart.- Returns:
- Status of the shutdown
- Throws:
Exception- If anything goes wrong during shutdown
-
shutdownAgent
- Throws:
Exception
-
getLogger
Returns the current logger (use sparingly and prefer your own logger).- Returns:
- logger associated with this subsystem
-
getName
Returns the name of thisAgent.- Returns:
- name of this
Agent
-
getAgentInfo
ReturnsAgentIfnoinstance associated with thisAgent.- Returns:
AgentIfnoinstance associated with thisAgent
-
getScheduler
ReturnsSchedulerused by thisAgent. Subsystem developers are encouraged to use this scheduler for running all periodic and delayed short tasks.- Returns:
Schedulerprovided by thisAgent.
-
getCommandCount
Returns the number of currently running commands of given types. Note that unless this method is called while holding commandExecutorLock monitor, the returned value is not guaranteed to be current when the method returns.- Parameters:
types- Types of commands to include in the count. In no types are given, all commands are included.- Returns:
- number of currently running commands of given types
-
isInEngineeringMode
@Command(description="is the system in engineering mode ?", type=QUERY, category=CORE) public boolean isInEngineeringMode()Command to tell if the subsystem is in Engineering mode.- Returns:
trueif thisAgentis in ENGINEERING_OK or ENGINEERING_FAULT mode.
-
printComponentNodeTree
@Command(description="Print component lookup", type=QUERY, category=SYSTEM) public String printComponentNodeTree()Get a representation of the component tree.- Returns:
- a String representing the component tree
-
getMessagingAccess
Get the underlying AgentMessagingLayer instance. Alternatively use MessagingService::getMessagingAccess();- Returns:
- the underlying AgentMessagingLayer.
-
getEnvironmentMessagingAccess
ReturnsAgentMessagingLayerassociated with this JVM. Normally, there is only one instance ofAgentMessagingLayerper JVM, providing busses access to theAgentand all its clients. In the test environment, however, multiple agents can run on the same JVM.- Returns:
AgentMessagingLayerassociated with this JVM
-
getEnvironmentLockService
-
sendStatusMessage
Method for sending messages on the status bus.- Parameters:
msg- The StatusMessage to send on the buses.
-
initLogBusHandler
public void initLogBusHandler()connects a LogBusHandler to the Log bus. Should be called only when messaging is initialized properly. -
publishSubsystemDataOnStatusBus
Publishes the providedKeyValueDataon the Status bus. Internally theKeyValueDatais wrapped into aStatusSubsystemDatabefore publication.- Parameters:
keyValueData- The KeyValueData to be published.
-
executeCommandRequest
Description copied from interface:CommandExecutorExecutes the received command- Specified by:
executeCommandRequestin interfaceCommandExecutor- Parameters:
request- the command to be executed by the CommandExecutor
-
sendNack
Sends a NACK to the command originator. This method can be called from inside methods annotated as commands withautoAck=false. It should be called on the same thread the command method was invoked on. If this method is called under any other circumstances, it has no effect and returnsfalse. The value returned by the command method after sending NACK is ignored.- Parameters:
reason- Reason for rejecting the command.- Returns:
trueif the NACK has been sent as a result of this call.
-
sendAck
Sends an ACK to the command originator. This method can be called from inside methods annotated as commands withautoAck=false. It should be called on the same thread the command method was invoked on. If this method is called under any other circumstances, it has no effect and returnsfalse.- Parameters:
timeout- Timeout for the command. Specifying non-positive ornulltimeout indicates the default should be used.- Returns:
trueif the ACK has been sent as a result of this call.
-
getCurrentAction
Get the current RunningCommand action.- Returns:
- The current RunningCommand for the action.
-
getCommandForThisThread
Returns handle ofRunningCommandcurrently being executed by this thread.- Returns:
- Current command, or
nullif this thread is not executing a command.
-
getCommandUser
Returns userid of the agent that submitted the command currently being executed by this thread.- Returns:
- User name, or
nullif this thread is not executing a command.
-
getComponentConfigurationEnvironment
@Deprecated public ComponentConfigurationEnvironment getComponentConfigurationEnvironment(Object obj) Deprecated.Use ConfigurationService instead.Get the ComponentConfigurationEnvironment object for a given Object.- Parameters:
obj- the object for which to get the component configuration service- Returns:
- a component configuration service for the given object
-
getComponentConfigurationEnvironmentByName
@Deprecated public ComponentConfigurationEnvironment getComponentConfigurationEnvironmentByName(String name) Deprecated.Use ConfigurationService instead.Get the ComponentConfigurationEnvironment object for a given node name.- Parameters:
name- the name of the object for which to get the component configuration service.- Returns:
- a component configuration service for the given object.
-
getAgentPersistenceService
Get this agent's local persistence service.- Returns:
- the local persistence service for this agent.
-
getDescription
Gets the name of the description this subsystem was built from. The description name is set after the initialization step.- Returns:
- the description name
-
vetoTransitionToNormalMode
Method to be overwritten by Agents that wish to veto the transition to NORMAL mode.- Returns:
- null if it's ok to transition to NORMAL mode. Otherwise return the String for the reason the transition has been vetoed. The String will be returned as part of the Nack.
-