Search in sources :

Example 51 with ReflectionException

use of javax.management.ReflectionException in project jdk8u_jdk by JetBrains.

the class SnmpGenericObjectServer method get.

/**
     * Execute an SNMP GET request.
     *
     * <p>
     * This method first builds the list of attributes that need to be
     * retrieved from the MBean and then calls getAttributes() on the
     * MBean server. Then it updates the SnmpMibSubRequest with the values
     * retrieved from the MBean.
     * </p>
     *
     * <p>
     * The SNMP metadata information is obtained through the given
     * <code>meta</code> object, which usually is an instance of a
     * <code>mibgen</code> generated class.
     * </p>
     *
     * <p><b><i>
     * This method is called internally by <code>mibgen</code> generated
     * objects and you should never need to call it directly.
     * </i></b></p>
     *
     * @param meta  The metadata object impacted by the subrequest
     * @param name  The ObjectName of the MBean impacted by this subrequest
     * @param req   The SNMP subrequest to execute on the MBean
     * @param depth The depth of the SNMP object in the OID tree.
     *
     * @exception SnmpStatusException whenever an SNMP exception must be
     *      raised. Raising an exception will abort the request.<br>
     *      Exceptions should never be raised directly, but only by means of
     * <code>
     * req.registerGetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
     * </code>
     **/
public void get(SnmpGenericMetaServer meta, ObjectName name, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
    // java.lang.System.out.println(">>>>>>>>> GET " + name);
    final int size = req.getSize();
    final Object data = req.getUserData();
    final String[] nameList = new String[size];
    final SnmpVarBind[] varList = new SnmpVarBind[size];
    final long[] idList = new long[size];
    int i = 0;
    for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
        final SnmpVarBind var = e.nextElement();
        try {
            final long id = var.oid.getOidArc(depth);
            nameList[i] = meta.getAttributeName(id);
            varList[i] = var;
            idList[i] = id;
            // Check the access rights according to the MIB.
            // The MBean might be less restrictive (have a getter
            // while the MIB defines the variable as AFN)
            //
            meta.checkGetAccess(id, data);
            //java.lang.System.out.println(nameList[i] + " added.");
            i++;
        } catch (SnmpStatusException x) {
            //java.lang.System.out.println("exception for " + nameList[i]);
            //x.printStackTrace();
            req.registerGetException(var, x);
        }
    }
    AttributeList result = null;
    int errorCode = SnmpStatusException.noSuchInstance;
    try {
        result = server.getAttributes(name, nameList);
    } catch (InstanceNotFoundException f) {
        //java.lang.System.out.println(name + ": instance not found.");
        //f.printStackTrace();
        result = new AttributeList();
    } catch (ReflectionException r) {
        //java.lang.System.out.println(name + ": reflexion error.");
        //r.printStackTrace();
        result = new AttributeList();
    } catch (Exception x) {
        result = new AttributeList();
    }
    final Iterator<?> it = result.iterator();
    for (int j = 0; j < i; j++) {
        if (!it.hasNext()) {
            //java.lang.System.out.println(name + "variable[" + j +
            //                           "] absent");
            final SnmpStatusException x = new SnmpStatusException(errorCode);
            req.registerGetException(varList[j], x);
            continue;
        }
        final Attribute att = (Attribute) it.next();
        while ((j < i) && (!nameList[j].equals(att.getName()))) {
            //java.lang.System.out.println(name + "variable[" +j +
            //                           "] not found");
            final SnmpStatusException x = new SnmpStatusException(errorCode);
            req.registerGetException(varList[j], x);
            j++;
        }
        if (j == i)
            break;
        try {
            varList[j].value = meta.buildSnmpValue(idList[j], att.getValue());
        } catch (SnmpStatusException x) {
            req.registerGetException(varList[j], x);
        }
    //java.lang.System.out.println(att.getName() + " retrieved.");
    }
//java.lang.System.out.println(">>>>>>>>> END GET");
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 52 with ReflectionException

use of javax.management.ReflectionException in project jdk8u_jdk by JetBrains.

the class SnmpGenericObjectServer method set.

/**
     * Execute an SNMP SET request.
     *
     * <p>
     * This method first builds the list of attributes that need to be
     * set on the MBean and then calls setAttributes() on the
     * MBean server. Then it updates the SnmpMibSubRequest with the new
     * values retrieved from the MBean.
     * </p>
     *
     * <p>
     * The SNMP metadata information is obtained through the given
     * <code>meta</code> object, which usually is an instance of a
     * <code>mibgen</code> generated class.
     * </p>
     *
     * <p><b><i>
     * This method is called internally by <code>mibgen</code> generated
     * objects and you should never need to call it directly.
     * </i></b></p>
     *
     * @param meta  The metadata object impacted by the subrequest
     * @param name  The ObjectName of the MBean impacted by this subrequest
     * @param req   The SNMP subrequest to execute on the MBean
     * @param depth The depth of the SNMP object in the OID tree.
     *
     * @exception SnmpStatusException whenever an SNMP exception must be
     *      raised. Raising an exception will abort the request. <br>
     *      Exceptions should never be raised directly, but only by means of
     * <code>
     * req.registerGetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
     * </code>
     **/
public void set(SnmpGenericMetaServer meta, ObjectName name, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
    final int size = req.getSize();
    final AttributeList attList = new AttributeList(size);
    final String[] nameList = new String[size];
    final SnmpVarBind[] varList = new SnmpVarBind[size];
    final long[] idList = new long[size];
    int i = 0;
    for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
        final SnmpVarBind var = e.nextElement();
        try {
            final long id = var.oid.getOidArc(depth);
            final String attname = meta.getAttributeName(id);
            final Object attvalue = meta.buildAttributeValue(id, var.value);
            final Attribute att = new Attribute(attname, attvalue);
            attList.add(att);
            nameList[i] = attname;
            varList[i] = var;
            idList[i] = id;
            i++;
        } catch (SnmpStatusException x) {
            req.registerSetException(var, x);
        }
    }
    AttributeList result;
    int errorCode = SnmpStatusException.noAccess;
    try {
        result = server.setAttributes(name, attList);
    } catch (InstanceNotFoundException f) {
        result = new AttributeList();
        errorCode = SnmpStatusException.snmpRspInconsistentName;
    } catch (ReflectionException r) {
        errorCode = SnmpStatusException.snmpRspInconsistentName;
        result = new AttributeList();
    } catch (Exception x) {
        result = new AttributeList();
    }
    final Iterator<?> it = result.iterator();
    for (int j = 0; j < i; j++) {
        if (!it.hasNext()) {
            final SnmpStatusException x = new SnmpStatusException(errorCode);
            req.registerSetException(varList[j], x);
            continue;
        }
        final Attribute att = (Attribute) it.next();
        while ((j < i) && (!nameList[j].equals(att.getName()))) {
            final SnmpStatusException x = new SnmpStatusException(SnmpStatusException.noAccess);
            req.registerSetException(varList[j], x);
            j++;
        }
        if (j == i)
            break;
        try {
            varList[j].value = meta.buildSnmpValue(idList[j], att.getValue());
        } catch (SnmpStatusException x) {
            req.registerSetException(varList[j], x);
        }
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 53 with ReflectionException

use of javax.management.ReflectionException in project jdk8u_jdk by JetBrains.

the class SnmpMibAgent method setSnmpAdaptorName.

/**
     * Sets the reference to the SNMP protocol adaptor through which the MIB
     * will be SNMP accessible and add this new MIB in the SNMP MIB handler
     * associated to the specified <CODE>name</CODE>.
     *
     * @param name The name of the SNMP protocol adaptor.
     * @param contextName The MIB context name. If null is passed, will be registered in the default context.
     * @exception InstanceNotFoundException The SNMP protocol adaptor does
     *     not exist in the MBean server.
     *
     * @exception ServiceNotFoundException This SNMP MIB is not registered
     *     in the MBean server or the requested service is not supported.
     *
     * @since 1.5
     */
@Override
public void setSnmpAdaptorName(ObjectName name, String contextName) throws InstanceNotFoundException, ServiceNotFoundException {
    if (server == null) {
        throw new ServiceNotFoundException(mibName + " is not registered in the MBean server");
    }
    //
    if (adaptor != null) {
        adaptor.removeMib(this, contextName);
    }
    // Then update the reference to the new adaptor server.
    //
    Object[] params = { this, contextName };
    String[] signature = { "com.sun.jmx.snmp.agent.SnmpMibAgent", "java.lang.String" };
    try {
        adaptor = (SnmpMibHandler) (server.invoke(name, "addMib", params, signature));
    } catch (InstanceNotFoundException e) {
        throw new InstanceNotFoundException(name.toString());
    } catch (ReflectionException e) {
        throw new ServiceNotFoundException(name.toString());
    } catch (MBeanException e) {
    // Should never occur...
    }
    adaptorName = name;
}
Also used : ReflectionException(javax.management.ReflectionException) ServiceNotFoundException(javax.management.ServiceNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException)

Example 54 with ReflectionException

use of javax.management.ReflectionException in project jdk8u_jdk by JetBrains.

the class SnmpMibAgent method setSnmpAdaptorName.

/**
     * Sets the reference to the SNMP protocol adaptor through which the MIB
     * will be SNMP accessible and add this new MIB in the SNMP MIB handler
     * associated to the specified <CODE>name</CODE>.
     * This method is to be called to set a specific agent to a specific OID. This can be useful when dealing with MIB overlapping.
     * Some OID can be implemented in more than one MIB. In this case, the OID nearer agent will be used on SNMP operations.
     * @param name The name of the SNMP protocol adaptor.
     * @param oids The set of OIDs this agent implements.
     * @exception InstanceNotFoundException The SNMP protocol adaptor does
     *     not exist in the MBean server.
     *
     * @exception ServiceNotFoundException This SNMP MIB is not registered
     *     in the MBean server or the requested service is not supported.
     *
     * @since 1.5
     */
@Override
public void setSnmpAdaptorName(ObjectName name, SnmpOid[] oids) throws InstanceNotFoundException, ServiceNotFoundException {
    if (server == null) {
        throw new ServiceNotFoundException(mibName + " is not registered in the MBean server");
    }
    //
    if (adaptor != null) {
        adaptor.removeMib(this);
    }
    // Then update the reference to the new adaptor server.
    //
    Object[] params = { this, oids };
    String[] signature = { "com.sun.jmx.snmp.agent.SnmpMibAgent", oids.getClass().getName() };
    try {
        adaptor = (SnmpMibHandler) (server.invoke(name, "addMib", params, signature));
    } catch (InstanceNotFoundException e) {
        throw new InstanceNotFoundException(name.toString());
    } catch (ReflectionException e) {
        throw new ServiceNotFoundException(name.toString());
    } catch (MBeanException e) {
    // Should never occur...
    }
    adaptorName = name;
}
Also used : ReflectionException(javax.management.ReflectionException) ServiceNotFoundException(javax.management.ServiceNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException)

Example 55 with ReflectionException

use of javax.management.ReflectionException in project jdk8u_jdk by JetBrains.

the class SnmpMibAgent method setSnmpAdaptorName.

/**
     * Sets the reference to the SNMP protocol adaptor through which the MIB
     * will be SNMP accessible and add this new MIB in the SNMP MIB handler
     * associated to the specified <CODE>name</CODE>.
     *
     * @param name The name of the SNMP protocol adaptor.
     * @param contextName The MIB context name. If null is passed, will be registered in the default context.
     * @param oids The set of OIDs this agent implements.
     * @exception InstanceNotFoundException The SNMP protocol adaptor does
     *     not exist in the MBean server.
     *
     * @exception ServiceNotFoundException This SNMP MIB is not registered
     *     in the MBean server or the requested service is not supported.
     *
     * @since 1.5
     */
@Override
public void setSnmpAdaptorName(ObjectName name, String contextName, SnmpOid[] oids) throws InstanceNotFoundException, ServiceNotFoundException {
    if (server == null) {
        throw new ServiceNotFoundException(mibName + " is not registered in the MBean server");
    }
    //
    if (adaptor != null) {
        adaptor.removeMib(this, contextName);
    }
    // Then update the reference to the new adaptor server.
    //
    Object[] params = { this, contextName, oids };
    String[] signature = { "com.sun.jmx.snmp.agent.SnmpMibAgent", "java.lang.String", oids.getClass().getName() };
    try {
        adaptor = (SnmpMibHandler) (server.invoke(name, "addMib", params, signature));
    } catch (InstanceNotFoundException e) {
        throw new InstanceNotFoundException(name.toString());
    } catch (ReflectionException e) {
        throw new ServiceNotFoundException(name.toString());
    } catch (MBeanException e) {
    // Should never occur...
    }
    adaptorName = name;
}
Also used : ReflectionException(javax.management.ReflectionException) ServiceNotFoundException(javax.management.ServiceNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException)

Aggregations

ReflectionException (javax.management.ReflectionException)72 InstanceNotFoundException (javax.management.InstanceNotFoundException)50 MBeanException (javax.management.MBeanException)46 AttributeNotFoundException (javax.management.AttributeNotFoundException)31 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)23 ObjectName (javax.management.ObjectName)22 Attribute (javax.management.Attribute)19 RuntimeOperationsException (javax.management.RuntimeOperationsException)17 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 IntrospectionException (javax.management.IntrospectionException)13 Method (java.lang.reflect.Method)12 AttributeList (javax.management.AttributeList)12 ServiceNotFoundException (javax.management.ServiceNotFoundException)12 IOException (java.io.IOException)11 MBeanInfo (javax.management.MBeanInfo)11 RuntimeErrorException (javax.management.RuntimeErrorException)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 ListenerNotFoundException (javax.management.ListenerNotFoundException)9 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)9 MBeanRegistrationException (javax.management.MBeanRegistrationException)9