Package org.yamcs.algorithms
Class AlgorithmManager
- java.lang.Object
-
- com.google.common.util.concurrent.AbstractService
-
- org.yamcs.AbstractProcessorService
-
- org.yamcs.algorithms.AlgorithmManager
-
- All Implemented Interfaces:
com.google.common.util.concurrent.Service,DVParameterConsumer,ParameterProvider,ProcessorService
public class AlgorithmManager extends AbstractProcessorService implements ParameterProvider, DVParameterConsumer, ProcessorService
Manages the provision of requested parameters that require the execution of one or more XTCE algorithms.Upon initialization it will scan all algorithms, and schedule any that are to be triggered periodically. OutputParameters of all algorithms will be indexed, so that AlgorithmManager knows what parameters it can provide to the ParameterRequestManager.
Algorithms and any needed algorithms that require earlier execution, will be activated as soon as a request for one of its output parameters is registered.
Algorithm executors are created by
AlgorithmExecutorFactorywhich themselves are created by theAlgorithmEngine. The algorithm engines are registered at server startup using theregisterAlgorithmEngine(String, AlgorithmEngine)method. javascript will be automatically registered as well as python if available.
-
-
Field Summary
-
Fields inherited from class org.yamcs.AbstractProcessorService
config, log, processor
-
-
Constructor Summary
Constructors Constructor Description AlgorithmManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateAlgorithm(Algorithm algorithm, AlgorithmExecutionContext execCtx, AlgorithmExecListener listener)Activate an algorithm in a context if not already active.booleancanProvide(org.yamcs.protobuf.Yamcs.NamedObjectId itemId)Returns whether or not a given parameter can be provided by this providerbooleancanProvide(Parameter p)voidclearAlgorithmOverride(CustomAlgorithm calg)AlgorithmExecutionContextcreateContext(String name)Create a new algorithm execution context.voiddeactivateAlgorithm(Algorithm algorithm, AlgorithmExecutionContext execCtx)protected voiddoStart()protected voiddoStop()ParametergetParameter(org.yamcs.protobuf.Yamcs.NamedObjectId paraId)Returns the parameterDefinition corresponding to the parameter idProcessorgetProcessor()intgetSubscriptionId()voidinit(Processor processor, YConfiguration config, Object spec)static voidregisterAlgorithmEngine(String name, AlgorithmEngine eng)voidsetAlgorithmText(CustomAlgorithm calg, String text)Override the algorithmvoidsetParameterListener(ParameterListener parameterRequestManager)Send parameters to this listener.voidstartProviding(Parameter paramDef)Adds a new parameter to the list of parameters that have to providedvoidstartProvidingAll()start providing all known parametersvoidstopProviding(Parameter paramDef)Removes a parameter from the list of parameters that have to be providedList<ParameterValue>updateParameters(int subscriptionId, List<ParameterValue> items)List<ParameterValue>updateParameters(List<ParameterValue> items, AlgorithmExecutionContext ctx)Update parameters in context and run the affected algorithms-
Methods inherited from class org.yamcs.AbstractProcessorService
getConfig, getYamcsInstance
-
Methods inherited from class com.google.common.util.concurrent.AbstractService
addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, failureCause, isRunning, notifyFailed, notifyStarted, notifyStopped, startAsync, state, stopAsync, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.yamcs.ProcessorService
getSpec
-
-
-
-
Method Detail
-
init
public void init(Processor processor, YConfiguration config, Object spec)
- Specified by:
initin interfaceProcessorService- Overrides:
initin classAbstractProcessorServiceconfig- service configuration as specified in processor.yamlspec- passed by the user when creating the processor (for instance via the REST API)
-
registerAlgorithmEngine
public static void registerAlgorithmEngine(String name, AlgorithmEngine eng)
-
getSubscriptionId
public int getSubscriptionId()
-
startProviding
public void startProviding(Parameter paramDef)
Description copied from interface:ParameterProviderAdds a new parameter to the list of parameters that have to provided- Specified by:
startProvidingin interfaceParameterProvider
-
createContext
public AlgorithmExecutionContext createContext(String name)
Create a new algorithm execution context.- Parameters:
name- - name of the context- Returns:
- the newly created context
-
activateAlgorithm
public void activateAlgorithm(Algorithm algorithm, AlgorithmExecutionContext execCtx, AlgorithmExecListener listener)
Activate an algorithm in a context if not already active. If already active, the listener is added to the listener list.- Parameters:
algorithm-execCtx-listener-
-
deactivateAlgorithm
public void deactivateAlgorithm(Algorithm algorithm, AlgorithmExecutionContext execCtx)
-
startProvidingAll
public void startProvidingAll()
Description copied from interface:ParameterProviderstart providing all known parameters- Specified by:
startProvidingAllin interfaceParameterProvider
-
stopProviding
public void stopProviding(Parameter paramDef)
Description copied from interface:ParameterProviderRemoves a parameter from the list of parameters that have to be provided- Specified by:
stopProvidingin interfaceParameterProvider
-
canProvide
public boolean canProvide(Parameter p)
- Specified by:
canProvidein interfaceParameterProvider
-
canProvide
public boolean canProvide(org.yamcs.protobuf.Yamcs.NamedObjectId itemId)
Description copied from interface:ParameterProviderReturns whether or not a given parameter can be provided by this provider- Specified by:
canProvidein interfaceParameterProvider- Returns:
-
getParameter
public Parameter getParameter(org.yamcs.protobuf.Yamcs.NamedObjectId paraId) throws InvalidIdentification
Description copied from interface:ParameterProviderReturns the parameterDefinition corresponding to the parameter id- Specified by:
getParameterin interfaceParameterProvider- Parameters:
paraId- - id of the parameter that is returned- Returns:
- Throws:
InvalidIdentification
-
updateParameters
public List<ParameterValue> updateParameters(int subscriptionId, List<ParameterValue> items)
- Specified by:
updateParametersin interfaceDVParameterConsumer
-
updateParameters
public List<ParameterValue> updateParameters(List<ParameterValue> items, AlgorithmExecutionContext ctx)
Update parameters in context and run the affected algorithms- Parameters:
items-ctx-- Returns:
- the parameters resulting from running the algorithms
-
setParameterListener
public void setParameterListener(ParameterListener parameterRequestManager)
Description copied from interface:ParameterProviderSend parameters to this listener. Normally is the channel.parameterRequestManager but something different may be used for unit tests or special applications (PacketViewer)- Specified by:
setParameterListenerin interfaceParameterProvider
-
doStart
protected void doStart()
- Specified by:
doStartin classcom.google.common.util.concurrent.AbstractService
-
doStop
protected void doStop()
- Specified by:
doStopin classcom.google.common.util.concurrent.AbstractService
-
getProcessor
public Processor getProcessor()
-
clearAlgorithmOverride
public void clearAlgorithmOverride(CustomAlgorithm calg)
-
setAlgorithmText
public void setAlgorithmText(CustomAlgorithm calg, String text)
Override the algorithm- Parameters:
calg-text-
-
-