Hi,

What version of SNMP4J are you using?
Why are you creating a Snmp instance and Transport for each
method call? (Opening a socket is slow and closing it might not
work instantly on all systems, thus this approach is not recommended)

Best regards,
Frank

Am 06.09.2012 13:45, schrieb MILLIGAN, Kristoffer:
> Hello list,
>
> snmp4j is for the most part working as expected .. I am however having a 
> problem with a method of mine.
>
> The method will leave a DefaultUdpTransportMapping listerner running, and it 
> will leave a Timer running. These never seem to die. What am I doing wrong, 
> and how can I kill of these listeners?
>
> public ArrayList<String> getValues(String oid) throws IOException {
>          
>          ArrayList<String> result = new ArrayList<String>();
>          
>          TransportMapping transport = new DefaultUdpTransportMapping();
>          //transport.listen();
>
>          // Create Target Address object
>          CommunityTarget comtarget = new CommunityTarget();
>          comtarget.setCommunity(new 
> OctetString(Setting.getInstance().getValue("settings", "community")));
>          comtarget.setVersion(SnmpConstants.version2c);
>          comtarget.setAddress(new 
> UdpAddress(Setting.getInstance().getValue("settings", "ip") + "/" + 
> Setting.getInstance().getValue("settings", "port")));
>          comtarget.setRetries(2);
>          comtarget.setTimeout(5000);
>
>          // Create the PDU object
>          PDU pdu = new PDU();
>          pdu.add(new VariableBinding(new OID(oid)));
>          pdu.setType(PDU.GET);
>          //pdu.setRequestID(new Integer32(1));
>
>          // Create Snmp object for sending data to Agent
>          Snmp snmp = new Snmp(transport);
>          snmp.listen();
>          ResponseEvent response;
>          while(true) {
>              response = snmp.getNext(pdu, comtarget);
>              if (response != null) {
>                  PDU responsePDU = response.getResponse();
>                  if(!response.getResponse().get(0).getOid().startsWith(new 
> OID(oid))) {
>                      //System.out.println("Starting with the same OID - 
> breaking!");
>                      break;
>                  }
>                  if (responsePDU != null) {
>                      int errorStatus = responsePDU.getErrorStatus();
>                      if (errorStatus == PDU.noError){
>                          result.add(responsePDU.get(0).toValueString());
>                          pdu = response.getResponse();
>                          System.out.println("Adding " + 
> responsePDU.get(0).toValueString());
>                      }
>                      else {
>                          System.out.println("Response was error: " + 
> pdu.getErrorStatusText());
>                          break;
>                      }
>                  } else {
>                      System.out.println("PDU received was null");
>                      break;
>                  }
>              } else {
>                  System.out.println("Response received was null");
>                  break;
>              }
>          }
>          snmp.close();
>
>          return result;
>      }
>
>
> This message and any attachments are confidential to Vizada and intended 
> solely for
> the individual(s) or entity to which it is addressed. If you are not the 
> intended recipient,
> do not read, copy or distribute the email or any attachments. Please notify 
> the sender
> immediately by return e-mail.
> _______________________________________________
> SNMP4J mailing list
> [email protected]
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
---
AGENT++
Maximilian-Kolbe-Str. 10
73257 Koengen, Germany
https://agentpp.com
Phone: +49 7024 8688230
Fax:   +49 7024 8688231

_______________________________________________
SNMP4J mailing list
[email protected]
http://lists.agentpp.org/mailman/listinfo/snmp4j

Reply via email to