Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* Starting with Yamcs 5.5.0, all system parameters have types defined in the MDB. For the basic types (corresponding to
* scalar values), this class will provide some types (e.g. uint65, float32, etc)
*
* For aggregate, the caller can use the {@link #createSystemParameter(String, AggregateParameterType, String)} to make
* the parameter and also add the corresponding type to the MDB.
*
*/
public class SystemParametersService extends AbstractYamcsService implements Runnable {
static Map instances = new HashMap<>();
static long frequencyMillisec = 1000;
List providers = new CopyOnWriteArrayList<>();
static final String STREAM_NAME = "sys_param";
Stream stream;
int seqCount = 0;
// /yamcs/
private String namespace;
private String serverId;
Mdb mdb;
TimeService timeService;
ScheduledFuture> collectionFuture;
@Override
public Spec getSpec() {
Spec spec = new Spec();
spec.addOption("provideJvmVariables", OptionType.BOOLEAN).withDefault(false)
.withDeprecationMessage("This option is obsolete, please add 'jvm' to the list of producers");
spec.addOption("provideFsVariables", OptionType.BOOLEAN).withDefault(false)
.withDeprecationMessage("This option is obsolete, please add 'fs' to the list of producers");
spec.addOption("producers", OptionType.LIST)
.withRequired(false)
.withElementType(OptionType.STRING)
.withDescription("Current providers are: jvm, fs and diskstats. Diskstats only works on Linux");
return spec;
}
@Override
public void init(String yamcsInstance, String serviceName, YConfiguration config) throws InitException {
super.init(yamcsInstance, serviceName, config);
mdb = YamcsServer.getServer().getInstance(yamcsInstance).getMdb();
YarchDatabaseInstance ydb = YarchDatabase.getInstance(yamcsInstance);
stream = ydb.getStream(STREAM_NAME);
if (stream == null) {
throw new ConfigurationException("Stream '" + STREAM_NAME + "' does not exist");
}
serverId = YamcsServer.getServer().getServerId();
namespace = Mdb.YAMCS_SPACESYSTEM_NAME + NameDescription.PATH_SEPARATOR + serverId;
List producers = config.containsKey("producers") ? producers = config.getList("producers")
: Collections.emptyList();
log.debug("Using {} as serverId, and {} as namespace for system parameters", serverId, namespace);
if (config.getBoolean("provideJvmVariables") || producers.contains("jvm")) {
providers.add(new SysVarProducer(new JvmParameterProducer(this)));
}
if (config.getBoolean("provideFsVariables") || producers.contains("fs")) {
try {
providers.add(new SysVarProducer(new FileStoreParameterProducer(this)));
} catch (IOException e) {
throw new InitException(e);
}
}
if (producers.contains("diskstats")) {
try {
if (DiskstatsParameterProducer.hasDisksStats()) {
providers.add(new SysVarProducer(new DiskstatsParameterProducer(this)));
} else {
log.info("No /proc/diskstats present, cannot produce diskstats parameters (only works on Linux)");
}
} catch (IOException e) {
throw new InitException(e);
}
}
if (producers.contains("rocksdb")) {
var producer = RdbStorageEngine.getInstance().newRdbParameterProducer(yamcsInstance, this);
providers.add(new SysVarProducer(producer));
}
synchronized (instances) {
instances.put(yamcsInstance, this);
}
}
public static SystemParametersService getInstance(String instance) {
synchronized (instances) {
return instances.get(instance);
}
}
@Override
public void doStart() {
YamcsServer server = YamcsServer.getServer();
timeService = server.getInstance(yamcsInstance).getTimeService();
ScheduledThreadPoolExecutor timer = server.getThreadPoolExecutor();
collectionFuture = timer.scheduleAtFixedRate(this, 1000L, frequencyMillisec, TimeUnit.MILLISECONDS);
notifyStarted();
}
@Override
public void doStop() {
collectionFuture.cancel(true);
synchronized (instances) {
instances.remove(yamcsInstance);
}
try {
collectionFuture.get();
notifyStopped();
} catch (CancellationException e) {
notifyStopped();
} catch (Exception e) {
notifyFailed(e);
}
}
/**
* Run from the timer, collect all parameters and send them on the stream
*/
@Override
public void run() {
long gentime = timeService.getMissionTime();
List params = new ArrayList<>();
for (SysVarProducer svp : providers) {
svp.count++;
if (svp.count >= svp.freq) {
svp.count = 0;
try {
Collection pvc = svp.producer.getSystemParameters(gentime);
params.addAll(pvc);
} catch (Exception e) {
log.warn("Error getting parameters from provider {}", svp.producer, e);
}
}
}
if (params.isEmpty()) {
return;
}
TupleDefinition tdef = StandardTupleDefinitions.PARAMETER.copy();
List