1 11 12 package com.sun.jmx.snmp.daemon; 13 14 import java.net.DatagramPacket ; 17 18 import com.sun.jmx.snmp.SnmpMessage; 21 import com.sun.jmx.snmp.SnmpPduFactory; 22 import com.sun.jmx.snmp.SnmpPduPacket; 23 import com.sun.jmx.snmp.SnmpPduRequest; 24 25 import com.sun.jmx.trace.Trace; 28 29 33 34 class SnmpResponseHandler { 35 36 39 SnmpAdaptorServer adaptor = null; 40 SnmpQManager snmpq = null; 41 42 45 public SnmpResponseHandler(SnmpAdaptorServer adp, SnmpQManager s) { 46 adaptor = adp; 47 snmpq = s; 48 } 49 50 53 public synchronized void processDatagram(DatagramPacket dgrm) { 54 55 byte []data = dgrm.getData(); 56 int datalen = dgrm.getLength(); 57 58 if (isTraceOn()) { 59 trace("processDatagram", "Received from " + dgrm.getAddress().toString() + " Length = " + datalen + 60 "\nDump : \n" + SnmpMessage.dumpHexBuffer(data, 0, datalen)); 61 } 62 63 try { 64 SnmpMessage msg = new SnmpMessage(); 65 msg.decodeMessage(data, datalen); 66 msg.address = dgrm.getAddress(); 67 msg.port = dgrm.getPort(); 68 69 SnmpPduFactory pduFactory = adaptor.getPduFactory(); 72 if (pduFactory == null) { 73 if (isDebugOn()) { 74 debug("processDatagram", "Dropping packet. Unable to find the pdu factory of the SNMP adaptor server"); 75 } 76 } 77 else { 78 SnmpPduPacket snmpProt = (SnmpPduPacket)pduFactory.decodeSnmpPdu(msg); 79 80 if (snmpProt == null) { 81 if (isDebugOn()) { 82 debug("processDatagram", "Dropping packet. Pdu factory returned a null value"); 83 } 84 } 85 else if (snmpProt instanceof SnmpPduRequest) { 86 87 SnmpPduRequest pduReq = (SnmpPduRequest)snmpProt; 88 SnmpInformRequest req = snmpq.removeRequest(pduReq.requestId) ; 89 if (req != null) { 90 req.invokeOnResponse(pduReq); 91 } else { 92 if (isDebugOn()) { 93 debug("processDatagram", "Dropping packet. Unable to find corresponding for InformRequestId = " + pduReq.requestId); 94 } 95 } 96 } 97 else { 98 if (isDebugOn()) { 99 debug("processDatagram", "Dropping packet. The packet does not contain an inform response"); 100 } 101 } 102 snmpProt = null ; 103 } 104 } catch (Exception e) { 105 if (isDebugOn()) { 106 debug("processDatagram", "Exception while processsing"); 107 debug("processDatagram", e); 108 } 109 } 110 } 111 112 115 boolean isTraceOn() { 116 return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP); 117 } 118 119 void trace(String clz, String func, String info) { 120 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP, clz, func, info); 121 } 122 123 void trace(String func, String info) { 124 trace(dbgTag, func, info); 125 } 126 127 boolean isDebugOn() { 128 return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP); 129 } 130 131 void debug(String clz, String func, String info) { 132 Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, info); 133 } 134 135 void debug(String clz, String func, Throwable exception) { 136 Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, exception); 137 } 138 139 void debug(String func, String info) { 140 debug(dbgTag, func, info); 141 } 142 143 void debug(String func, Throwable exception) { 144 debug(dbgTag, func, exception); 145 } 146 147 String dbgTag = "SnmpResponseHandler"; 148 } 149 | Popular Tags |