Search in sources :

Example 1 with Config

use of io.openems.core.Config in project openems by OpenEMS.

the class App method main.

// public final static String OPENEMS_VERSION = "2018.5.0-SNAPSHOT";
public static void main(String[] args) {
    log.info("OpenEMS version [" + OPENEMS_VERSION + "] started");
    // parse cli
    Option helpOption = Option.builder("h").longOpt("help").required(false).desc("shows this message").build();
    Option configFileOption = Option.builder("c").longOpt("configFile").numberOfArgs(1).required(false).type(String.class).desc("path for the configFile").build();
    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(configFileOption);
    CommandLineParser parser = new DefaultParser();
    CommandLine cmdLine;
    String configPath = null;
    try {
        cmdLine = parser.parse(options, args);
        if (cmdLine.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("openEMS", options);
            System.exit(0);
        } else {
            configPath = cmdLine.hasOption("configFile") ? (String) cmdLine.getParsedOptionValue("configFile") : null;
        }
    } catch (ParseException e1) {
        log.error("cli parsing failed!", e1);
    }
    // kick the watchdog: READY
    SDNotify.sendNotify();
    // configure Restlet logging
    Engine.getInstance().setLoggerFacade(new Slf4jLoggerFacade());
    // Get config
    try {
        Config config = Config.initialize(configPath);
        config.readConfigFile();
    } catch (Exception e) {
        App.shutdownWithError("OpenEMS Edge start failed", e);
    }
    log.info("OpenEMS Edge started");
    log.info("================================================================================");
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) Slf4jLoggerFacade(org.restlet.ext.slf4j.Slf4jLoggerFacade) Config(io.openems.core.Config) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 2 with Config

use of io.openems.core.Config in project openems by OpenEMS.

the class FeneconPersistence method dispose.

@Override
protected void dispose() {
    this.reconnectingWebsocket.dispose();
    try {
        Config config = Config.getInstance();
        config.removeOnConfigUpdateListener(this.onConfigUpdate);
    } catch (ConfigException e) {
        log.error(e.getMessage());
    }
}
Also used : Config(io.openems.core.Config) ConfigException(io.openems.api.exception.ConfigException)

Aggregations

Config (io.openems.core.Config)2 ConfigException (io.openems.api.exception.ConfigException)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Option (org.apache.commons.cli.Option)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 Slf4jLoggerFacade (org.restlet.ext.slf4j.Slf4jLoggerFacade)1