Date: Fri, 29 Mar 2024 11:05:10 +0000 (UTC) Message-ID: <1288071338.163.1711710310115@2997b7dde346> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_162_822915841.1711710310115" ------=_Part_162_822915841.1711710310115 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
RandomAccessManagedObject
is=
written to disk immediately during COMMIT phase.In your main agent code, first add the member moXodusPersistenceProvider= and initialise it as follows:
public = class SampleAgent implements AgentStateListener<AgentConfigManager> {= // <--- UPDATE THIS LINE ... private MOXodusPersistence moXodusPersistence; // <--- ADD TH= IS LINE =20 protected AgentConfigManager agent; ... }
// Encl= ose the following code block (most likely part of the constructor) that loa= ds 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 =3D new MOXodusPersistence(moServ= ers, Environments.newInstance(configFile)); // <--- ADD THIS LINE if (!moXodusPersistence.isContextLoadable(null)) { &n= bsp; = // <--- ADD TH= IS LINE InputStream configInputStream =3D SampleAgent.class.getResourceAsStream("SampleAgentConfi= g.properties"); if (args.containsKey("cfg")) { String configFilename =3D (String) ArgumentParser.getValue(= args, "cfg", 0); try { configInputStream =3D new FileInputStream(configFilenam= e); } catch (FileNotFoundException ex1) { logger.error("Config file '" + configFilename + "' not = found: " + ex1.getMessage(), ex1); throw new RuntimeException(ex1); } } final Properties props =3D new Properties(); try { props.load(configInputStream); } catch (IOException ex) { ex.printStackTrace(); } configurationFactory =3D () -> new PropertyMOInput(props, ag= ent); }
The AgentConfigManager call will be the sam=
e as before except that the moXodusPersistenceProvider
is used=
now:
= MOXodusPersistenceProvider moXodusPersistenceProvider =3D new MOXodusPersi= stenceProvider(moXodusPersistence); // <--- ADD THIS LINE OctetString defaultEngineID =3D new OctetString(MPv3.createLocalEng= ineID()); OctetString engineID =3D moXodusPersistenceProvider.getEngineId(def= aultEngineID); SnmpConfigurator snmpConfigurator =3D new SnmpConfigurator(true); agent =3D new AgentConfigManager( engineID, messageDispatcher, null, moServers, ThreadPool.create("SampleAgent", 3), configurationFactory, moXodusPersistenceProvider, moXodusPersistenceProvider, nul= l, dhKickstartParameters) { // <--- UPDATE THIS LINE @Override protected Session createSnmpSession(MessageDispatcher dispatche= r) { Session session =3D super.createSnmpSession(dispatcher); snmpConfigurator.configure(session, getUsm(), messageDispat= cher, args); return session; } }; agent.addAgentStateListener(this);
The following callback method needs to be a= dded to the main class in order to be able to compile the last code line fr= om the above snippet:
/** * The agent state has changed to the new state as provided. * * @param agentConfigManager * the agent's configuration manager. Use this object to access= all agent resources, if needed to process this * event. * @param newState * the new state of the agent. Although the listener may advanc= e to agent state further, it is not recommended * to do so, because the {@link AgentConfigManager} will do it = anyway. */ @Override public void agentStateChanged(AgentConfigManager agentConfigManager, Ag= entState newState) { switch (newState.getState()) { case AgentState.STATE_INITIALIZED: moXodusPersistence.registerChangeListenersWithServer(server= ); break; case AgentState.STATE_SHUTDOWN: moXodusPersistence.unregisterChangeListenersWithServer(serv= er); break; } }
That's all.