Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
public class SampleAgent implements AgentStateListener<AgentConfigManager> { // <--- UPDATE THIS LINE
...
    private MOXodusPersistence moXodusPersistence;   // <--- ADD THIS LINE     
    protected AgentConfigManager agent;
...
}


Code Block
languagejava
// Enclose the following code block (most likely part of the constructor) that loads the default configuration with the following if-statement:

        // load initial configuration from properties file only if there is no persistent data for the default context:
        moXodusPersistence = new MOXodusPersistence(moServers, Environments.newInstance(configFile));  // <--- ADD THIS LINE
        if (!moXodusPersistence.isContextLoadable(null)) {                                             // <--- ADD THIS LINE
            InputStream configInputStream =
                    SampleAgent.class.getResourceAsStream("SampleAgentConfig.properties");
            if (args.containsKey("cfg")) {
                String configFilename = (String) ArgumentParser.getValue(args, "cfg", 0);
                try {
                    configInputStream = new FileInputStream(configFilename);
                } catch (FileNotFoundException ex1) {
                    logger.error("Config file '" + configFilename + "' not found: " + ex1.getMessage(), ex1);
                    throw new RuntimeException(ex1);
                }
            }
            final Properties props = new Properties();
            try {
                props.load(configInputStream);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            configurationFactory = () -> new PropertyMOInput(props, agent);
        }

...