Search in sources :

Example 1 with SnmpOid

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

the class SnmpMibTable method endRowAction.

/**
     * This method takes care of final RowStatus handling during the
     * set() phase of a SET request.
     *
     * In particular it will:
     *     <ul><li>either call <code>setRowStatus(<i>active</i>)</code>
     *         (<code> rowAction = <i>createAndGo</i> or <i>active</i>
     *         </code>),</li>
     *     <li>or call <code>setRowStatus(<i>notInService</i> or <i>
     *         notReady</i>)</code> depending on the result of <code>
     *         isRowReady()</code> (<code>rowAction = <i>createAndWait</i>
     *         </code>),</li>
     *     <li>or call <code>setRowStatus(<i>notInService</i>)</code>
     *         (<code> rowAction = <i>notInService</i></code>),
     *     <li>or call <code>removeTableRow()</code> (<code>
     *         rowAction = <i>destroy</i></code>),</li>
     *     <li>or generate a SnmpStatusException if the passed <code>
     *         rowAction</code> is not correct. This should be avoided
     *         since it would break SET request atomicity</li>
     *     </ul>
     * <p>
     * In principle, you should not need to redefine this method.
     * <p>
     * <code>endRowAction()</code> is called during the set() phase
     * of a SET request, after the actual set() on the varbind list
     * has been performed. The varbind containing the control variable
     * is updated with the value returned by setRowStatus() (if it is
     * not <code>null</code>).
     *
     * <p>
     * @param req    The sub-request that must be handled by this node.
     *
     * @param rowOid The <CODE>SnmpOid</CODE> identifying the table
     *               row involved in the operation.
     *
     * @param depth  The depth reached in the OID tree.
     *
     * @param rowAction The requested action as returned by <code>
     *        getRowAction()</code>: one of the RowStatus codes defined in
     *        {@link com.sun.jmx.snmp.EnumRowStatus}. These codes
     *        correspond to RowStatus codes as defined in RFC 2579,
     *        plus the <i>unspecified</i> value which is SNMP Runtime specific.
     *
     * @exception SnmpStatusException if the specified <code>rowAction</code>
     *            is not valid.
     *
     * @see com.sun.jmx.snmp.EnumRowStatus
     **/
protected void endRowAction(SnmpMibSubRequest req, SnmpOid rowOid, int depth, int rowAction) throws SnmpStatusException {
    final boolean isnew = req.isNewEntry();
    final SnmpOid oid = rowOid;
    final int action = rowAction;
    final Object data = req.getUserData();
    SnmpValue value = null;
    switch(action) {
        case EnumRowStatus.unspecified:
            break;
        case EnumRowStatus.createAndGo:
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'active' " + "for row[" + rowOid + "] : requested RowStatus = " + "createAndGo");
            }
            value = setRowStatus(oid, EnumRowStatus.active, data);
            break;
        case EnumRowStatus.createAndWait:
            if (isRowReady(oid, data)) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'notInService' for row[" + rowOid + "] : requested RowStatus = createAndWait");
                }
                value = setRowStatus(oid, EnumRowStatus.notInService, data);
            } else {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'notReady' " + "for row[" + rowOid + "] : requested RowStatus = " + "createAndWait");
                }
                value = setRowStatus(oid, EnumRowStatus.notReady, data);
            }
            break;
        case EnumRowStatus.destroy:
            if (isnew) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Warning: requested RowStatus = destroy, " + "but row[" + rowOid + "] does not exist");
                }
            } else {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Destroying row[" + rowOid + "] : requested RowStatus = destroy");
                }
            }
            removeTableRow(req, oid, depth);
            break;
        case EnumRowStatus.active:
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'active' for row[" + rowOid + "] : requested RowStatus = active");
            }
            value = setRowStatus(oid, EnumRowStatus.active, data);
            break;
        case EnumRowStatus.notInService:
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'notInService' for row[" + rowOid + "] : requested RowStatus = notInService");
            }
            value = setRowStatus(oid, EnumRowStatus.notInService, data);
            break;
        case EnumRowStatus.notReady:
        default:
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Invalid RowStatus value for row[" + rowOid + "] : specified RowStatus = " + action);
            }
            setRowStatusFail(req, SnmpStatusException.snmpRspInconsistentValue);
    }
    if (value != null) {
        final SnmpVarBind vb = req.getRowStatusVarBind();
        if (vb != null)
            vb.value = value;
    }
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid) SnmpValue(com.sun.jmx.snmp.SnmpValue) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 2 with SnmpOid

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

the class SnmpMibTable method get.

// ---------------------------------------------------------------------
//
// Implements the method defined in SnmpMibNode.
//
// ---------------------------------------------------------------------
/**
     * Generic handling of the <CODE>get</CODE> operation.
     * <p> The default implementation of this method is to
     * <ul>
     * <li> check whether the entry exists, and if not register an
     *      exception for each varbind in the list.
     * <li> call the generated
     *      <CODE>get(req,oid,depth+1)</CODE> method. </li>
     * </ul>
     * <p>
     * <pre>
     * public void get(SnmpMibSubRequest req, int depth)
     *    throws SnmpStatusException {
     *    boolean         isnew  = req.isNewEntry();
     *
     *    // if the entry does not exists, then registers an error for
     *    // each varbind involved (nb: this should not happen, since
     *    // the error should already have been detected earlier)
     *    //
     *    if (isnew) {
     *        SnmpVarBind     var = null;
     *        for (Enumeration e= req.getElements(); e.hasMoreElements();) {
     *            var = (SnmpVarBind) e.nextElement();
     *            req.registerGetException(var,noSuchNameException);
     *        }
     *    }
     *
     *    final SnmpOid oid = req.getEntryOid();
     *    get(req,oid,depth+1);
     * }
     * </pre>
     * <p> You should not need to override this method in any cases, because
     * it will eventually call
     * <CODE>get(SnmpMibSubRequest req, int depth)</CODE> on the generated
     * derivative of <CODE>SnmpMibEntry</CODE>. If you need to implement
     * 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,
     * you should then rather override
     * <CODE>get(SnmpMibSubRequest req, int depth)</CODE> on the generated
     * derivative of <CODE>SnmpMibEntry</CODE>.
     * <p>
     *
     */
@Override
public void get(SnmpMibSubRequest req, int depth) throws SnmpStatusException {
    final boolean isnew = req.isNewEntry();
    final SnmpMibSubRequest r = req;
    // should have been registered earlier)
    if (isnew) {
        SnmpVarBind var;
        for (Enumeration<SnmpVarBind> e = r.getElements(); e.hasMoreElements(); ) {
            var = e.nextElement();
            r.registerGetException(var, new SnmpStatusException(SnmpStatusException.noSuchInstance));
        }
    }
    final SnmpOid oid = r.getEntryOid();
    // SnmpIndex   index  = buildSnmpIndex(oid.longValue(false), 0);
    // get(req,index,depth+1);
    //
    get(req, oid, depth + 1);
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpOid(com.sun.jmx.snmp.SnmpOid) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 3 with SnmpOid

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

the class SnmpMibTable method removeEntry.

/**
     * Remove the specified entry from the table.
     * Also triggers the removeEntryCB() callback of the
     * {@link com.sun.jmx.snmp.agent.SnmpTableEntryFactory} interface
     * if this node is bound to a factory.
     *
     * <p>
     * @param pos The position of the entry in the table.
     *
     * @param entry The entry to be removed. This parameter is not used
     *              internally, it is simply passed along to the
     *              removeEntryCB() callback.
     *
     * @exception SnmpStatusException if the specified entry couldn't
     *            be removed.
     */
public synchronized void removeEntry(int pos, Object entry) throws SnmpStatusException {
    if (pos == -1)
        return;
    if (pos >= size)
        return;
    Object obj = entry;
    if (entries != null && entries.size() > pos) {
        obj = entries.elementAt(pos);
        entries.removeElementAt(pos);
    }
    ObjectName name = null;
    if (entrynames != null && entrynames.size() > pos) {
        name = entrynames.elementAt(pos);
        entrynames.removeElementAt(pos);
    }
    final SnmpOid rowOid = tableoids[pos];
    removeOid(pos);
    size--;
    if (obj == null)
        obj = entry;
    if (factory != null)
        factory.removeEntryCb(pos, rowOid, name, obj, this);
    sendNotification(SnmpTableEntryNotification.SNMP_ENTRY_REMOVED, (new Date()).getTime(), obj, name);
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid) Date(java.util.Date) ObjectName(javax.management.ObjectName)

Example 4 with SnmpOid

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

the class SnmpMibTable method findNextHandlingNode.

// ---------------------------------------------------------------------
//
// Implements the method defined in SnmpMibNode. The algorithm is very
// largely inspired from the original getNext() method.
//
// ---------------------------------------------------------------------
@Override
final synchronized long[] findNextHandlingNode(SnmpVarBind varbind, long[] oid, int pos, int depth, SnmpRequestTree handlers, AcmChecker checker) throws SnmpStatusException {
    int length = oid.length;
    if (handlers == null) {
        //
        throw new SnmpStatusException(SnmpStatusException.noSuchObject);
    }
    final Object data = handlers.getUserData();
    final int pduVersion = handlers.getRequestPduVersion();
    long var = -1;
    //
    if (pos >= length) {
        // this will have the side effect to set
        //    oid[pos] = nodeId
        // and
        //    (pos+1) = length
        // so we won't fall into the "else if" cases below -
        // so using "else if" rather than "if ..." is guaranteed
        // to be safe.
        //
        oid = new long[1];
        oid[0] = nodeId;
        pos = 0;
        length = 1;
    } else if (oid[pos] > nodeId) {
        //
        throw new SnmpStatusException(SnmpStatusException.noSuchObject);
    } else if (oid[pos] < nodeId) {
        // we must return the first leaf under the first columnar
        // object, so we are back to our first case where pos was
        // out of bounds... => reset the oid to contain only the
        // arc of the xxxEntry object.
        //
        oid = new long[1];
        oid[0] = nodeId;
        pos = 0;
        length = 0;
    } else if ((pos + 1) < length) {
        // The arc at the position "pos+1" is the id of the columnar
        // object (ie: the id of the variable in the table entry)
        //
        var = oid[pos + 1];
    }
    // Now that we've got everything right we can begin.
    SnmpOid entryoid;
    if (pos == (length - 1)) {
        // pos points to the last arc in the oid, and this arc is
        // guaranteed to be the xxxEntry id (we have handled all
        // the other possibilities before)
        //
        // We must therefore return the first leaf below the first
        // columnar object in the table.
        //
        // Get the first index. If an exception is raised,
        // then it means that the table is empty. We thus do not
        // have to catch the exception - we let it propagate to
        // the caller.
        //
        entryoid = getNextOid(data);
        var = getNextVarEntryId(entryoid, var, data, pduVersion);
    } else if (pos == (length - 2)) {
        // In that case we have (pos+1) = (length-1), so pos
        // points to the arc of the querried variable (columnar object).
        // Since the requested oid stops there, it means we have
        // to return the first leaf under this columnar object.
        //
        // So we first get the first index:
        // Note: if this raises an exception, this means that the table
        // is empty, so we can let the exception propagate to the caller.
        //
        entryoid = getNextOid(data);
        //
        if (skipEntryVariable(entryoid, var, data, pduVersion)) {
            var = getNextVarEntryId(entryoid, var, data, pduVersion);
        }
    } else {
        //
        try {
            entryoid = getNextOid(oid, pos + 2, data);
            //
            if (skipEntryVariable(entryoid, var, data, pduVersion)) {
                throw new SnmpStatusException(SnmpStatusException.noSuchObject);
            }
        } catch (SnmpStatusException se) {
            entryoid = getNextOid(data);
            var = getNextVarEntryId(entryoid, var, data, pduVersion);
        }
    }
    return findNextAccessibleOid(entryoid, varbind, oid, depth, handlers, checker, data, var);
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpOid(com.sun.jmx.snmp.SnmpOid)

Example 5 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)

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