Search in sources :

Example 36 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException in project wildfly by wildfly.

the class LogStoreTransactionDeleteHandler method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    MBeanServer mbs = TransactionExtension.getMBeanServer(context);
    final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
    try {
        final ObjectName on = LogStoreResource.getObjectName(resource);
        //  Invoke operation
        Object res = mbs.invoke(on, "remove", null, null);
        try {
            // validate that the MBean was removed:
            mbs.getObjectInstance(on);
            String reason = res != null ? res.toString() : LOG_DELETE_FAILURE_MESSAGE;
            throw new OperationFailedException(reason);
        } catch (InstanceNotFoundException e) {
            // success, the MBean was deleted
            final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
            final PathElement element = address.getLastElement();
            logStoreResource.removeChild(element);
        }
    } catch (OperationFailedException e) {
        throw e;
    } catch (Exception e) {
        throw new OperationFailedException(e.getMessage());
    }
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : PathElement(org.jboss.as.controller.PathElement) InstanceNotFoundException(javax.management.InstanceNotFoundException) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 37 with InstanceNotFoundException

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

the class DefaultMBeanServerInterceptor method getClassLoader.

/**
     * <p>Return the named {@link java.lang.ClassLoader}.
     * @param loaderName The ObjectName of the ClassLoader.
     * @return The named ClassLoader.
     * @exception InstanceNotFoundException if the named ClassLoader
     * is not found.
     */
public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException {
    if (loaderName == null) {
        checkMBeanPermission((String) null, null, null, "getClassLoader");
        return server.getClass().getClassLoader();
    }
    DynamicMBean instance = getMBean(loaderName);
    checkMBeanPermission(instance, null, loaderName, "getClassLoader");
    Object resource = getResource(instance);
    /* Check if the given MBean is a ClassLoader */
    if (!(resource instanceof ClassLoader))
        throw new InstanceNotFoundException(loaderName.toString() + " is not a classloader");
    return (ClassLoader) resource;
}
Also used : DynamicMBean(javax.management.DynamicMBean) InstanceNotFoundException(javax.management.InstanceNotFoundException) NamedObject(com.sun.jmx.mbeanserver.NamedObject)

Example 38 with InstanceNotFoundException

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

the class SnmpGenericObjectServer method set.

/**
     * Set the value of an SNMP variable.
     *
     * <p><b><i>
     * You should never need to use this method directly.
     * </i></b></p>
     *
     * @param meta  The impacted metadata object
     * @param name  The ObjectName of the impacted MBean
     * @param x     The new requested SnmpValue
     * @param id    The OID arc identifying the variable we're trying to set.
     * @param data  User contextual data allocated through the
     *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
     *
     * @return The new value of the variable after the operation.
     *
     * @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.registerSetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
     * </code>
     **/
public SnmpValue set(SnmpGenericMetaServer meta, ObjectName name, SnmpValue x, long id, Object data) throws SnmpStatusException {
    final String attname = meta.getAttributeName(id);
    final Object attvalue = meta.buildAttributeValue(id, x);
    final Attribute att = new Attribute(attname, attvalue);
    Object result = null;
    try {
        server.setAttribute(name, att);
        result = server.getAttribute(name, attname);
    } catch (InvalidAttributeValueException iv) {
        throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
    } catch (InstanceNotFoundException f) {
        throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (ReflectionException r) {
        throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (MBeanException m) {
        Exception t = m.getTargetException();
        if (t instanceof SnmpStatusException)
            throw (SnmpStatusException) t;
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    } catch (Exception e) {
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    }
    return meta.buildSnmpValue(id, result);
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) 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)

Example 39 with InstanceNotFoundException

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

the class SnmpGenericObjectServer method check.

/**
     * Checks whether a SET operation can be performed on a given SNMP
     * variable.
     *
     * @param meta  The impacted metadata object
     * @param name  The ObjectName of the impacted MBean
     * @param x     The new requested SnmpValue
     * @param id    The OID arc identifying the variable we're trying to set.
     * @param data  User contextual data allocated through the
     *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
     *
     * <p>
     * This method calls checkSetAccess() on the meta object, and then
     * tries to invoke the check<i>AttributeName</i>() method on the MBean.
     * If this method is not defined then it is assumed that the SET
     * won't fail.
     * </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>
     *
     * @exception SnmpStatusException if the requested SET operation must
     *      be rejected. Raising an exception will abort the request. <br>
     *      Exceptions should never be raised directly, but only by means of
     * <code>
     * req.registerCheckException(<i>VariableId</i>,<i>SnmpStatusException</i>)
     * </code>
     *
     **/
// XXX xxx ZZZ zzz Maybe we should go through the MBeanInfo here?
public void check(SnmpGenericMetaServer meta, ObjectName name, SnmpValue x, long id, Object data) throws SnmpStatusException {
    meta.checkSetAccess(x, id, data);
    try {
        final String attname = meta.getAttributeName(id);
        final Object attvalue = meta.buildAttributeValue(id, x);
        final Object[] params = new Object[1];
        final String[] signature = new String[1];
        params[0] = attvalue;
        signature[0] = attvalue.getClass().getName();
        server.invoke(name, "check" + attname, params, signature);
    } catch (SnmpStatusException e) {
        throw e;
    } catch (InstanceNotFoundException i) {
        throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (ReflectionException r) {
    // checkXXXX() not defined => do nothing
    } catch (MBeanException m) {
        Exception t = m.getTargetException();
        if (t instanceof SnmpStatusException)
            throw (SnmpStatusException) t;
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    } catch (Exception e) {
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) ReflectionException(javax.management.ReflectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) 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)

Example 40 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException 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.
     *
     * @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.
     */
@Override
public void setSnmpAdaptorName(ObjectName name) 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 };
    String[] signature = { "com.sun.jmx.snmp.agent.SnmpMibAgent" };
    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

InstanceNotFoundException (javax.management.InstanceNotFoundException)102 ObjectName (javax.management.ObjectName)59 ReflectionException (javax.management.ReflectionException)44 MBeanException (javax.management.MBeanException)32 MalformedObjectNameException (javax.management.MalformedObjectNameException)28 MBeanRegistrationException (javax.management.MBeanRegistrationException)25 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)19 MBeanServer (javax.management.MBeanServer)17 IOException (java.io.IOException)16 AttributeNotFoundException (javax.management.AttributeNotFoundException)16 Attribute (javax.management.Attribute)15 IntrospectionException (javax.management.IntrospectionException)14 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)14 AttributeList (javax.management.AttributeList)12 ObjectInstance (javax.management.ObjectInstance)12 MBeanInfo (javax.management.MBeanInfo)11 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)10 RuntimeOperationsException (javax.management.RuntimeOperationsException)9 ArrayList (java.util.ArrayList)7 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)7