/** This method will listen for traps and response pdu's from SNMP agent. */ public synchronized void listen(TransportIpAddress address) throws IOException { AbstractTransportMapping transport; if (address instanceof TcpAddress) { transport = new DefaultTcpTransportMapping((TcpAddress) address); } else { transport = new DefaultUdpTransportMapping((UdpAddress) address); } ThreadPool threadPool = ThreadPool.create("DispatcherPool", 10); MessageDispatcher mtDispatcher = new MultiThreadedMessageDispatcher(threadPool, new MessageDispatcherImpl()); // add message processing models mtDispatcher.addMessageProcessingModel(new MPv1()); mtDispatcher.addMessageProcessingModel(new MPv2c()); // add all security protocols SecurityProtocols.getInstance().addDefaultProtocols(); SecurityProtocols.getInstance().addPrivacyProtocol(new Priv3DES()); // Create Target CommunityTarget target = new CommunityTarget(); target.setCommunity(new OctetString("public")); Snmp snmp = new Snmp(mtDispatcher, transport); snmp.addCommandResponder(this); transport.listen(); logger.info("Listening on " + address); try { this.wait(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } }
/** @param model 参数 */ public void addMessageProcessingModel(MessageProcessingModel model) { dispatcher.addMessageProcessingModel(model); }