1 11 12 package com.sun.jmx.snmp.agent; 13 14 15 import java.io.Serializable ; 18 import java.util.Enumeration ; 19 20 import com.sun.jmx.snmp.SnmpStatusException; 23 import com.sun.jmx.snmp.SnmpDefinitions; 24 import javax.management.ObjectName ; 25 import javax.management.MBeanServer ; 26 import com.sun.jmx.snmp.SnmpVarBind; 27 28 import com.sun.jmx.trace.Trace; 31 32 40 41 public class SnmpErrorHandlerAgent extends SnmpMibAgent 42 implements Serializable { 43 44 public SnmpErrorHandlerAgent() {} 45 46 52 53 public void init() throws IllegalAccessException { 54 } 55 56 67 68 public ObjectName preRegister(MBeanServer server, ObjectName name) 69 throws Exception { 70 return name; 71 } 72 73 80 81 public long[] getRootOid() { 82 return null; 83 } 84 85 92 93 public void get(SnmpMibRequest inRequest) throws SnmpStatusException { 94 95 if(isDebugOn()) trace("get","Get in Exception"); 96 97 if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne) 98 throw new SnmpStatusException(SnmpStatusException.noSuchName); 99 100 Enumeration l = inRequest.getElements(); 101 while(l.hasMoreElements()) { 102 SnmpVarBind varbind = (SnmpVarBind) l.nextElement(); 103 varbind.setNoSuchObject(); 104 } 105 } 106 107 119 120 public void check(SnmpMibRequest inRequest) throws SnmpStatusException { 121 122 if(isDebugOn()) trace("check","Check in Exception"); 123 124 throw new SnmpStatusException(SnmpDefinitions.snmpRspNotWritable); 125 } 126 127 134 135 public void set(SnmpMibRequest inRequest) throws SnmpStatusException { 136 137 if(isDebugOn()) trace("set","Set in Exception, CAN't be called"); 138 139 throw new SnmpStatusException(SnmpDefinitions.snmpRspNotWritable); 140 } 141 142 149 150 public void getNext(SnmpMibRequest inRequest) throws SnmpStatusException { 151 152 if(isDebugOn()) trace("getNext","GetNext in Exception"); 153 154 if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne) 155 throw new SnmpStatusException(SnmpStatusException.noSuchName); 156 157 Enumeration l = inRequest.getElements(); 158 while(l.hasMoreElements()) { 159 SnmpVarBind varbind = (SnmpVarBind) l.nextElement(); 160 varbind.setEndOfMibView(); 161 } 162 } 163 164 171 172 public void getBulk(SnmpMibRequest inRequest, int nonRepeat, int maxRepeat) 173 throws SnmpStatusException { 174 175 if(isDebugOn()) trace("getBulk","GetBulk in Exception"); 176 177 if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne) 178 throw new SnmpStatusException(SnmpDefinitions.snmpRspGenErr, 0); 179 180 Enumeration l = inRequest.getElements(); 181 while(l.hasMoreElements()) { 182 SnmpVarBind varbind = (SnmpVarBind) l.nextElement(); 183 varbind.setEndOfMibView(); 184 } 185 } 186 187 private boolean isDebugOn() { 188 return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP); 189 } 190 191 private void debug(String clz, String func, String info) { 192 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP, clz, func, info); 193 } 194 195 private void trace(String func, String info) { 196 debug(dbgTag, func, info); 197 } 198 199 private String dbgTag = "SnmpErrorHandlerAgent"; 200 } 201 202 203 | Popular Tags |