org.snmp4j.Snmp.getMessageDispatcher()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(240)

本文整理了Java中org.snmp4j.Snmp.getMessageDispatcher()方法的一些代码示例,展示了Snmp.getMessageDispatcher()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Snmp.getMessageDispatcher()方法的具体详情如下:
包路径:org.snmp4j.Snmp
类名称:Snmp
方法名:getMessageDispatcher

Snmp.getMessageDispatcher介绍

[英]Returns the message dispatcher associated with this SNMP session.
[中]返回与此SNMP会话关联的消息调度程序。

代码示例

代码示例来源:origin: stackoverflow.com

Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
USM usm = new USM(SecurityProtocols.getInstance(),
          localEngineID,
          engineBootCount);
usm.addUser(securityName, new UsmUser(securityName,
        authProtocol,
        authPassphrase,
        privProtocol,
        privPassphrase));
MessageProcessingModel oldModel = snmp.getMessageDispatcher().getMessageProcessingModel(MessageProcessingModel.MPv3);
if (oldModel != null) {    
  snmp.getMessageDispatcher().removeMessageProcessingModel(oldModel);
}
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3(usm));

代码示例来源:origin: org.snmp4j/snmp4j

public void configure(Snmp snmp, Map<String, List<Object>> settings) {
  configure(snmp, snmp.getUSM(), snmp.getMessageDispatcher(), settings);
}

代码示例来源:origin: org.opennms.lib.snmp/org.opennms.lib.snmp.snmp4j

public void sendTest(String agentAddress, int port, String community, PDU pdu) {
  for (RegistrationInfo info : s_registrations.values()) {
    if (port == info.getPort()) {
      Snmp snmp = info.getSession();
      MessageDispatcher dispatcher = snmp.getMessageDispatcher();
      TransportMapping transport = info.getTransportMapping();
      
      int securityModel = (pdu instanceof PDUv1 ? SecurityModel.SECURITY_MODEL_SNMPv1 :SecurityModel.SECURITY_MODEL_SNMPv2c);
      int messageModel = (pdu instanceof PDUv1 ? MessageProcessingModel.MPv1 : MessageProcessingModel.MPv2c);
      CommandResponderEvent e = new CommandResponderEvent(dispatcher, transport, new IpAddress(agentAddress), messageModel, 
                                securityModel, community.getBytes(), 
                                SecurityLevel.NOAUTH_NOPRIV, new PduHandle(), pdu, 1000, null);
      info.getHandler().processPdu(e);
    }
  }
}

代码示例来源:origin: OpenNMS/opennms

public void sendTest(String agentAddress, int port, String community, PDU pdu) {
  for (RegistrationInfo info : s_registrations.values()) {
    if (port == info.getPort()) {
      final Snmp snmp = info.getSession();
      Snmp4JStrategy.trackSession(snmp);
      MessageDispatcher dispatcher = snmp.getMessageDispatcher();
      TransportMapping<UdpAddress> transport = info.getTransportMapping();
      
      int securityModel = (pdu instanceof PDUv1 ? SecurityModel.SECURITY_MODEL_SNMPv1 :SecurityModel.SECURITY_MODEL_SNMPv2c);
      int messageModel = (pdu instanceof PDUv1 ? MessageProcessingModel.MPv1 : MessageProcessingModel.MPv2c);
      CommandResponderEvent e = new CommandResponderEvent(dispatcher, transport, new IpAddress(agentAddress), messageModel, 
                                securityModel, community.getBytes(), 
                                SecurityLevel.NOAUTH_NOPRIV, new PduHandle(), pdu, 1000, null);
      info.getHandler().processPdu(e);
    }
  }
}

代码示例来源:origin: org.opennms.core.snmp/org.opennms.core.snmp.implementations.snmp4j

public void sendTest(String agentAddress, int port, String community, PDU pdu) {
  for (RegistrationInfo info : s_registrations.values()) {
    if (port == info.getPort()) {
      final Snmp snmp = info.getSession();
      Snmp4JStrategy.trackSession(snmp);
      MessageDispatcher dispatcher = snmp.getMessageDispatcher();
      TransportMapping<UdpAddress> transport = info.getTransportMapping();
      
      int securityModel = (pdu instanceof PDUv1 ? SecurityModel.SECURITY_MODEL_SNMPv1 :SecurityModel.SECURITY_MODEL_SNMPv2c);
      int messageModel = (pdu instanceof PDUv1 ? MessageProcessingModel.MPv1 : MessageProcessingModel.MPv2c);
      CommandResponderEvent e = new CommandResponderEvent(dispatcher, transport, new IpAddress(agentAddress), messageModel, 
                                securityModel, community.getBytes(), 
                                SecurityLevel.NOAUTH_NOPRIV, new PduHandle(), pdu, 1000, null);
      info.getHandler().processPdu(e);
    }
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j

private void init() throws IOException {
 threadPool = ThreadPool.create("Trap", 2);
 dispatcher =
   new MultiThreadedMessageDispatcher(threadPool,
                     new MessageDispatcherImpl());
 listenAddress =
   GenericAddress.parse(System.getProperty("snmp4j.listenAddress",
                       "udp:0.0.0.0/162"));
 TransportMapping<? extends Address> transport;
 if (listenAddress instanceof UdpAddress) {
  transport = new DefaultUdpTransportMapping((UdpAddress)listenAddress);
 }
 else {
  transport = new DefaultTcpTransportMapping((TcpAddress)listenAddress);
 }
 snmp = new Snmp(dispatcher, transport);
 snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());
 snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
 snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());
 USM usm = new USM(SecurityProtocols.getInstance(),
          new OctetString(MPv3.createLocalEngineID()), 0);
 SecurityModels.getInstance().addSecurityModel(usm);
 snmp.listen();
}

代码示例来源:origin: org.kaazing/snmp4j

private void init() throws UnknownHostException, IOException {
 threadPool = ThreadPool.create("Trap", 2);
 dispatcher =
   new MultiThreadedMessageDispatcher(threadPool,
                     new MessageDispatcherImpl());
 listenAddress =
   GenericAddress.parse(System.getProperty("snmp4j.listenAddress",
                       "udp:0.0.0.0/162"));
 TransportMapping transport;
 if (listenAddress instanceof UdpAddress) {
  transport = new DefaultUdpTransportMapping((UdpAddress)listenAddress);
 }
 else {
  transport = new DefaultTcpTransportMapping((TcpAddress)listenAddress);
 }
 snmp = new Snmp(dispatcher, transport);
 snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());
 snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
 snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());
 USM usm = new USM(SecurityProtocols.getInstance(),
          new OctetString(MPv3.createLocalEngineID()), 0);
 SecurityModels.getInstance().addSecurityModel(usm);
 snmp.listen();
}

代码示例来源:origin: org.opennms.lib.snmp/org.opennms.lib.snmp.snmp4j

public Snmp createSnmpSession() throws IOException {
  TransportMapping transport = new DefaultUdpTransportMapping();
  Snmp session = new Snmp(transport);
  
  if (isSnmpV3()) {
    // Make a new USM
    USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    // Add the specified user to the USM
    usm.addUser(
      getSecurityName(),
      new UsmUser(
        getSecurityName(),
        getAuthProtocol(),
        getAuthPassPhrase(),
        getPrivProtocol(),
        getPrivPassPhrase()
      )
    );
    // Remove the old SNMPv3 MessageProcessingModel. If you don't do this, you'll end up with
    // two SNMPv3 MessageProcessingModel instances in the dispatcher and connections will fail.
    MessageProcessingModel oldModel = session.getMessageDispatcher().getMessageProcessingModel(MessageProcessingModel.MPv3);
    if (oldModel != null) {
      session.getMessageDispatcher().removeMessageProcessingModel(oldModel);
    }
    // Add a new SNMPv3 MessageProcessingModel with the newly-created USM
    session.getMessageDispatcher().addMessageProcessingModel(new MPv3(usm));
  }
  
  return session;
}

代码示例来源:origin: com.rogueai/snmp2bean

private void init() throws UnknownHostException, IOException {
  //create thread pool
  threadPool = ThreadPool.create("Trap Receiver ThreadPool", poolSize);
  //create dispatcher
  dispatcher = new MultiThreadedMessageDispatcher(threadPool,
      new MessageDispatcherImpl());
  //create transport
  Address address = GenericAddress.parse(this.listenAddress);
  TransportMapping transport = null;
  if (address instanceof UdpAddress) {
    transport = new DefaultUdpTransportMapping((UdpAddress) address);
  } else {
    transport = new DefaultTcpTransportMapping((TcpAddress) address);
  }
  //create snmp
  snmp = new Snmp(dispatcher, transport);
  snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());
  snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
  snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());
  USM usm = new USM(
      SecurityProtocols.getInstance(),
      new OctetString(MPv3.createLocalEngineID()), 0);
  SecurityModels.getInstance().addSecurityModel(usm);
  snmp.listen();
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j

for (TransportMapping tm : snmp.getMessageDispatcher().getTransportMappings()) {
 if (tm instanceof TLSTM) {
  TLSTM tlsTM = (TLSTM) tm;

代码示例来源:origin: org.snmp4j/snmp4j-agent

((Snmp)session).getMessageDispatcher().getTransport(address);
if ((tm != null) && (tm.getListenAddress() instanceof IpAddress)) {
 InetAddress localAddress =

代码示例来源:origin: org.kaazing/snmp4j-agent

((Snmp)session).getMessageDispatcher().getTransport(address);
if ((tm != null) && (tm.getListenAddress() instanceof IpAddress)) {
 InetAddress localAddress =

相关文章