1 11 12 package com.sun.jmx.snmp.daemon; 13 14 import java.util.Vector ; 17 18 import com.sun.jmx.snmp.SnmpEngine; 21 import com.sun.jmx.snmp.SnmpPdu; 22 import com.sun.jmx.snmp.SnmpValue; 23 import com.sun.jmx.snmp.SnmpVarBind; 24 import com.sun.jmx.snmp.SnmpVarBindList; 25 import com.sun.jmx.snmp.SnmpOid; 26 import com.sun.jmx.snmp.SnmpDefinitions; 27 import com.sun.jmx.snmp.SnmpStatusException; 28 import com.sun.jmx.snmp.agent.SnmpMibAgent; 31 import com.sun.jmx.snmp.agent.SnmpMibRequest; 32 import com.sun.jmx.snmp.daemon.SnmpAdaptorServer; 33 import com.sun.jmx.snmp.internal.SnmpIncomingRequest; 34 35 36 import com.sun.jmx.snmp.ThreadContext; 37 38 39 class SnmpSubNextRequestHandler extends SnmpSubRequestHandler { 40 private SnmpAdaptorServer server = null; 41 45 protected SnmpSubNextRequestHandler(SnmpAdaptorServer server, 46 SnmpMibAgent agent, 47 SnmpPdu req) { 48 super(agent,req); 49 init(req, server); 50 } 51 52 protected SnmpSubNextRequestHandler(SnmpEngine engine, 53 SnmpAdaptorServer server, 54 SnmpIncomingRequest incRequest, 55 SnmpMibAgent agent, 56 SnmpPdu req) { 57 super(engine, incRequest, agent, req); 58 init(req, server); 59 if(isDebugOn()) 60 debug("SnmpSubNextRequestHandler", "Constructor :" + this); 61 } 62 63 private void init(SnmpPdu req, SnmpAdaptorServer server) { 64 this.server = server; 65 66 final int max= translation.length; 69 final SnmpVarBind[] list= req.varBindList; 70 final NonSyncVector nonSyncVarBind = ((NonSyncVector)varBind); 71 for(int i=0; i < max; i++) { 72 translation[i]= i; 73 final SnmpVarBind newVarBind = 77 new SnmpVarBind(list[i].oid, list[i].value); 78 nonSyncVarBind.addNonSyncElement(newVarBind); 79 } 80 } 81 82 public void run() { 83 84 try { 85 86 final ThreadContext oldContext = 87 ThreadContext.push("SnmpUserData",data); 88 try { 89 if (isTraceOn()) { 90 trace("run", "[" + Thread.currentThread() + 91 "]:getNext operation on " + agent.getMibName()); 92 } 93 94 agent.getNext(createMibRequest(varBind, snmpVersionTwo, data)); 98 } finally { 99 ThreadContext.restore(oldContext); 100 } 101 102 103 104 } catch(SnmpStatusException x) { 105 errorStatus = x.getStatus() ; 106 errorIndex= x.getErrorIndex(); 107 if (isDebugOn()) { 108 debug("run", "[" + Thread.currentThread() + 109 "]:an Snmp error occured during the operation"); 110 debug("run",x); 111 } 112 } 113 catch(Exception x) { 114 errorStatus = SnmpDefinitions.snmpRspGenErr ; 115 if (isTraceOn()) { 116 trace("run", "[" + Thread.currentThread() + 117 "]:a generic error occured during the operation"); 118 } 119 if (isDebugOn()) { 120 debug("run","Error is: " + x); 121 debug("run",x); 122 } 123 } 124 if (isTraceOn()) { 125 trace("run", "[" + Thread.currentThread() + 126 "]:operation completed"); 127 } 128 } 129 130 133 protected void updateRequest(SnmpVarBind var, int pos) { 134 if(isDebugOn()) 135 debug("updateRequest", "Copy :" + var); 136 int size= varBind.size(); 137 translation[size]= pos; 138 final SnmpVarBind newVarBind = 139 new SnmpVarBind(var.oid, var.value); 140 if(isDebugOn()) 141 debug("updateRequest", "Copied :" + newVarBind); 142 143 varBind.addElement(newVarBind); 144 } 145 152 protected void updateResult(SnmpVarBind[] result) { 153 154 final int max=varBind.size(); 155 for(int i= 0; i< max ; i++) { 156 final int index= translation[i]; 159 final SnmpVarBind elmt= 160 (SnmpVarBind)((NonSyncVector)varBind).elementAtNonSync(i); 161 162 final SnmpVarBind vb= result[index]; 163 if (vb == null) { 164 result[index]= elmt; 165 166 170 continue; 171 } 172 173 final SnmpValue val= vb.value; 174 if ((val == null)|| (val == SnmpVarBind.endOfMibView)){ 175 176 if ((elmt != null) && 177 (elmt.value != SnmpVarBind.endOfMibView)) 178 result[index]= elmt; 179 continue; 182 183 } 184 185 186 if (elmt == null) continue; 187 188 189 if (elmt.value == SnmpVarBind.endOfMibView) continue; 190 191 192 int comp = elmt.oid.compareTo(vb.oid); 195 if (comp < 0) { 196 result[index]= elmt; 199 } 200 else { 201 if(comp == 0) { 202 if(isDebugOn()) { 205 trace("updateResult"," oid overlapping. Oid : " + 206 elmt.oid + "value :" + elmt.value); 207 trace("updateResult","Already present varBind : " + 208 vb); 209 } 210 211 SnmpOid oid = vb.oid; 212 SnmpMibAgent deeperAgent = server.getAgentMib(oid); 213 214 if(isDebugOn()) 215 trace("updateResult","Deeper agent : " + deeperAgent); 216 if(deeperAgent == agent) { 217 if(isDebugOn()) 218 trace("updateResult","The current agent is the deeper one. Update the value with the current one"); 219 result[index].value = elmt.value; 220 } 221 222 241 } 242 } 243 } 244 } 245 246 protected String makeDebugTag() { 247 return "SnmpSubNextRequestHandler"; 248 } 249 } 250 | Popular Tags |