FileDocCategorySizeDatePackage
SnmpMibNode.javaAPI DocJava SE 5 API13524Fri Aug 26 14:55:04 BST 2005com.sun.jmx.snmp.agent

SnmpMibNode

public abstract class SnmpMibNode extends Object implements Serializable
The SnmpMibNode class represents a node in an SNMP MIB.

This class is used internally and by the class generated by mibgen. You should not need to use this class directly.

This API is a Sun Microsystems internal API and is subject to change without notice.

version
4.20 12/19/03
author
Sun Microsystems, Inc

Fields Summary
protected int[]
varList
Contains the list of variable identifiers.
protected static final com.sun.jmx.snmp.SnmpStatusException
noSuchInstanceException
Contains a predefined exception that is often fired when an object is not found in the MIB.
protected static final com.sun.jmx.snmp.SnmpStatusException
noSuchObjectException
protected static final com.sun.jmx.snmp.SnmpStatusException
noSuchNameException
Constructors Summary
Methods Summary
static voidQuickSort(int[] a, int lo0, int hi0)
This is a generic version of C.A.R Hoare's Quick Sort algorithm. This will handle arrays that are already sorted, and arrays with duplicate keys. If you think of a one dimensional array as going from the lowest index on the left to the highest index on the right then the parameters to this function are lowest index or left and highest index or right. The first time you call this function it will be with the parameters 0, a.length - 1.

param
a An integer array.
param
lo0 Left boundary of array partition.
param
hi0 Right boundary of array partition.

        int lo = lo0;
        int hi = hi0;
        int mid;

        if ( hi0 > lo0) {  

            /* Arbitrarily establishing partition element as the midpoint of
             * the array.
             */
            mid = a[ ( lo0 + hi0 ) / 2 ];

            // loop through the array until indices cross
            while( lo <= hi ) {
                /* find the first element that is greater than or equal to
                 * the partition element starting from the left Index.
                 */
                while( ( lo < hi0 )  && ( a[lo] < mid ))
                    ++lo;

                /* find an element that is smaller than or equal to
                 * the partition element starting from the right Index.
                 */
                while( ( hi > lo0 ) && ( a[hi] > mid ))
                    --hi;

                // if the indexes have not crossed, swap
                if( lo <= hi ) {
                    swap(a, lo, hi);
                    ++lo;
                    --hi;
                }
            }

            /* If the right index has not reached the left side of array
             * must now sort the left partition.
             */
            if( lo0 < hi )
                QuickSort( a, lo0, hi );

            /* If the left index has not reached the right side of array
             * must now sort the right partition.
             */
            if( lo < hi0 )
                QuickSort( a, lo, hi0 );

        }  
    
public abstract voidcheck(SnmpMibSubRequest req, int depth)
Generic handling of the check operation.

You can override this method if you need to implement some specific policies for minimizing the accesses made to some remote underlying resources, or if you need to implement some consistency checks between the different values provided in the varbind list.

param
req The sub-request that must be handled by this node.
param
depth The depth reached in the OID tree.
exception
SnmpStatusException An error occurred while accessing the MIB node.

voidfindHandlingNode(com.sun.jmx.snmp.SnmpVarBind varbind, long[] oid, int depth, SnmpRequestTree handlers)
Find the node which handles a varbind, and register it in the SnmpRequestTree. This method is a pure internal method. You should never try to call it directly.

param
varbind The varbind to be handled
param
oid The OID array extracted from the varbind
param
depth The depth reached in the OID at this step of the processing.
param
handlers The Hashtable in which the varbind will be registered with its handling node. This hashtable contains SnmpRequestTree.Handler items.
exception
SnmpStatusException No handling node was found.

	throw noSuchObjectException;
    
long[]findNextHandlingNode(com.sun.jmx.snmp.SnmpVarBind varbind, long[] oid, int pos, int depth, SnmpRequestTree handlers, AcmChecker checker)
Find the node which handles the leaf that immediately follows the given varbind OID, and register the it in the SnmpRequestTree. This method is a pure internal method. You should never try to call it directly.

param
varbind The varbind to be handled
param
oid The OID array extracted from the varbind
param
depth The depth reached in the OID at this step of the processing.
param
handlers The Hashtable in which the varbind will be registered with its handling node. This hashtable contains SnmpRequestTree.Handler items.
return
The SnmpOid of the next leaf.
exception
SnmpStatusException No handling node was found.

	throw noSuchObjectException;
    
public abstract voidget(SnmpMibSubRequest req, int depth)
Generic handling of the get operation.

You can override this method if you need to implement some specific policies for minimizing the accesses made to some remote underlying resources.

param
req The sub-request that must be handled by this node.
param
depth The depth reached in the OID tree.
exception
SnmpStatusException An error occurred while accessing the MIB node.

protected static final intgetNextIdentifier(int[] table, long value)
This will give the first element greater than value in a sorted array. If there is no element of the array greater than value, the method will throw a SnmpStatusException.

param
table A sorted integer array.
param
value The greatest value.
exception
SnmpStatusException If there is no element greater than value.

 
	final int[] a = table;
        final int val= (int) value;

	if (a == null) 
	    throw noSuchObjectException;

        int low= 0;
        int max= a.length;
        int curr= low + (max-low)/2;
        int elmt= 0;
    
        // Basic check
        //
	if (max < 1) 
	    throw noSuchObjectException;

        if (a[max-1] <= val) 
            throw noSuchObjectException;
 
        while (low <= max) {
            elmt= a[curr];     
            if (val == elmt) {
                // We ned to get the next index ...
                //
                curr++;
                return a[curr];
            }
            if (elmt < val) {
                low= curr +1;
            } else {
                max= curr -1;
            }
            curr= low + (max-low)/2;
        }
        return a[curr];
    
public longgetNextVarId(long id, java.lang.Object userData)
Get the next OID arc corresponding to a readable scalar variable, a branch leading to a subgroub, or a table.

param
id Id we start from looking for the next.
param
userData A contextual object containing user-data. This object is allocated through the {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory} for each incoming SNMP request.
return
The next id in this group.
exception
SnmpStatusException If no id is found after the given id.

	return getNextIdentifier(varList,id);
    
public longgetNextVarId(long id, java.lang.Object userData, int pduVersion)
Get the next OID arc corresponding to a readable scalar variable, a branch leading to a subgroub, or a table, possibly skipping over those arcs that must not or cannot be returned. Calls {@link #getNextVarId(long,java.lang.Object)} until {@link #skipVariable(long,java.lang.Object,int)} returns false.

param
id Id we start from looking for the next.
param
userData A contextual object containing user-data. This object is allocated through the {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory} for each incoming SNMP request.
param
pduVersion Protocol version of the original request PDU.
return
The next id in this group which can be returned using the given PDU's protocol version.
exception
SnmpStatusException If no id is found after the given id.

	long varid=id;
	do {
	    varid = getNextVarId(varid,userData);
	} while (skipVariable(varid,userData,pduVersion));

	return varid;
    
public voidgetRootOid(java.util.Vector result)
Computes the root OID of the MIB.

        return;
    
public abstract voidset(SnmpMibSubRequest req, int depth)
Generic handling of the set operation.

You can override this method if you need to implement some specific policies for minimizing the accesses made to some remote underlying resources.

param
req The sub-request that must be handled by this node.
param
depth The depth reached in the OID tree.
exception
SnmpStatusException An error occurred while accessing the MIB node.

protected booleanskipVariable(long id, java.lang.Object userData, int pduVersion)
Hook for subclasses. The default implementation of this method is to always return false. Subclasses should redefine this method so that it returns true when:
  • the variable is a leaf that is not instantiated,
  • or the variable is a leaf whose type cannot be returned by that version of the protocol (e.g. an Counter64 with SNMPv1).

param
id Id we start from looking for the next.
param
userData A contextual object containing user-data. This object is allocated through the {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory} for each incoming SNMP request.
param
pduVersion Protocol version of the original request PDU.
return
true if the variable must be skipped by the get-next algorithm.

	return false;
    
public static voidsort(int[] array)
Sorts the specified integer array.

param
array An integer array.

        QuickSort(array, 0, array.length - 1);
    
private static final voidswap(int[] a, int i, int j)

        int T;
        T = a[i];
        a[i] = a[j];
        a[j] = T;