Example #1
0
 protected void addListenAddresses(MessageDispatcher md, List addresses) {
   for (Iterator it = addresses.iterator(); it.hasNext(); ) {
     Address address = GenericAddress.parse((String) it.next());
     TransportMapping tm = TransportMappings.getInstance().createTransportMapping(address);
     if (tm != null) {
       md.addTransportMapping(tm);
     } else {
       logger.warn("No transport mapping available for address '" + address + "'.");
     }
   }
 }
    /** 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();
      }
    }
 public PduHandle sendPdu(
     Address transportAddress,
     int messageProcessingModel,
     int securityModel,
     byte[] securityName,
     int securityLevel,
     PDU pdu,
     boolean expectResponse)
     throws MessageException {
   return dispatcher.sendPdu(
       transportAddress,
       messageProcessingModel,
       securityModel,
       securityName,
       securityLevel,
       pdu,
       expectResponse);
 }
 public int returnResponsePdu(
     int messageProcessingModel,
     int securityModel,
     byte[] securityName,
     int securityLevel,
     PDU pdu,
     int maxSizeResponseScopedPDU,
     StateReference stateReference,
     StatusInformation statusInformation)
     throws MessageException {
   return dispatcher.returnResponsePdu(
       messageProcessingModel,
       securityModel,
       securityName,
       securityLevel,
       pdu,
       maxSizeResponseScopedPDU,
       stateReference,
       statusInformation);
 }
 @Override
 public PduHandle sendPdu(
     TransportMapping transportMapping,
     Address transportAddress,
     int messageProcessingModel,
     int securityModel,
     byte[] securityName,
     int securityLevel,
     PDU pdu,
     boolean expectResponse,
     PduHandleCallback callback)
     throws MessageException {
   return dispatcher.sendPdu(
       transportMapping,
       transportAddress,
       messageProcessingModel,
       securityModel,
       securityName,
       securityLevel,
       pdu,
       expectResponse,
       callback);
 }
 @Override
 public void removeCommandResponder(CommandResponder listener) {
   dispatcher.removeCommandResponder(listener);
 }
 @Override
 public void addCommandResponder(CommandResponder listener) {
   dispatcher.addCommandResponder(listener);
 }
 public Collection getTransportMappings() {
   return dispatcher.getTransportMappings();
 }
 /**
  * @param transport 参数
  * @return 结果
  */
 public TransportMapping removeTransportMapping(TransportMapping transport) {
   return dispatcher.removeTransportMapping(transport);
 }
 /** @param transport 参数 */
 public void addTransportMapping(TransportMapping transport) {
   dispatcher.addTransportMapping(transport);
 }
 /**
  * @param messageProcessingModel 参数
  * @return 结果
  */
 public MessageProcessingModel getMessageProcessingModel(int messageProcessingModel) {
   return dispatcher.getMessageProcessingModel(messageProcessingModel);
 }
 /** @param model 参数 */
 public void removeMessageProcessingModel(MessageProcessingModel model) {
   dispatcher.removeMessageProcessingModel(model);
 }
 /** @param model 参数 */
 public void addMessageProcessingModel(MessageProcessingModel model) {
   dispatcher.addMessageProcessingModel(model);
 }
 public int getNextRequestID() {
   return dispatcher.getNextRequestID();
 }
 @Override
 public TransportMapping getTransport(Address destAddress) {
   return dispatcher.getTransport(destAddress);
 }
 @Override
 public void releaseStateReference(int messageProcessingModel, PduHandle pduHandle) {
   dispatcher.releaseStateReference(messageProcessingModel, pduHandle);
 }