Search in sources :

Example 16 with SnmpOid

use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.

the class SnmpMibTable method getNextOid.

/**
     * Get the <CODE>SnmpOid</CODE> index of the row that follows
     * the given <CODE>oid</CODE> in the table. The given <CODE>
     * oid</CODE> does not need to be a valid row OID index.
     *
     * <p>
     * @param oid The OID from which the search will begin.
     *
     * @param userData A contextual object containing user-data.
     *        This object is allocated through the <code>
     *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}</code>
     *        for each incoming SNMP request.
     *
     * @return The next <CODE>SnmpOid</CODE> index.
     *
     * @exception SnmpStatusException There is no index following the
     *     specified <CODE>oid</CODE> in the table.
     */
protected SnmpOid getNextOid(SnmpOid oid, Object userData) throws SnmpStatusException {
    if (size == 0) {
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    }
    final SnmpOid resOid = oid;
    // Just a simple check to speed up retrieval of last element ...
    //
    // XX SnmpOid last= (SnmpOid) oids.lastElement();
    SnmpOid last = tableoids[tablecount - 1];
    if (last.equals(resOid)) {
        //
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    }
    // First find the oid. This will allow to speed up retrieval process
    // during smart discovery of table (using the getNext) as the
    // management station will use the valid index returned during a
    // previous getNext ...
    //
    // Returns the position following the position at which resOid
    // is found, or the position at which resOid should be inserted.
    //
    final int newPos = getInsertionPoint(resOid, false);
    //
    if (newPos > -1 && newPos < size) {
        try {
            // XX last = (SnmpOid) oids.elementAt(newPos);
            last = tableoids[newPos];
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
        }
    } else {
        //
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    }
    return last;
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpOid(com.sun.jmx.snmp.SnmpOid)

Example 17 with SnmpOid

use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.

the class SnmpMibOid method registerNode.

/**
     * Registers a specific node in the tree.
     */
public void registerNode(String oidString, SnmpMibNode node) throws IllegalAccessException {
    SnmpOid oid = new SnmpOid(oidString);
    registerNode(oid.longValue(), 0, node);
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid)

Example 18 with SnmpOid

use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.

the class SnmpMibTable method findHandlingNode.

// ---------------------------------------------------------------------
//
// Implements the method defined in SnmpMibNode.
//
// ---------------------------------------------------------------------
@Override
final synchronized void findHandlingNode(SnmpVarBind varbind, long[] oid, int depth, SnmpRequestTree handlers) throws SnmpStatusException {
    final int length = oid.length;
    if (handlers == null)
        throw new SnmpStatusException(SnmpStatusException.snmpRspGenErr);
    if (depth >= length)
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    if (oid[depth] != nodeId)
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    if (depth + 2 >= length)
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    // Checks that the oid is valid
    // validateOid(oid,depth);
    // Gets the part of the OID that identifies the entry
    final SnmpOid entryoid = new SnmpEntryOid(oid, depth + 2);
    // Finds the entry: false means that the entry does not exists
    final Object data = handlers.getUserData();
    final boolean hasEntry = contains(entryoid, data);
    // We know that the entry does not exists if (isentry == false).
    if (!hasEntry) {
        if (!handlers.isCreationAllowed()) {
            // we're not doing a set
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
        } else if (!isCreationEnabled())
            // we're doing a set but creation is disabled.
            throw new SnmpStatusException(SnmpStatusException.snmpRspNoAccess);
    }
    final long var = oid[depth + 1];
    // Validate the entry id
    if (hasEntry) {
        // The entry already exists - validate the id
        validateVarEntryId(entryoid, var, data);
    }
    //
    if (handlers.isSetRequest() && isRowStatus(entryoid, var, data))
        // We only try to identify the RowStatus for SET operations
        //
        handlers.add(this, depth, entryoid, varbind, (!hasEntry), varbind);
    else
        handlers.add(this, depth, entryoid, varbind, (!hasEntry));
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpOid(com.sun.jmx.snmp.SnmpOid)

Example 19 with SnmpOid

use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.

the class SnmpRequestTree method getInsertionPoint.

//-------------------------------------------------------------------
// Return the index at which the given oid should be inserted in the
// `oids' array.
//-------------------------------------------------------------------
private static int getInsertionPoint(SnmpOid[] oids, int count, SnmpOid oid) {
    final SnmpOid[] localoids = oids;
    final int size = count;
    int low = 0;
    int max = size - 1;
    int curr = low + (max - low) / 2;
    while (low <= max) {
        final SnmpOid pos = localoids[curr];
        // never know ...we might find something ...
        //
        final int comp = oid.compareTo(pos);
        // given OID.
        if (comp == 0)
            return curr;
        if (comp > 0) {
            low = curr + 1;
        } else {
            max = curr - 1;
        }
        curr = low + (max - low) / 2;
    }
    return curr;
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid)

Example 20 with SnmpOid

use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.

the class JvmRTLibraryPathTableMetaImpl method getNextOid.

// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(SnmpOid oid, Object userData) throws SnmpStatusException {
    final boolean dbg = log.isDebugOn();
    if (dbg)
        log.debug("getNextOid", "previous=" + oid);
    // Get the data handler.
    //
    SnmpTableHandler handler = getHandler(userData);
    if (handler == null) {
        //
        if (dbg)
            log.debug("getNextOid", "handler is null!");
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    }
    // Get the next oid
    //
    final SnmpOid next = handler.getNext(oid);
    if (dbg)
        log.debug("*** **** **** **** getNextOid", "next=" + next);
    //
    if (next == null)
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    return next;
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpOid(com.sun.jmx.snmp.SnmpOid) SnmpTableHandler(sun.management.snmp.util.SnmpTableHandler)

Aggregations

SnmpOid (com.sun.jmx.snmp.SnmpOid)37 SnmpStatusException (com.sun.jmx.snmp.SnmpStatusException)15 SnmpTableHandler (sun.management.snmp.util.SnmpTableHandler)9 SnmpVarBind (com.sun.jmx.snmp.SnmpVarBind)4 SnmpValue (com.sun.jmx.snmp.SnmpValue)3 SnmpMibAgent (com.sun.jmx.snmp.agent.SnmpMibAgent)2 TreeMap (java.util.TreeMap)2 ObjectName (javax.management.ObjectName)2 Date (java.util.Date)1 Map (java.util.Map)1