1 11 12 13 package com.sun.jmx.snmp.agent; 14 15 16 17 import java.io.Serializable ; 20 import java.util.Vector ; 21 import java.util.Hashtable ; 22 import java.util.Enumeration ; 23 24 import com.sun.jmx.snmp.SnmpOid; 27 import com.sun.jmx.snmp.SnmpValue; 28 import com.sun.jmx.snmp.SnmpVarBind; 29 import com.sun.jmx.snmp.SnmpDefinitions; 30 import com.sun.jmx.snmp.SnmpStatusException; 31 32 44 45 public abstract class SnmpMibNode implements Serializable { 46 47 51 65 public long getNextVarId(long id, Object userData) 66 throws SnmpStatusException { 67 return getNextIdentifier(varList,id); 68 } 69 70 90 public long getNextVarId(long id, Object userData, int pduVersion) 91 throws SnmpStatusException { 92 long varid=id; 93 do { 94 varid = getNextVarId(varid,userData); 95 } while (skipVariable(varid,userData,pduVersion)); 96 97 return varid; 98 } 99 100 120 protected boolean skipVariable(long id, Object userData, int pduVersion) { 121 return false; 122 } 123 124 142 void findHandlingNode(SnmpVarBind varbind, 143 long[] oid, int depth, 144 SnmpRequestTree handlers) 145 throws SnmpStatusException { 146 throw noSuchObjectException; 147 } 148 149 170 long[] findNextHandlingNode(SnmpVarBind varbind, 171 long[] oid, int pos, int depth, 172 SnmpRequestTree handlers, AcmChecker checker) 173 throws SnmpStatusException { 174 throw noSuchObjectException; 175 } 176 177 192 public abstract void get(SnmpMibSubRequest req, int depth) 193 throws SnmpStatusException; 194 195 209 public abstract void set(SnmpMibSubRequest req, int depth) 210 throws SnmpStatusException; 211 212 227 public abstract void check(SnmpMibSubRequest req, int depth) 228 throws SnmpStatusException; 229 230 235 static public void sort(int array[]) { 236 QuickSort(array, 0, array.length - 1); 237 } 238 239 242 public void getRootOid(Vector result) { 243 return; 244 } 245 246 250 265 static void QuickSort(int a[], int lo0, int hi0) { 266 int lo = lo0; 267 int hi = hi0; 268 int mid; 269 270 if ( hi0 > lo0) { 271 272 275 mid = a[ ( lo0 + hi0 ) / 2 ]; 276 277 while( lo <= hi ) { 279 282 while( ( lo < hi0 ) && ( a[lo] < mid )) 283 ++lo; 284 285 288 while( ( hi > lo0 ) && ( a[hi] > mid )) 289 --hi; 290 291 if( lo <= hi ) { 293 swap(a, lo, hi); 294 ++lo; 295 --hi; 296 } 297 } 298 299 302 if( lo0 < hi ) 303 QuickSort( a, lo0, hi ); 304 305 308 if( lo < hi0 ) 309 QuickSort( a, lo, hi0 ); 310 311 } 312 } 313 314 318 331 final static protected int getNextIdentifier(int table[], long value) 332 throws SnmpStatusException { 333 334 final int[] a = table; 335 final int val= (int) value; 336 337 if (a == null) 338 throw noSuchObjectException; 339 340 int low= 0; 341 int max= a.length; 342 int curr= low + (max-low)/2; 343 int elmt= 0; 344 345 if (max < 1) 348 throw noSuchObjectException; 349 350 if (a[max-1] <= val) 351 throw noSuchObjectException; 352 353 while (low <= max) { 354 elmt= a[curr]; 355 if (val == elmt) { 356 curr++; 359 return a[curr]; 360 } 361 if (elmt < val) { 362 low= curr +1; 363 } else { 364 max= curr -1; 365 } 366 curr= low + (max-low)/2; 367 } 368 return a[curr]; 369 } 370 371 372 376 final static private void swap(int a[], int i, int j) { 377 int T; 378 T = a[i]; 379 a[i] = a[j]; 380 a[j] = T; 381 } 382 383 387 390 protected int[] varList; 391 392 396 static final protected SnmpStatusException noSuchInstanceException = 397 new SnmpStatusException(SnmpStatusException.noSuchInstance); 398 static final protected SnmpStatusException noSuchObjectException = 399 new SnmpStatusException(SnmpStatusException.noSuchObject); 400 static final protected SnmpStatusException noSuchNameException = 401 new SnmpStatusException(SnmpDefinitions.snmpRspNoSuchName); 402 } 403 | Popular Tags |