Package org.lsst.ccs.scripting
Class CCS
java.lang.Object
org.lsst.ccs.scripting.CCS
Main scripting entry point to CCS. This class is used to create scripting
entry points to CCS subsystems through
ScriptingSubsystemWrapper, register a
ScriptingStatusBusListener to listen to Status
messages on the CCS Status Bus and to suspend the script execution until a
given Status message meets the criteria of a filter:
ScriptingStatusBusMessageFilter.- Author:
- The LSST CCS Team
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdd a Status bus listener.static voidaddStatusBusListener(ScriptingStatusBusListener listener, ScriptingStatusBusMessageFilter filter) Add a Status bus listener with a filter.static ScriptingSubsystemWrapperattachSubsystem(String target) Creates and instance of a ScriptingSubsystemWrapper by making sure that the giventargetcorresponds to a CCS subsystem that is currently available, not locked and alive.static ScriptingSubsystemWrapperattachSubsystem(String target, boolean lock) Creates and instance of a ScriptingSubsystemWrapper by making sure that the giventargetcorresponds to a CCS subsystem that is currently alive.That method will attempt to acquire a lock only iflockis set to true.static ScriptingSubsystemWrapperattachSubsystem(String target, int level) Creates and instance of a ScriptingSubsystemWrapper by making sure that the giventargetcorresponds to a CCS subsystem that is currently available, not locked and alive.static voidcleanUp()Clean up the ThreadLocal stack, (close all subsystems and remove all listeners).Get the list of available Agents on the buses.static DurationGet the default timeout to be used when sending commands.static AgentMessagingLayergetTargetsForSubsystem(String subsystemName) Get the command targets for the provided subsystem.static booleanReturns true if exceptions are thrown, otherwise they are returned as the Object on the invoke methods.static voidIn a test context, this method has to be called in the first placestatic voidRemoves the Status bus listener.static voidsetDefaultTimeout(Duration timeout) Set the default timeout to be used when sending commands.static voidsetShareLocksAcrossThreads(boolean shareLocks) Indicates whether locks should be shared across threads or made exclusive to the calling thread.static voidsetThrowExceptions(boolean throwExceptions) In the scripting environment, exceptions resulted from method invocation can either be thrown or returned.static voidsetUnlockOnExit(boolean unlockWhenExit) Indicates whether locks should be released when the script terminates.static voidIn a test context, this method can be called to shutdown scripting environmentstatic Future<ScriptingStatusBusMessage>startListeningForStatusBusMessage(ScriptingStatusBusMessageFilter filter, Duration timeout) Get a Future on a ScriptingStatusBusMessage.
-
Method Details
-
getMessagingAccess
-
getAvailableAgents
Get the list of available Agents on the buses.- Returns:
- The list of AgentInfo for the agents on the buses.
-
setDefaultTimeout
Set the default timeout to be used when sending commands. The default timeout Duration must be greater than zero. The default timeout will be used when: - no timeout is specified when invoking a command - no timeout is returned in the command ack as received from the command invocation over the buses- Parameters:
timeout- The default timeout Duration.
-
getDefaultTimeoutDuration
Get the default timeout to be used when sending commands.- Returns:
- The default timeout Duration.
-
setUnlockOnExit
public static void setUnlockOnExit(boolean unlockWhenExit) Indicates whether locks should be released when the script terminates.- Parameters:
unlockWhenExit-
-
initializeScriptingEnvironment
public static void initializeScriptingEnvironment()In a test context, this method has to be called in the first place -
shutdownScriptingEnvironment
In a test context, this method can be called to shutdown scripting environment- Throws:
Exception- If something goes wrong
-
setThrowExceptions
public static void setThrowExceptions(boolean throwExceptions) In the scripting environment, exceptions resulted from method invocation can either be thrown or returned. Use this method to toggle between the two options.- Parameters:
throwExceptions- boolean flag. If true exceptions will be thrown.
-
getThrowExceptions
public static boolean getThrowExceptions()Returns true if exceptions are thrown, otherwise they are returned as the Object on the invoke methods.- Returns:
- true/false to indicate if exceptions are thrown/returned
-
attachSubsystem
Creates and instance of a ScriptingSubsystemWrapper by making sure that the giventargetcorresponds to a CCS subsystem that is currently available, not locked and alive. That method will attempt to acquire a lock on the subsystem. Note : it is equivalent toattachSubsystem(target, true)- Parameters:
target- The name of the CCS subsystem. e.g. ccs-rafts, or one of its inner component, e.g. ccs-rafts/REB1- Returns:
- The ScriptingSubsystemWrapper representing the CCS subsystem
- Throws:
RuntimeException- if no subsystem corresponding totargetcan be found on the buses, or if the subsystem could not be locked.
-
attachSubsystem
Creates and instance of a ScriptingSubsystemWrapper by making sure that the giventargetcorresponds to a CCS subsystem that is currently available, not locked and alive. That method will attempt to acquire a lock on the subsystem, and to override the obtained lock's level with the givenlevel.- Parameters:
target- The name of the CCS subsystem. e.g. ccs-rafts, or one of its inner component, e.g. ccs-rafts/REB1level- a level that overrides the acquired lock level.- Returns:
- The ScriptingSubsystemWrapper representing the CCS subsystem
- Throws:
Exception- if no subsystem corresponding totargetcan be found on the buses, or if the subsystem could not be locked.
-
attachSubsystem
public static ScriptingSubsystemWrapper attachSubsystem(String target, boolean lock) throws UnauthorizedLockException, IOException Creates and instance of a ScriptingSubsystemWrapper by making sure that the giventargetcorresponds to a CCS subsystem that is currently alive.That method will attempt to acquire a lock only iflockis set to true.- Parameters:
target- The name of the CCS subsystem. e.g. ccs-rafts, or one of its inner component, e.g. ccs-rafts/REB1lock- true if the subsystem should be locked, false otherwise.- Returns:
- The ScriptingSubsystemWrapper representing the CCS subsystem
- Throws:
UnauthorizedLockExceptionIOException
-
cleanUp
public static void cleanUp()Clean up the ThreadLocal stack, (close all subsystems and remove all listeners). -
addStatusBusListener
Add a Status bus listener.- Parameters:
listener- The ScriptingStatusListener
-
addStatusBusListener
public static void addStatusBusListener(ScriptingStatusBusListener listener, ScriptingStatusBusMessageFilter filter) Add a Status bus listener with a filter.- Parameters:
listener- The ScriptingStatusListenerfilter- The ScriptingStatusBusMessageFilter
-
removeStatusBusListener
Removes the Status bus listener.- Parameters:
listener- The listener to be removed.
-
startListeningForStatusBusMessage
public static Future<ScriptingStatusBusMessage> startListeningForStatusBusMessage(ScriptingStatusBusMessageFilter filter, Duration timeout) Get a Future on a ScriptingStatusBusMessage. The content of the Future is filled when the first StatusBusMessage that satisfies the ScriptingStatusBusMessageFilter is received. When the Future is exercised it will return the first ScriptingStatusBusMessage or an ExecutionException will be thrown when the timeout is reached.- Parameters:
filter- ScriptingStatusBusMessageFilter The message filtertimeout- Timeout Duration, after which a ScriptiongTimeoutException is thrown. This timeout is from the time the method is invoked. If this timeout is reached an exception will be thrown if/when the Future is exercised.- Returns:
- A Future on a ScriptingStatusBusMessage.
-
getTargetsForSubsystem
Get the command targets for the provided subsystem.- Parameters:
subsystemName- The name of the subsystem- Returns:
- The List of command targets.
-