
public class Subsystem extends Object implements CommandListener, StatusListener, CommandExecutor
This object will register itself on the three buses (control, status, log). It broadcasts its status, and can receive Commands.
| Modifier and Type | Class and Description |
|---|---|
protected class |
Subsystem.DictionarySearchResult
an internal data object for describing the result of a dictionary search.
|
static class |
Subsystem.SignalThread
threads that run "signals" are peculiar because they know about a time deadline.
|
static class |
Subsystem.State
this class represents a composite state ofr a Subsystem.
|
protected class |
Subsystem.StatusBroadcaster
the Runnable in charge of broadcasting status
|
| Modifier and Type | Field and Description |
|---|---|
protected Object |
actionMonitor
monitor used by actions
|
protected ThreadGroup |
ancillaryGroup
This group should be used by Thread created
by programmers (for instance Threads reading
data ).
|
protected boolean |
closing
are we closing ?
|
protected LocalCommandDictionary |
commandBuilder
we know about the subsystem available commands
|
protected String |
commandBusSelector |
protected ThreadGroup |
commandGroup
all commands are executed in separate threads that belong to this
threadGroup.
|
protected Object |
commandMonitor
used mostly for test that wait for execution of a command
|
protected ConfigurationProxy |
configurationProxy
the proxy for configuration (useful only for passive subsystem)
|
protected static ThreadLocal<Subsystem> |
currentSubsystem
Deprecated.
|
protected MessagingFactory |
fac
access to messaging layer.
|
protected boolean |
forceShutdown
used to force shutdown.
|
protected boolean |
initializing
are we initializing ?
|
protected Thread |
initThread
the Thread that performs initialisation
|
protected Subsystem.State |
innerState
Subsystem inner state read/modification of this should be
synchronized on "this"
|
protected boolean |
inTestContext
used to know if the usbsystem is in test context: this is important
since parameter changes in testcontext will not be registered by the configuration database
|
static ThreadLocal<CurrentCommandContext> |
LOCAL_EXECUTION_INFO
ThreadLocal variable: what is the current thread doing?
|
protected Map<String,LockArbitrator.LockOwnerInfo> |
locks
locks management.
|
protected static Logger |
log
logger
|
protected LogBusHandler |
logBusHandler
the logging bushandler: it logs to the lob bus.
|
protected Object |
signalsMonitor
monitor used by "signal" threads
|
protected boolean |
startInEngineeringMode
to be set if we want the subsystem to be started in engineering mode but works only if the subsystem is already in test context.
|
protected Object |
statusBroadcasterLock
monitor for status broadcasting operations
|
protected Thread |
statusBroadcasterThread
the Thread in charge of status broadcasting
|
protected String |
statusBusSelector |
protected boolean |
waitingForCommandTermination
might be used for tests that want to test the result of a command.
|
| Constructor and Description |
|---|
Subsystem()
Deprecated.
|
Subsystem(String name,
Agent.AgentType type) |
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
to be overriden : semantics of an urgent halt
|
void |
abort(long expectedMaxDelay)
to be overriden : semantics of an urgent halt with a time limit
|
void |
addLock(String target,
LockArbitrator.LockOwnerInfo info)
adds a lock (TODO: DOCUMENT)
|
void |
broadcastAlarm()
Deprecated.
|
void |
broadcastAlarm(String message)
Deprecated.
|
void |
broadcastAlarmClear(String message)
Deprecated.
|
void |
broadcastStatus(int statusBroadcastPeriod)
broadcast the current status
|
void |
broadcastStatus(Status s)
broadcast a status object
|
void |
checkAllHardwareStarted()
checks if all hardwares have been correctly started.
|
void |
checkAllHardwareStopped()
checks if all hardwares have been correctly stopped..
|
void |
checkHardware()
to be called before activating anything
and to be called again once problems are supposed to have been addressed.
|
void |
clearAlarms(String message)
clear alarms, publishes an AlarmClear message and returns to Alarm state NOMINAL
|
void |
completeInitialization()
command to complete initialisation (if commands were issued to heal hardware problems)
|
static Subsystem.State |
createState(Phase phase,
Mode mode,
CommandState activity,
AlarmState alarm)
this is for testing purposes only (when in need to compare states)
|
void |
doShutdown()
to be overriden by subclasses.
|
void |
doStart()
Called upon subsystem start.
|
protected Object |
executeCommandSingleThread(Command cmd)
Deprecated.
|
protected Status |
fillStatus(Status s)
Store current state and status information in a Status object.
|
void |
forceShutdown()
to be called before a shutdown, when previous shutdowns faild
|
AgentPresenceManager |
getAgentPresenceManager() |
ThreadGroup |
getAncillaryGroup() |
CCSVersions |
getCCSVersions()
Command to get the CCSVersions object for the current CCS Environment.
|
protected LocalCommandDictionary |
getCommandBuilder(Object obj)
utility method to get a LocalCommandDictionary
|
String |
getCommandBusSelector()
Deprecated.
|
String |
getConfiguration() |
ConfigurationProxy |
getConfigurationProxy() |
Thread |
getCurrentActionThread()
gets the current action thread which is alive (and kills it if zombie)
|
static String |
getCurrentSubsystemName()
Deprecated.
|
String |
getDefaultSelector()
Deprecated.
|
static String |
getEthHardAddress()
MAC address of the main ethernet card
|
Subsystem.State |
getInnerState()
use for tests only
|
Logger |
getLogger() |
MessagingFactory |
getMessagingAccess() |
String |
getName() |
int |
getNumberCommandThreads() |
static String |
getSoftwareRevision()
Software revision
|
PublishedState |
getStateForPublication()
create a Published state containing a clone of the innerstate
|
Status |
getStatus(int statusBroadcastPeriod)
returns our current status, including State can be overriden to
return a Status subclass if needed when not using ModularSubsystem
|
int |
getStatusBroadcastPeriod() |
String |
getStatusBusSelector()
Deprecated.
|
Dictionary |
getSystemDictionary()
command to get the subsystem disctionary
|
String |
getTag() |
void |
initialisationEndPhase(boolean checkHardwareOK)
runs the last phase of initialisation.
|
protected void |
initLogBusHandler()
connects a LogBusHandler to the Log bus.
|
void |
interruptActionThread()
command to send an interrupt to the only action command thread.
|
void |
interruptAllRunningCommands()
command to send an interrupt to all running commands (expected behaviour of commands
is implementation dependant).
|
void |
interruptAllSignalThreads()
command to send an interrupt all "signal" threads
|
void |
interruptAncillaryThreads(String expReg)
a sends a software interrupt to all 'ancillary' Threads
whose name matches the regular expression
|
void |
interruptInitThread()
sends an interrupt to the initialisation thread.
|
boolean |
isInEngineeringMode()
tells if the subystem is in Engineering mode
|
boolean |
isInTestContext()
is this subsystem in test context?
|
boolean |
isListenToStatus()
does this subsystem listen to the status bus
|
boolean |
isMaster()
to be overriden : tells if the subsystem invokes command
|
boolean |
isMultithreaded()
Deprecated.
|
boolean |
isSlave()
to be overriden : tells if the subsystem execute command (they all do: but these are commands that
go further than the standard list of subsystem commands).
|
boolean |
isStartedInEngineeringMode()
is this subsystem started in engineering mode?
|
void |
lockUpdate(String target,
LockArbitrator.LockOwnerInfo info,
boolean isAdd)
TODO: document
|
void |
onAck(CommandAck a)
reveived an ack: to be overriden
|
void |
onCommand(Command cmd)
what happens if a command is received? (see internal comments)
|
void |
onReply(CommandReply r)
Received reply message on the command bus.
|
void |
onStatus(BusMessage s)
Received status message.
|
void |
ping()
broadcast on the status bus a message of presence
|
void |
postStart()
called after subsystem has been started
|
String |
printRunningCommands()
Command returning a String describing which commands are running
|
void |
publishData(DataValueNotification td)
Deprecated.
|
void |
publishData(List<? extends ValueNotification> tdl)
Deprecated.
|
void |
publishData(String name,
Object value)
Deprecated.
|
void |
publishData(String name,
Object value,
long tStamp)
Deprecated.
|
void |
publishData(String name,
Serializable value)
Deprecated.
|
void |
publishData(String name,
Serializable value,
long tStamp)
Deprecated.
|
void |
publishData(ValueNotification td)
Deprecated.
|
void |
publishMetaData(String dataname,
String metadataname,
String value)
Sends trending metadata on the status bus
It allows to associate to some some data associated meta data like alarm limits.
|
void |
publishReply(CommandReply myReply)
Deprecated.
|
protected void |
publishStateChange(Subsystem.State before,
Subsystem.State after)
internal service: publishes a state transition
|
void |
publishStatus(KVList kvlist) |
void |
publishStatus(List<ValueNotification> tdl) |
void |
publishStatus(long timestamp,
KVList kvlist) |
void |
publishStatus(long timestamp,
String key,
Object value) |
void |
publishStatus(String key,
long[] timestamps,
Object[] objects) |
void |
publishStatus(String key,
Object value) |
protected void |
publishStatusData(EncodedDataStatus dataStatus) |
protected void |
publishTrendingStatus(TrendingStatus ts) |
void |
raiseAlarm(String message)
raises an Alarm: state is switched to ENGINEERING_FAULT and ALARM , state change published.
|
protected Object |
rawCommandExecution(Command cmd,
Object obj)
placeholder for future modification of command execution
|
void |
registerAsBusMaster()
todo: implement relevant code
|
void |
removeLock(String target)
removes a lock (TODO: document)
|
void |
removeLogPanicState()
tries to reset the panic state of a the Log Bus Handler (logging
failed before)
|
protected Subsystem.DictionarySearchResult |
searchForDictionary(boolean fatal,
Command command,
Object goal,
LocalCommandDictionary localDict)
utility method to produce a DictionarySearchResultObject.
|
protected Subsystem.DictionarySearchResult |
searchForDictionary(Command command)
searches for details of an incoming command
|
void |
sendRawStatus(Status status)
sends a status message which is not to be published as data for the trending database.
|
void |
setBusLogHandlerLevel(String levelName)
sets the level at which the Log Bus Hander will start logging.
|
void |
setCommandBusSelector(String selector)
Deprecated.
|
protected void |
setConfigurationProxy(ConfigurationProxy configurationProxy)
this method should not be used once the proxy is delegated to all components
so it should not be public!
TODO: this makes only sense for Modular subsystem (so move away)
|
void |
setListenToStatus(boolean listenToStatus)
Will this subsystem listen to the status bus?
|
void |
setLogFormat(String format)
command to set a format for the TextFormatter of LogBusHandler (see logging.properties doc)
|
void |
setLogHandlerLevel(String handler,
String level)
Command to set a level for a given handler
|
void |
setLogLevel(String keyLogger,
String levelName)
sets the Level of a named Logger
|
void |
setMultithreaded(boolean multithreaded)
Deprecated.
|
void |
setName(String name)
Deprecated.
use subsystem(String name, AgentType type) constructor instead of empty constructor
|
void |
setStackTraceDepth(int depth)
Will modify the depth of stackTrace printing for ALL handlers (including the LogBusHandler)
|
void |
setStatusBroadcastPeriod(int statusBroadcastPeriod)
how often (in seconds) should our status be broadcasted?
|
void |
setStatusBusSelector(String selector)
Deprecated.
|
Object |
shutdown()
Clean shutdown of subsystem: call stop for hardware stopping before invoking this method.
|
void |
start()
Starts the subsystem.
|
protected void |
startStatusBroadcasting()
Starts broadcasting our status
|
void |
stayAlive()
Blocks the current thread that started the subsystem until the subsystem receives a shutdown.
|
void |
stop(long expectedMaxDelay)
to be overriden : semantics of "soft" stop
|
protected void |
stopStatusBroadcasting()
Stops broadcasting our status
This can only be called when the subsystem is shutting down
|
boolean |
switchToEngineeringMode()
command to switch to ENGINEERING mode
|
void |
switchToErrorState(String message)
Deprecated.
|
void |
switchToNormalMode()
tries to get back to normal mode
|
protected void |
switchToShutdownState()
state modifications linked to a shutdown request
|
void |
tryReadyState(String message)
command to try to switch to READY state
|
protected void |
updateCurrentSubsystem()
Deprecated.
|
org.lsst.ccs.SystemState |
updateState(org.lsst.ccs.SystemState newState)
Deprecated.
|
org.lsst.ccs.SystemState |
updateState(org.lsst.ccs.SystemState newState,
String extraInfo)
Deprecated.
|
boolean |
waitForCommandExecution(long timeOut)
mostly used for tests that need to test the result of single command execution
|
boolean |
waitForReadyState()
waits for all actions and signals to terminate before switching to READY.
|
void |
warning(String message)
publishes a warning -> Alarm state to WARNING
|
protected Subsystem.State innerState
protected volatile boolean initializing
protected volatile boolean closing
protected ThreadGroup commandGroup
protected ThreadGroup ancillaryGroup
protected final Object actionMonitor
protected final Object commandMonitor
protected volatile boolean waitingForCommandTermination
protected final Object signalsMonitor
protected Thread initThread
protected volatile boolean forceShutdown
protected static Logger log
protected MessagingFactory fac
protected String commandBusSelector
protected String statusBusSelector
protected boolean inTestContext
protected boolean startInEngineeringMode
protected ConfigurationProxy configurationProxy
protected LogBusHandler logBusHandler
protected LocalCommandDictionary commandBuilder
protected volatile Thread statusBroadcasterThread
protected volatile Object statusBroadcasterLock
protected Map<String,LockArbitrator.LockOwnerInfo> locks
@Deprecated protected static ThreadLocal<Subsystem> currentSubsystem
public static final ThreadLocal<CurrentCommandContext> LOCAL_EXECUTION_INFO
@Deprecated public Subsystem()
public Subsystem(String name, Agent.AgentType type)
public static Subsystem.State createState(Phase phase, Mode mode, CommandState activity, AlarmState alarm)
phase - mode - activity - alarm - public static String getSoftwareRevision()
public MessagingFactory getMessagingAccess()
public Subsystem.State getInnerState()
@Command(description="is the system in engineering mode ?", type=QUERY, category=SYSTEM) public boolean isInEngineeringMode()
public boolean isMaster()
public boolean isSlave()
public static String getEthHardAddress()
public Logger getLogger()
public Thread getCurrentActionThread()
public ThreadGroup getAncillaryGroup()
public void setListenToStatus(boolean listenToStatus)
public boolean isListenToStatus()
@Command(description="is the system in test context", type=QUERY, category=SYSTEM) public boolean isInTestContext()
public boolean isStartedInEngineeringMode()
@Deprecated public void setName(String name)
name - protected void initLogBusHandler()
public String getName()
public String getConfiguration()
public String getTag()
public ConfigurationProxy getConfigurationProxy()
protected void setConfigurationProxy(ConfigurationProxy configurationProxy)
@Deprecated public String getDefaultSelector()
@Deprecated public String getStatusBusSelector()
@Deprecated public void setStatusBusSelector(String selector)
@Deprecated public String getCommandBusSelector()
@Deprecated public void setCommandBusSelector(String selector)
public void start()
Not to be overriden, will call doStart
public void initialisationEndPhase(boolean checkHardwareOK)
throws HardwareException
checkHardwareOK - false if engineering fault was entered due to checkHardware errorsHardwareException - if some hardware is still not startedpublic void stayAlive()
@Command(description="completes initialization after hardware problems corrections", type=ACTION) public void completeInitialization() throws SystemStateException, HardwareException
public void doStart()
To be overriden by derived classes if required
public void postStart()
throws HardwareException
to be overriden.
HardwareException - because some "homing" operations may be tried by the hardwarepublic void checkHardware()
throws HardwareException
HardwareExceptionpublic void checkAllHardwareStarted()
throws HardwareException
HardwareException - a compound exception that list the exceptions fired by hardwares that
are not started.public void checkAllHardwareStopped()
throws HardwareException
HardwareException - a compound exception that list the exceptions fired by hardwares that
are not stopped.public Status getStatus(int statusBroadcastPeriod)
protected Status fillStatus(Status s)
public void setStatusBroadcastPeriod(int statusBroadcastPeriod)
statusBroadcastPeriod - (seconds)public int getStatusBroadcastPeriod()
protected void stopStatusBroadcasting()
protected void startStatusBroadcasting()
public void broadcastStatus(int statusBroadcastPeriod)
public void broadcastStatus(Status s)
s - @Command(description="shutdown", type=ACTION) public Object shutdown() throws HardwareException
HardwareException - if some hardware is not stoppedpublic void doShutdown()
@Command(description="forces blocked shutdown (not implemented yet!)", type=ABORT) public void forceShutdown()
@Command(description="halt hardware", type=ABORT) public void abort()
@Command(description="halt hardware with expected max delay", type=ABORT) public void abort(long expectedMaxDelay)
@Command(description="stops hardware with expected max delay", type=ACTION) public void stop(long expectedMaxDelay) throws HardwareException
expectedMaxDelay - time limit for executionHardwareException@Deprecated public org.lsst.ccs.SystemState updateState(org.lsst.ccs.SystemState newState, String extraInfo)
newState - @Deprecated public org.lsst.ccs.SystemState updateState(org.lsst.ccs.SystemState newState)
protected void publishStateChange(Subsystem.State before, Subsystem.State after)
before - after - protected void switchToShutdownState()
@Command(description="switch to ENGINEERING mode", type=ACTION) public boolean switchToEngineeringMode()
@Command(description="Tries to get back to NORMAL mode", type=ACTION) public void switchToNormalMode() throws SystemStateException
SystemStateException - if alarms are not cleared or signals are still runningpublic void raiseAlarm(String message)
message - @Deprecated public void switchToErrorState(String message)
public void warning(String message)
message - @Command(description="clear alarms", type=QUERY) public void clearAlarms(String message)
message - @Command(description="tries to switch to READY ", type=QUERY) public void tryReadyState(String message) throws SystemStateException
message - SystemStateException - if acction commands or signals are still running or if the subsystem is closing@Command(description="tries to wait until READY ", type=QUERY) public boolean waitForReadyState() throws ClosingStateException
ClosingStateException - if closingpublic PublishedState getStateForPublication()
@Deprecated public void broadcastAlarm()
@Deprecated public void broadcastAlarm(String message)
@Deprecated public void broadcastAlarmClear(String message)
@Deprecated public boolean isMultithreaded()
isMultithreaded in interface CommandExecutor@Deprecated public void setMultithreaded(boolean multithreaded)
multithreaded - @Deprecated public static String getCurrentSubsystemName()
@Deprecated protected void updateCurrentSubsystem()
public void addLock(String target, LockArbitrator.LockOwnerInfo info)
target - info - public void removeLock(String target)
target - public void lockUpdate(String target, LockArbitrator.LockOwnerInfo info, boolean isAdd)
target - info - isAdd - public void onCommand(Command cmd)
onCommand in interface CommandListenercmd - public boolean waitForCommandExecution(long timeOut)
timeOut - @Deprecated protected Object executeCommandSingleThread(Command cmd)
cmd - The command to be executedprotected Subsystem.DictionarySearchResult searchForDictionary(Command command) throws CommandInvocationException
command - CommandInvocationExceptionprotected Subsystem.DictionarySearchResult searchForDictionary(boolean fatal, Command command, Object goal, LocalCommandDictionary localDict) throws CommandInvocationException
fatal - command - goal - localDict - CommandInvocationExceptionprotected LocalCommandDictionary getCommandBuilder(Object obj)
obj - @Command(description="get the command dictionary for the subsystem", type=QUERY, category=SYSTEM) public Dictionary getSystemDictionary()
@Command(description="Get the CCS Versions for the current CCS Environment", type=QUERY, category=SYSTEM) public CCSVersions getCCSVersions()
protected Object rawCommandExecution(Command cmd, Object obj) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
cmd - obj - NoSuchMethodExceptionIllegalAccessExceptionInvocationTargetExceptionpublic void onStatus(BusMessage s)
onStatus in interface StatusListenerpublic void onReply(CommandReply r)
onReply in interface CommandListenerpublic void onAck(CommandAck a)
onAck in interface CommandListenera - public void registerAsBusMaster()
@Deprecated public void publishData(String name, Object value, long tStamp)
@Deprecated public void publishData(String name, Serializable value, long tStamp)
@Deprecated public void publishData(String name, Object value)
@Deprecated public void publishData(String name, Serializable value)
@Deprecated public void publishData(List<? extends ValueNotification> tdl)
@Deprecated public void publishData(ValueNotification td)
@Deprecated public void publishData(DataValueNotification td)
protected void publishTrendingStatus(TrendingStatus ts)
public void publishMetaData(String dataname, String metadataname, String value)
protected void publishStatusData(EncodedDataStatus dataStatus)
public void publishStatus(long timestamp,
KVList kvlist)
public void publishStatus(KVList kvlist)
public void publishStatus(List<ValueNotification> tdl)
tdl - @Deprecated public void publishReply(CommandReply myReply)
public void sendRawStatus(Status status)
status - @Command(description="set the level of the BusLogHandler", type=QUERY) public void setBusLogHandlerLevel(String levelName)
levelName - the name of a JUL Level@Command(description="set the level of a Logger", type=QUERY) public void setLogLevel(String keyLogger, String levelName)
keyLogger - name of Logger (can be a package or a "concern" such
as "INIT", "CONFIG"levelName - the name of a JUL Level@Command(description="sets the the depth of stacktraces in Logger messages", type=QUERY) public void setStackTraceDepth(int depth)
depth - could be negative if we want all the stackTrace@Command(description="sets the format used by TextFormatter for LogEvent messages ", type=QUERY) public void setLogFormat(String format)
format - @Command(description="sets the handler (ConsoleHandlerN, FileHandlerN, LogBusHandler) log level", type=QUERY) public void setLogHandlerLevel(String handler, String level)
handler - can be ConsoleHandlerN, FileHandlerN, LogBusHandlerlevel - @Command(description="tries to stop the panic state of logmanagement", type=QUERY) public void removeLogPanicState()
@Command(description="gets the number of commands which are currently running (except the current one!)", type=QUERY) public int getNumberCommandThreads()
@Command(description="gets the name of commands which are currently running", type=QUERY) public String printRunningCommands()
@Command(description="sends an interrupt for all command threads (behaviour of commands are implementation dependent)", type=ABORT) public void interruptAllRunningCommands()
@Command(description="sends an interrupt to a running ACTION thread", type=ABORT) public void interruptActionThread()
@Command(description="sends an interrupt to all running SIGNAL threads", type=ABORT) public void interruptAllSignalThreads()
@Command(description="sends an interrupt to any \'ancillary\' thread whose name matches the regular expression passed as argument", type=ABORT) public void interruptAncillaryThreads(String expReg)
expReg - @Command(description="sends an interrupt to the initialization thread", type=ABORT) public void interruptInitThread()
@Command(description="broadcast on the status bus a message of presence", type=QUERY, category=SYSTEM) public void ping()
public AgentPresenceManager getAgentPresenceManager()
Copyright © 2015 LSST. All rights reserved.