FileDocCategorySizeDatePackage
SnmpResponseHandler.javaAPI DocJava SE 5 API4609Fri Aug 26 14:55:06 BST 2005com.sun.jmx.snmp.daemon

SnmpResponseHandler

public class SnmpResponseHandler extends Object
This class is used to handle received inform request responses. This classes parses the SNMP inform response packet to obtain the corresponding inform request.

Fields Summary
SnmpAdaptorServer
adaptor
SnmpQManager
snmpq
String
dbgTag
Constructors Summary
public SnmpResponseHandler(SnmpAdaptorServer adp, SnmpQManager s)


    // CONSTRUCTORS
    //-------------
    
         
        adaptor = adp;
        snmpq = s;
    
Methods Summary
voiddebug(java.lang.String func, java.lang.Throwable exception)

        debug(dbgTag, func, exception);
    
voiddebug(java.lang.String clz, java.lang.String func, java.lang.String info)

        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, info);
    
voiddebug(java.lang.String clz, java.lang.String func, java.lang.Throwable exception)

        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, exception);
    
voiddebug(java.lang.String func, java.lang.String info)

        debug(dbgTag, func, info);
    
booleanisDebugOn()

        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP);
    
booleanisTraceOn()

        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP);
    
public synchronized voidprocessDatagram(java.net.DatagramPacket dgrm)

        
        byte []data = dgrm.getData();
        int datalen = dgrm.getLength();
        
        if (isTraceOn()) {
            trace("processDatagram", "Received from " + dgrm.getAddress().toString() + " Length = " + datalen +
                  "\nDump : \n" + SnmpMessage.dumpHexBuffer(data, 0, datalen));
        }
	
        try {
            SnmpMessage msg = new SnmpMessage();
            msg.decodeMessage(data, datalen);
            msg.address = dgrm.getAddress();
            msg.port = dgrm.getPort();
            
            // Retreive the PDU factory of the SNMP adaptor to decode the received inform response.
            //
            SnmpPduFactory pduFactory = adaptor.getPduFactory();
            if (pduFactory == null) {
                if (isDebugOn()) {
                    debug("processDatagram", "Dropping packet. Unable to find the pdu factory of the SNMP adaptor server");
                }
            }
            else {
                SnmpPduPacket snmpProt = (SnmpPduPacket)pduFactory.decodeSnmpPdu(msg);
                
                if (snmpProt == null) {
                    if (isDebugOn()) {
                        debug("processDatagram", "Dropping packet. Pdu factory returned a null value");
                    }
                }
                else if (snmpProt instanceof SnmpPduRequest) {
                    
                    SnmpPduRequest pduReq = (SnmpPduRequest)snmpProt;
                    SnmpInformRequest req = snmpq.removeRequest(pduReq.requestId) ;
                    if (req != null) {
                        req.invokeOnResponse(pduReq);
                    } else {
                        if (isDebugOn()) {
                            debug("processDatagram", "Dropping packet. Unable to find corresponding for InformRequestId = " + pduReq.requestId);
                        }
                    }
                }
                else {
                    if (isDebugOn()) {
                        debug("processDatagram", "Dropping packet. The packet does not contain an inform response");
                    }
                }
                snmpProt = null ;
            }
        } catch (Exception e) {
            if (isDebugOn()) {
                debug("processDatagram", "Exception while processsing");
                debug("processDatagram", e);
            }
        }    
    
voidtrace(java.lang.String clz, java.lang.String func, java.lang.String info)

        Trace.send(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP, clz, func, info);
    
voidtrace(java.lang.String func, java.lang.String info)

        trace(dbgTag, func, info);