Search in sources :

Example 1 with SnmpVarBind

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

the class SnmpMibOid method get.

// PUBLIC METHODS
//---------------
/**
     * Generic handling of the <CODE>get</CODE> operation.
     *
     * <p> This method should be overridden in subclasses.
     * <p>
     *
     * @param req   The sub-request that must be handled by this node.
     *
     * @param depth The depth reached in the OID tree.
     *
     * @exception SnmpStatusException The default implementation (if not
     *            overridden) is to generate a SnmpStatusException.
     */
@Override
public void get(SnmpMibSubRequest req, int depth) throws SnmpStatusException {
    for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
        SnmpVarBind var = e.nextElement();
        SnmpStatusException x = new SnmpStatusException(SnmpStatusException.noSuchObject);
        req.registerGetException(var, x);
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 2 with SnmpVarBind

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

the class SnmpMibOid method set.

/**
     * Generic handling of the <CODE>set</CODE> operation.
     *
     * <p> This method should be overridden in subclasses.
     * <p>
     *
     * @param req   The sub-request that must be handled by this node.
     *
     * @param depth The depth reached in the OID tree.
     *
     * @exception SnmpStatusException The default implementation (if not
     *            overridden) is to generate a SnmpStatusException.
     */
@Override
public void set(SnmpMibSubRequest req, int depth) throws SnmpStatusException {
    for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
        SnmpVarBind var = e.nextElement();
        SnmpStatusException x = new SnmpStatusException(SnmpStatusException.noAccess);
        req.registerSetException(var, x);
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 3 with SnmpVarBind

use of com.sun.jmx.snmp.SnmpVarBind 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 4 with SnmpVarBind

use of com.sun.jmx.snmp.SnmpVarBind 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 5 with SnmpVarBind

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

the class SnmpErrorHandlerAgent method getNext.

/**
     * Processes a <CODE>getNext</CODE> operation. It will throw an exception for V1 requests or it will set exceptions within the list for V2 requests..
     *
     * @param inRequest The SnmpMibRequest object holding the list of variables to be retrieved.
     *
     * @exception SnmpStatusException An error occurred during the operation.
     */
@Override
public void getNext(SnmpMibRequest inRequest) throws SnmpStatusException {
    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpErrorHandlerAgent.class.getName(), "getNext", "GetNext in Exception");
    if (inRequest.getVersion() == SnmpDefinitions.snmpVersionOne)
        throw new SnmpStatusException(SnmpStatusException.noSuchName);
    Enumeration<SnmpVarBind> l = inRequest.getElements();
    while (l.hasMoreElements()) {
        SnmpVarBind varbind = l.nextElement();
        varbind.setEndOfMibView();
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

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