
public class Agent extends Object implements CommandExecutor, ServiceLifecycle
AgentMessagingLayer.| Modifier and Type | Class and Description |
|---|---|
class |
Agent.RunningCommand
Represents a command accepted for execution by this
Agent. |
| Modifier and Type | Field and Description |
|---|---|
static String |
AGENT_HEARTBEAT_TASK |
static String |
AGENT_RUNTIMEINFO_TASK |
protected Object |
commandExecutorLock
Lock that guards command executor state.
|
protected Agent.RunningCommand |
currentAction
Currently running CONFIGURATION or ACTION command.
|
protected Set<Agent.RunningCommand> |
currentQueries
Currently running QUERY commands.
|
protected Set<Agent.RunningCommand> |
currentSignals
Currently running SIGNAL commands.
|
protected AtomicBoolean |
jvmShutdown
Flag indicating that shutdownAgent() is being executed in a JVM shutdown hook.
|
protected LogBusHandler |
logBusHandler
Logging bus handler
|
protected AgentStateService |
stateService |
protected boolean |
treeComponentInitialized |
| Constructor and Description |
|---|
Agent(String name,
AgentInfo.AgentType agentType)
Constructs an
Agent. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addCommandSet(String fullPath,
Object obj)
Adds a
CommandSet to extend the set of commands recognized by this Agent. |
void |
addCommandsFromObject(Object obj,
String path)
Add the commands defined in an Object to this Agent's CommandSet.
|
void |
addStateChangeListener(StateChangeListener stateChangeListener,
Class... states)
Deprecated.
use
AgentStateService::addStateChangeListener(StateChangeListener, Class...) instead |
protected void |
broadcastStatus()
Broadcasts the current heartbeat status.
|
void |
checkAllHardwareStopped()
Called to check if all hardware has been correctly started.
|
protected CommandHelper |
createHelper()
This method can be overridden by subclasses of Agent to create a subclass of CommandHelper
to be returned by
helper() |
void |
executeCommandRequest(CommandRequest request)
Executes the received command
|
AgentInfo |
getAgentInfo()
Returns
AgentIfno instance associated with this Agent. |
AgentLockService |
getAgentLockService()
Deprecated.
use
getAgentService(Class) instead. |
AgentPeriodicTaskService |
getAgentPeriodicTaskService()
Deprecated.
use
getAgentService(Class) instead. |
PersistencyService |
getAgentPersistenceService()
Get this agent's local persistence service.
|
Properties |
getAgentProperties()
Get the agent properties.
|
Set |
getAgentPropertiesKeySet()
Get the Set of agent properties.
|
String |
getAgentProperty(String property)
Get an agent property.
|
<T extends AgentService> |
getAgentService(Class<T> agentClass)
Generic method to access agent services.
|
List<AgentService> |
getAgentServices()
Get the list of available services for this Agent.
|
AgentStatusAggregatorService |
getAgentStatusAggregatorService()
Deprecated.
use
getAgentService(Class) instead. |
AlertService |
getAlertService()
Deprecated.
use
getAgentService(Class) instead. |
CCSVersions |
getCCSVersions()
Command to get the CCSVersions object for the current CCS Environment.
|
int |
getCommandCount(Command.CommandType... types)
Returns the number of currently running commands of given types.
|
protected CommandSet |
getCommandSet(String name) |
List<String> |
getCommandTargets()
Returns this
Agent list of command targets. |
ComponentConfigurationEnvironment |
getComponentConfigurationEnvironment(Object obj)
Get the ComponentConfigurationEnvironment object for a given Object.
|
ComponentConfigurationEnvironment |
getComponentConfigurationEnvironmentByName(String name)
Get the ComponentConfigurationEnvironment object for a given node name.
|
ComponentLookup |
getComponentLookup()
Provides access to the inner modular structure of this Subsystem.
|
ConfigurationService |
getConfigurationService()
Deprecated.
use
getAgentService(Class) instead. |
Agent.RunningCommand |
getCurrentAction()
Get the current RunningCommand action.
|
DataProviderDictionaryService |
getDataProviderDictionaryService()
Deprecated.
use
getAgentService(Class) instead. |
String |
getDescription()
Gets the name of the description this subsystem was built from.
|
HashMap<String,Dictionary> |
getDictionaries()
Returns the command dictionary used by this
Agent. |
DistributionInfo |
getDistributionInfo()
Command to get the DistributionInfo object for this
Agent. |
static AgentLockService |
getEnvironmentLockService() |
static AgentMessagingLayer |
getEnvironmentMessagingAccess()
Returns
AgentMessagingLayer associated with this JVM. |
Logger |
getLogger()
Returns the current logger (use sparingly and prefer your own logger).
|
AgentMessagingLayer |
getMessagingAccess()
Returns
AgentMessagingLayer used by this Agent. |
Monitor |
getMonitor()
Deprecated.
|
String |
getName()
Returns the name of this
Agent. |
Scheduler |
getScheduler()
Returns
Scheduler used by this Agent. |
StateBundle |
getState()
Deprecated.
use
AgentStateService::getState() instead |
Enum |
getState(Class stateClass)
Deprecated.
use
AgentStateService::getState(Class) instead |
int |
getStatusBroadcastPeriod()
Returns heartbeat broadcasting period for this
Agent. |
CommandHelper |
helper()
A convenience method for creating a new CommandHelper
|
protected void |
internalCheckHardware()
Called before activating anything and again once problems are supposed to
have been addressed.
|
boolean |
isConnectedToTheBuses() |
boolean |
isInEngineeringMode()
Command to tell if the subsystem is in Engineering mode.
|
boolean |
isInState(Enum state)
Deprecated.
use
AgentStateService::isInState(Enum) instead |
boolean |
isInState(StateBundle state)
Deprecated.
use
AgentStateService::isInState(StateBundle) instead |
protected void |
populateComponentLookup(ComponentLookup lookup)
Sets the component lookup for this Agent.
|
void |
preBuild() |
void |
preInit() |
String |
printComponentNodeTree()
Get a representation of the component tree.
|
void |
publishSubsystemDataOnStatusBus(KeyValueData keyValueData)
Publishes the provided
KeyValueData on the Status bus. |
void |
removeStateChangeListener(StateChangeListener stateChangeListener)
Deprecated.
use
AgentStateService::removeStateChangeListener(StateChangeListener) instead |
boolean |
sendAck(Duration timeout)
Sends an ACK to the command originator.
|
boolean |
sendNack(Serializable reason)
Sends a NACK to the command originator.
|
void |
setAgentName(String alias) |
void |
setAgentProperty(String property,
String value)
Set an Agent property.startAge
This method can be invoked only up to the point the Agent is about to connect
to the buses.
|
Object |
shutdownAgent()
Clean shutdown of subsystem: call stop for hardware stopping before invoking this method.
|
void |
startAgent()
Starts this Agent
|
void |
startAgent(String alias)
Deprecated.
Use startAgent(). To set an Alias use setAgentName.
|
void |
updateAgentComponentState(Object component,
Enum... stateChanges)
Deprecated.
use
AgentStateService::updateAgentComponentState(Object, Enum...) instead |
void |
updateAgentState(Enum... stateChanges)
Deprecated.
use
AgentStateService::updateAgentState(Enum...) instead |
void |
updateAgentState(StateBundle stateChanges)
Deprecated.
use
AgentStateService::updateAgentState(StateBundle) instead |
protected void |
updateHeartBeat(StatusHeartBeat heartBeat)
Subclasses can override this method to add customized information to the heartbeat.
|
boolean |
waitFor(Predicate<StateBundle> target,
long timeout,
TimeUnit unit)
Deprecated.
use
AgentStateService::waitFor(Predicate<StateBundle>, long, TimeUnit) instead |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitafterInit, preShutdown, preStartprotected final AtomicBoolean jvmShutdown
protected LogBusHandler logBusHandler
protected final Object commandExecutorLock
protected final Set<Agent.RunningCommand> currentQueries
protected volatile Agent.RunningCommand currentAction
protected final Set<Agent.RunningCommand> currentSignals
protected volatile boolean treeComponentInitialized
@LookupField(strategy=CHILDREN) protected AgentStateService stateService
public static final String AGENT_HEARTBEAT_TASK
public static final String AGENT_RUNTIMEINFO_TASK
public Agent(String name, AgentInfo.AgentType agentType)
Agent.name - name of this Agent; for CONSOLE and LISTENER
agents, the name will be modified to ensure uniqueness.agentType - type of this Agent.public void preBuild()
preBuild in interface ServiceLifecyclepublic void preInit()
preInit in interface ServiceLifecycleprotected final void populateComponentLookup(ComponentLookup lookup)
lookup - the lookuppublic final List<AgentService> getAgentServices()
public final <T extends AgentService> T getAgentService(Class<T> agentClass)
T - The class of the service to fetch.agentClass - public final ComponentLookup getComponentLookup()
ComponentLookup object.protected CommandHelper createHelper()
helper()public CommandHelper helper()
createHelper()@Deprecated public final AgentPeriodicTaskService getAgentPeriodicTaskService()
getAgentService(Class) instead.@Deprecated public final AgentStatusAggregatorService getAgentStatusAggregatorService()
getAgentService(Class) instead.public final void setAgentName(String alias)
@Deprecated public void startAgent(String alias)
alias - public void startAgent()
@Command(name="shutdown", description="shutdown", type=ACTION) public Object shutdownAgent() throws Exception
Exception - If anything goes wrong during shutdownpublic Logger getLogger()
public final String getName()
Agent.Agentpublic AgentInfo getAgentInfo()
AgentIfno instance associated with this Agent.AgentIfno instance associated with this Agentpublic Scheduler getScheduler()
Scheduler used by this Agent.
Subsystem developers are encouraged to use this scheduler for running all
periodic and delayed short tasks.Scheduler provided by this Agent.public int getCommandCount(Command.CommandType... types)
types - Types of commands to include in the count.
In no types are given, all commands are included.public int getStatusBroadcastPeriod()
Agent.@Command(description="is the system in engineering mode ?", type=QUERY, category=SYSTEM) public boolean isInEngineeringMode()
true if this Agent is in ENGINEERING_OK or ENGINEERING_FAULT mode.@Command(description="Get the CCS Versions for the current CCS Environment", type=QUERY, category=SYSTEM) public CCSVersions getCCSVersions()
@Command(description="Get the Agent\'s DistributionInfo object.", type=QUERY, category=SYSTEM) public DistributionInfo getDistributionInfo()
Agent.
The DistributionInfo object contains version information about the distribution
from which this Agent was launched.Agent.@Command(description="get the command dictionary for the subsystem", type=QUERY, category=SYSTEM) public HashMap<String,Dictionary> getDictionaries()
Agent.@Command(description="Get the list of command targets", type=QUERY, category=SYSTEM) public List<String> getCommandTargets()
Agent list of command targets.@Command(description="Print component lookup", type=QUERY, category=SYSTEM) public String printComponentNodeTree()
protected CommandSet getCommandSet(String name)
protected void addCommandSet(String fullPath, Object obj)
CommandSet to extend the set of commands recognized by this Agent.obj - The object with the commandsfullPath - the full path of the component to addpublic void addCommandsFromObject(Object obj, String path)
obj - The Object from which to extract the commands.path - The path at which the resulting CommandSet will be added.public void setAgentProperty(String property, String value)
property - The name of the property to set.value - The value of the property.@Command(category=SYSTEM, type=QUERY) public String getAgentProperty(String property)
property - The property name.@Command(category=SYSTEM, type=QUERY) public Set getAgentPropertiesKeySet()
@Command(category=SYSTEM, type=QUERY) public Properties getAgentProperties()
public AgentMessagingLayer getMessagingAccess()
AgentMessagingLayer used by this Agent.
The returned instance is used by the Agent internally, and can also
be used by the client code to publish messages on the buses.AgentMessagingLayer used by this Agentpublic static AgentMessagingLayer getEnvironmentMessagingAccess()
AgentMessagingLayer associated with this JVM.
Normally, there is only one instance of AgentMessagingLayer per JVM,
providing busses access to the Agent and all its clients. In the test
environment, however, multiple agents can run on the same JVM.AgentMessagingLayer associated with this JVMpublic static AgentLockService getEnvironmentLockService()
public boolean isConnectedToTheBuses()
public final void publishSubsystemDataOnStatusBus(KeyValueData keyValueData)
KeyValueData on the Status bus.
Internally the KeyValueData is wrapped into a
StatusSubsystemData before publication.keyValueData - The KeyValueData to be published.protected final void broadcastStatus()
protected void updateHeartBeat(StatusHeartBeat heartBeat)
heartBeat - Heartbeat instance to be modified before publication.public void executeCommandRequest(CommandRequest request)
CommandExecutorexecuteCommandRequest in interface CommandExecutorrequest - the command to be executed by the CommandExecutorpublic boolean sendNack(Serializable reason)
autoAck=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 returns false. The value returned by the command
method after sending NACK is ignored.reason - Reason for rejecting the command.true if the NACK has been sent as a result of this call.public boolean sendAck(Duration timeout)
autoAck=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 returns false.timeout - Timeout for the command. Specifying non-positive or null
timeout indicates the default should be used.true if the ACK has been sent as a result of this call.public Agent.RunningCommand getCurrentAction()
@Deprecated public Monitor getMonitor()
@Deprecated public final ConfigurationService getConfigurationService()
getAgentService(Class) instead.@Deprecated public final AlertService getAlertService()
getAgentService(Class) instead.@Deprecated public final DataProviderDictionaryService getDataProviderDictionaryService()
getAgentService(Class) instead.@Deprecated public final AgentLockService getAgentLockService()
getAgentService(Class) instead.public ComponentConfigurationEnvironment getComponentConfigurationEnvironment(Object obj)
obj - the object for which to get the component configuration servicepublic ComponentConfigurationEnvironment getComponentConfigurationEnvironmentByName(String name)
name - the name of the object for which to get the component configuration service.public PersistencyService getAgentPersistenceService()
public String getDescription()
protected void internalCheckHardware()
public void checkAllHardwareStopped()
throws HardwareException
HardwareException - a compound exception that list the exceptions
fired by hardwares that are not stopped.@Deprecated public boolean isInState(Enum state)
AgentStateService::isInState(Enum) insteadAgent is in the given state.state - The state to check.true if this Agent is in the specified state.@Deprecated public boolean isInState(StateBundle state)
AgentStateService::isInState(StateBundle) insteadAgent is in all of the states contained in the given StateBundle.state - A StateBundle.true if the Agent is in the provided StateBundle.@Deprecated public Enum getState(Class stateClass)
AgentStateService::getState(Class) insteadstateClass - The class of the Enum for which we would like the Agent's state.@Deprecated public StateBundle getState()
AgentStateService::getState() instead@Deprecated public void updateAgentState(Enum... stateChanges)
AgentStateService::updateAgentState(Enum...) insteadHasLifecyclestateChanges - The list of the states that have changed.IllegalArgumentException - if the list of arguments contains internal Agent states.@Deprecated public void updateAgentState(StateBundle stateChanges)
AgentStateService::updateAgentState(StateBundle) insteadHasLifecyclestateChanges - The StateBundle with all the changes.IllegalArgumentException - if the list of arguments contains internal Agent states.@Deprecated public void updateAgentComponentState(Object component, Enum... stateChanges)
AgentStateService::updateAgentComponentState(Object, Enum...) insteadHasLifecyclecomponentName - The name of the component to be updatedstateChanges - The list of the states that have changed.IllegalArgumentException - if the list of arguments contains internal Agent states.@Deprecated public final boolean waitFor(Predicate<StateBundle> target, long timeout, TimeUnit unit) throws InterruptedException
AgentStateService::waitFor(Predicate<StateBundle>, long, TimeUnit) insteadAgent is in state that satisfies the specified predicate.
The condition is not guaranteed to remain true when the thread resumes.
The predicate provided to this method should not depend on anything other than
its argument, and should not have side effects.target - Condition to be satisfied for this method to return.timeout - Timeout value.unit - Timeout unit.True if the condition was satisfied; false if the method timed out.InterruptedException - if the thread is interrupted while waiting.@Deprecated public void addStateChangeListener(StateChangeListener stateChangeListener, Class... states)
AgentStateService::addStateChangeListener(StateChangeListener, Class...) instead@Deprecated public void removeStateChangeListener(StateChangeListener stateChangeListener)
AgentStateService::removeStateChangeListener(StateChangeListener) insteadCopyright © 2018 LSST. All rights reserved.