/** * For SNMP Runtime internal use only. Constructor for creating new inform request. This object * can be created only by an SNMP adaptor object. * * @param session <CODE>SnmpSession</CODE> object for this inform request. * @param adp <CODE>SnmpAdaptorServer</CODE> object for this inform request. * @param addr The <CODE>InetAddress</CODE> destination for this inform request. * @param cs The community string to be used for the inform request. * @param requestCB Callback interface for the inform request. * @exception SnmpStatusException SNMP adaptor is not ONLINE or session is dead. */ SnmpInformRequest( SnmpSession session, SnmpAdaptorServer adp, InetAddress addr, String cs, int p, SnmpInformHandler requestCB) throws SnmpStatusException { informSession = session; adaptor = adp; address = addr; communityString = cs; port = p; callback = requestCB; informSession.addInformRequest(this); // add to adaptor queue. setTimeout(adaptor.getTimeout()); }
boolean sendPdu() { try { responsePdu = null; SnmpPduFactory pduFactory = adaptor.getPduFactory(); SnmpMessage msg = (SnmpMessage) pduFactory.encodeSnmpPdu( (SnmpPduPacket) requestPdu, adaptor.getBufferSize().intValue()); if (msg == null) { if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { SNMP_ADAPTOR_LOGGER.logp( Level.FINEST, SnmpInformRequest.class.getName(), "sendPdu", "pdu factory returned a null value"); } throw new SnmpStatusException(snmpReqUnknownError); // This exception will caught hereafter and reported as an snmpReqUnknownError // FIXME: may be it's not the best behaviour ? } int maxPktSize = adaptor.getBufferSize().intValue(); byte[] encoding = new byte[maxPktSize]; int encodingLength = msg.encodeMessage(encoding); if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) { SNMP_ADAPTOR_LOGGER.logp( Level.FINER, SnmpInformRequest.class.getName(), "sendPdu", "Dump : \n" + msg.printMessage()); } sendPduPacket(encoding, encodingLength); return true; } catch (SnmpTooBigException ar) { if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { SNMP_ADAPTOR_LOGGER.logp( Level.FINEST, SnmpInformRequest.class.getName(), "sendPdu", "Got unexpected exception", ar); } setErrorStatusAndIndex(snmpReqPacketOverflow, ar.getVarBindCount()); requestPdu = null; reason = ar.getMessage(); if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { SNMP_ADAPTOR_LOGGER.logp( Level.FINEST, SnmpInformRequest.class.getName(), "sendPdu", "Packet Overflow while building inform request"); } } catch (java.io.IOException ioe) { setErrorStatusAndIndex(snmpReqSocketIOError, 0); reason = ioe.getMessage(); } catch (Exception e) { if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { SNMP_ADAPTOR_LOGGER.logp( Level.FINEST, SnmpInformRequest.class.getName(), "sendPdu", "Got unexpected exception", e); } setErrorStatusAndIndex(snmpReqUnknownError, 0); reason = e.getMessage(); } return false; }
/** * Gets the maximum number of tries before declaring that the manager is not responding. * * @return The maximum number of times an inform request should be tried. */ public final int getMaxTries() { return adaptor.getMaxTries(); }