/** * Runs a sample agent with a default configuration defined by <code>SampleAgentConfig.properties * </code>. A sample command line is: * * <pre> * -c SampleAgent.cfg -bc SampleAgent.bc udp:127.0.0.1/4700 tcp:127.0.0.1/4700 * </pre> * * @param args the command line arguments defining at least the listen addresses. The format is * <code>-c[s{=SampleAgent.cfg}] -bc[s{=SampleAgent.bc}] * +ts[s] +cfg[s] #address[s<(udp|tcp):.*[/[0-9]+]?>] ..</code>. For the format description see * {@link ArgumentParser}. */ public static void main(String[] args) { ArgumentParser parser = new ArgumentParser( "-c[s{=SampleAgent.cfg}] -bc[s{=SampleAgent.bc}] " + "+ts[s] +cfg[s]", "#address[s<(udp|tcp):.*[/[0-9]+]?>] .."); Map commandLineParameters = null; try { args = new String[1]; args[0] = "udp:127.0.0.1/4700"; commandLineParameters = parser.parse(args); SampleAgent sampleAgent = new SampleAgent(commandLineParameters); // Add all available security protocols (e.g. // SHA,MD5,DES,AES,3DES,..) SecurityProtocols.getInstance().addDefaultProtocols(); // configure system group: // Set system description: // sampleAgent.agent.getSysDescr().setValue("My system // description".getBytes()); // Set system OID (= OID of the AGENT-CAPABILITIES statement // describing // the implemented MIB objects of this agent: // sampleAgent.agent.getSysOID().setValue("1.3.1.6.1.4.1...."); // Set the system services // sampleAgent.agent.getSysServices().setValue(72); sampleAgent.run(); } catch (ParseException ex) { System.err.println(ex.getMessage()); } }
public SampleAgent(Map args) { configFile = (String) ((List) args.get("c")).get(0); bootCounterFile = new File((String) ((List) args.get("bc")).get(0)); server = new DefaultMOServer(); MOServer[] moServers = new MOServer[] {server}; InputStream configInputStream = SampleAgent.class.getResourceAsStream("SampleAgentConfig.properties"); if (args.containsKey("cfg")) { try { configInputStream = new FileInputStream((String) ArgumentParser.getValue(args, "cfg", 0)); } catch (FileNotFoundException ex1) { ex1.printStackTrace(); } } final Properties props = new Properties(); try { props.load(configInputStream); } catch (IOException ex) { ex.printStackTrace(); } MOInputFactory configurationFactory = new MOInputFactory() { public MOInput createMOInput() { return new PropertyMOInput(props, SampleAgent.this); } }; InputStream tableSizeLimitsInputStream = SampleAgent.class.getResourceAsStream("SampleAgentTableSizeLimits.properties"); if (args.containsKey("ts")) { try { tableSizeLimitsInputStream = new FileInputStream((String) ArgumentParser.getValue(args, "ts", 0)); } catch (FileNotFoundException ex1) { ex1.printStackTrace(); } } tableSizeLimits = new Properties(); try { tableSizeLimits.load(tableSizeLimitsInputStream); } catch (IOException ex) { ex.printStackTrace(); } MessageDispatcher messageDispatcher = new MessageDispatcherImpl(); addListenAddresses(messageDispatcher, (List) args.get("address")); agent = new AgentConfigManager( new OctetString(MPv3.createLocalEngineID()), messageDispatcher, null, moServers, ThreadPool.create("SampleAgent", 3), configurationFactory, new DefaultMOPersistenceProvider(moServers, configFile), new EngineBootsCounterFile(bootCounterFile)); }