Search in sources :

Example 26 with SnmpVarBind

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

the class SnmpStandardObjectServer method get.

/**
     * Generic handling of the <CODE>get</CODE> operation.
     * <p> The default implementation of this method is to loop over the
     * varbind list associated with the sub-request and to call
     * <CODE>get(var.oid.getOidArc(depth), data);</CODE>
     * <pre>
     * public void get(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
     *                 int depth)
     *    throws SnmpStatusException {
     *
     *    final Object data = req.getUserData();
     *
     *    for (Enumeration e= req.getElements(); e.hasMoreElements();) {
     *
     *        final SnmpVarBind var= (SnmpVarBind) e.nextElement();
     *
     *        try {
     *            // This method will generate a SnmpStatusException
     *            // if `depth' is out of bounds.
     *            //
     *            final long id = var.oid.getOidArc(depth);
     *            var.value = meta.get(id, data);
     *        } catch(SnmpStatusException x) {
     *            req.registerGetException(var,x);
     *        }
     *    }
     * }
     * </pre>
     * <p> You can override this method if you need to implement some
     * specific policies for minimizing the accesses made to some remote
     * underlying resources.
     * <p>
     *
     * @param meta  A pointer to the generated meta-data object which
     *              implements the <code>SnmpStandardMetaServer</code>
     *              interface.
     *
     * @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.
     */
public void get(SnmpStandardMetaServer meta, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
    final Object data = req.getUserData();
    for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
        final SnmpVarBind var = e.nextElement();
        try {
            final long id = var.oid.getOidArc(depth);
            var.value = meta.get(id, data);
        } catch (SnmpStatusException x) {
            req.registerGetException(var, x);
        }
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 27 with SnmpVarBind

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

the class SnmpStandardObjectServer method set.

/**
     * Generic handling of the <CODE>set</CODE> operation.
     * <p> The default implementation of this method is to loop over the
     * varbind list associated with the sub-request and to call
     * <CODE>set(var.value, var.oid.getOidArc(depth), data);</CODE>
     * <pre>
     * public void set(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
     *                 int depth)
     *    throws SnmpStatusException {
     *
     *    final Object data = req.getUserData();
     *
     *    for (Enumeration e= req.getElements(); e.hasMoreElements();) {
     *
     *        final SnmpVarBind var= (SnmpVarBind) e.nextElement();
     *
     *        try {
     *            // This method will generate a SnmpStatusException
     *            // if `depth' is out of bounds.
     *            //
     *            final long id = var.oid.getOidArc(depth);
     *            var.value = meta.set(var.value, id, data);
     *        } catch(SnmpStatusException x) {
     *            req.registerSetException(var,x);
     *        }
     *    }
     * }
     * </pre>
     * <p> You can override this method if you need to implement some
     * specific policies for minimizing the accesses made to some remote
     * underlying resources.
     * <p>
     *
     * @param meta  A pointer to the generated meta-data object which
     *              implements the <code>SnmpStandardMetaServer</code>
     *              interface.
     *
     * @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.
     */
public void set(SnmpStandardMetaServer meta, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
    final Object data = req.getUserData();
    for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
        SnmpVarBind var = e.nextElement();
        try {
            // This method will generate a SnmpStatusException
            // if `depth' is out of bounds.
            //
            final long id = var.oid.getOidArc(depth);
            var.value = meta.set(var.value, id, data);
        } catch (SnmpStatusException x) {
            req.registerSetException(var, x);
        }
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 28 with SnmpVarBind

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

the class SnmpMibTable method getRowAction.

/**
     * Return the RowStatus code value specified in this request.
     * <p>
     * The RowStatus code value should be one of the values defined
     * by {@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.
     * <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.
     *
     * @return The RowStatus code specified in this request, if any:
     * <ul>
     * <li>If the specified row does not exist and this table do
     *     not use any variable to control creation/deletion of
     *     rows, then default creation mechanism is assumed and
     *     <i>createAndGo</i> is returned</li>
     * <li>Otherwise, if the row exists and this table do not use any
     *     variable to control creation/deletion of rows,
     *     <i>unspecified</i> is returned.</li>
     * <li>Otherwise, if the request does not contain the control variable,
     *     <i>unspecified</i> is returned.</li>
     * <li>Otherwise, mapRowStatus() is called to extract the RowStatus
     *     code from the SnmpVarBind that contains the control variable.</li>
     * </ul>
     *
     * @exception SnmpStatusException if the value of the control variable
     *            could not be mapped to a RowStatus code.
     *
     * @see com.sun.jmx.snmp.EnumRowStatus
     **/
protected int getRowAction(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException {
    final boolean isnew = req.isNewEntry();
    final SnmpVarBind vb = req.getRowStatusVarBind();
    if (vb == null) {
        if (isnew && !hasRowStatus())
            return EnumRowStatus.createAndGo;
        else
            return EnumRowStatus.unspecified;
    }
    try {
        return mapRowStatus(rowOid, vb, req.getUserData());
    } catch (SnmpStatusException x) {
        checkRowStatusFail(req, x.getStatus());
    }
    return EnumRowStatus.unspecified;
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 29 with SnmpVarBind

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

the class SnmpMibTable method checkRowStatusFail.

// ---------------------------------------------------------------------
//
// Register an exception when checking the RowStatus variable
//
// ---------------------------------------------------------------------
static void checkRowStatusFail(SnmpMibSubRequest req, int errorStatus) throws SnmpStatusException {
    final SnmpVarBind statusvb = req.getRowStatusVarBind();
    final SnmpStatusException x = new SnmpStatusException(errorStatus);
    req.registerCheckException(statusvb, x);
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 30 with SnmpVarBind

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

the class SnmpMibAgent method splitFrom.

// ---------------------------------------------------------------------
// PRIVATE METHODS
// ---------------------------------------------------------------------
/**
     * This method creates a new Vector which does not contain the first
     * element up to the specified limit.
     *
     * @param original The original vector.
     * @param limit The limit.
     */
private Vector<SnmpVarBind> splitFrom(Vector<SnmpVarBind> original, int limit) {
    int max = original.size();
    Vector<SnmpVarBind> result = new Vector<>(max - limit);
    int i = limit;
    //
    for (Enumeration<SnmpVarBind> e = original.elements(); e.hasMoreElements(); --i) {
        SnmpVarBind var = e.nextElement();
        if (i > 0)
            continue;
        result.addElement(new SnmpVarBind(var.oid, var.value));
    }
    return result;
}
Also used : SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind) Vector(java.util.Vector)

Aggregations

SnmpVarBind (com.sun.jmx.snmp.SnmpVarBind)35 SnmpStatusException (com.sun.jmx.snmp.SnmpStatusException)18 SnmpTimeticks (com.sun.jmx.snmp.SnmpTimeticks)5 SnmpVarBindList (com.sun.jmx.snmp.SnmpVarBindList)5 SnmpOid (com.sun.jmx.snmp.SnmpOid)4 SnmpPduRequest (com.sun.jmx.snmp.SnmpPduRequest)3 SnmpValue (com.sun.jmx.snmp.SnmpValue)3 SnmpMibAgent (com.sun.jmx.snmp.agent.SnmpMibAgent)2 Vector (java.util.Vector)2 Attribute (javax.management.Attribute)2 AttributeList (javax.management.AttributeList)2 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)2 MBeanException (javax.management.MBeanException)2 MBeanRegistrationException (javax.management.MBeanRegistrationException)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)2 ReflectionException (javax.management.ReflectionException)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 SnmpPduPacket (com.sun.jmx.snmp.SnmpPduPacket)1