Search in sources :

Example 56 with AttributeNotFoundException

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

the class DefaultMBeanServerInterceptor method getAttribute.

public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException {
    if (name == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Object name cannot be null"), "Exception occurred trying to invoke the getter on the MBean");
    }
    if (attribute == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Exception occurred trying to invoke the getter on the MBean");
    }
    name = nonDefaultDomain(name);
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "getAttribute", "Attribute = " + attribute + ", ObjectName = " + name);
    }
    final DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, attribute, name, "getAttribute");
    try {
        return instance.getAttribute(attribute);
    } catch (AttributeNotFoundException e) {
        throw e;
    } catch (Throwable t) {
        rethrowMaybeMBeanException(t);
        // not reached
        throw new AssertionError();
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) AttributeNotFoundException(javax.management.AttributeNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 57 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project tomcat70 by apache.

the class ContextResourceLinkMBean method getAttribute.

// ----------------------------------------------------- Instance Variables
// ------------------------------------------------------------- Attributes
/**
 * Obtain and return the value of a specific attribute of this MBean.
 *
 * @param name Name of the requested attribute
 *
 * @exception AttributeNotFoundException if this attribute is not
 *  supported by this MBean
 * @exception MBeanException if the initializer of an object
 *  throws an exception
 * @exception ReflectionException if a Java reflection exception
 *  occurs when invoking the getter
 */
@Override
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
    // Validate the input parameters
    if (name == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
    ContextResourceLink cl = null;
    try {
        cl = (ContextResourceLink) getManagedResource();
    } catch (InstanceNotFoundException e) {
        throw new MBeanException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new MBeanException(e);
    }
    String value = null;
    if ("global".equals(name)) {
        return (cl.getGlobal());
    } else if ("description".equals(name)) {
        return (cl.getDescription());
    } else if ("name".equals(name)) {
        return (cl.getName());
    } else if ("type".equals(name)) {
        return (cl.getType());
    } else {
        value = (String) cl.getProperty(name);
        if (value == null) {
            throw new AttributeNotFoundException("Cannot find attribute " + name);
        }
    }
    return value;
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) ContextResourceLink(org.apache.catalina.deploy.ContextResourceLink) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 58 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project tomcat70 by apache.

the class ManagedBean method getGetter.

Method getGetter(String aname, BaseModelMBean mbean, Object resource) throws AttributeNotFoundException, ReflectionException {
    Method m = null;
    AttributeInfo attrInfo = attributes.get(aname);
    // Look up the actual operation to be used
    if (attrInfo == null)
        throw new AttributeNotFoundException(" Cannot find attribute " + aname + " for " + resource);
    String getMethod = attrInfo.getGetMethod();
    if (getMethod == null)
        throw new AttributeNotFoundException("Cannot find attribute " + aname + " get method name");
    Object object = null;
    NoSuchMethodException exception = null;
    try {
        object = mbean;
        m = object.getClass().getMethod(getMethod, NO_ARGS_PARAM_SIG);
    } catch (NoSuchMethodException e) {
        exception = e;
    }
    if (m == null && resource != null) {
        try {
            object = resource;
            m = object.getClass().getMethod(getMethod, NO_ARGS_PARAM_SIG);
            exception = null;
        } catch (NoSuchMethodException e) {
            exception = e;
        }
    }
    if (exception != null)
        throw new ReflectionException(exception, "Cannot find getter method " + getMethod);
    return m;
}
Also used : MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Method(java.lang.reflect.Method)

Example 59 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project tomcat70 by apache.

the class BaseModelMBean method getAttribute.

// key: operation val: invoke method
// private Hashtable invokeAttMap=new Hashtable();
/**
 * Obtain and return the value of a specific attribute of this MBean.
 *
 * @param name Name of the requested attribute
 *
 * @exception AttributeNotFoundException if this attribute is not
 *  supported by this MBean
 * @exception MBeanException if the initializer of an object
 *  throws an exception
 * @exception ReflectionException if a Java reflection exception
 *  occurs when invoking the getter
 */
@Override
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
    // Validate the input parameters
    if (name == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
    if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
        return ((DynamicMBean) resource).getAttribute(name);
    }
    Method m = managedBean.getGetter(name, this, resource);
    Object result = null;
    try {
        Class<?> declaring = m.getDeclaringClass();
        // but this is the catalina class.
        if (declaring.isAssignableFrom(this.getClass())) {
            result = m.invoke(this, NO_ARGS_PARAM);
        } else {
            result = m.invoke(resource, NO_ARGS_PARAM);
        }
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t == null)
            t = e;
        if (t instanceof RuntimeException)
            throw new RuntimeOperationsException((RuntimeException) t, "Exception invoking method " + name);
        else if (t instanceof Error)
            throw new RuntimeErrorException((Error) t, "Error invoking method " + name);
        else
            throw new MBeanException(e, "Exception invoking method " + name);
    } catch (Exception e) {
        throw new MBeanException(e, "Exception invoking method " + name);
    }
    // FIXME - should we validate the return type?
    return (result);
}
Also used : DynamicMBean(javax.management.DynamicMBean) RuntimeErrorException(javax.management.RuntimeErrorException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 60 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project acs-aem-commons by Adobe-Consulting-Services.

the class ThrottledTaskRunnerImpl method getMemoryUsage.

@Override
public final double getMemoryUsage() {
    try {
        Object memoryusage = mbs.getAttribute(memBeanName, "HeapMemoryUsage");
        CompositeData cd = (CompositeData) memoryusage;
        long max = (Long) cd.get("max");
        long used = (Long) cd.get("used");
        return (double) used / (double) max;
    } catch (AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException e) {
        LOG.error("No Memory stats found for HeapMemoryUsage", e);
        return -1;
    }
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) CompositeData(javax.management.openmbean.CompositeData) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException)

Aggregations

AttributeNotFoundException (javax.management.AttributeNotFoundException)77 ReflectionException (javax.management.ReflectionException)57 MBeanException (javax.management.MBeanException)54 InstanceNotFoundException (javax.management.InstanceNotFoundException)40 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)30 Attribute (javax.management.Attribute)26 ObjectName (javax.management.ObjectName)24 RuntimeOperationsException (javax.management.RuntimeOperationsException)16 IntrospectionException (javax.management.IntrospectionException)13 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)13 AttributeList (javax.management.AttributeList)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 Method (java.lang.reflect.Method)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 Test (org.testng.annotations.Test)9 MBeanInfo (javax.management.MBeanInfo)8 ListenerNotFoundException (javax.management.ListenerNotFoundException)7 RuntimeErrorException (javax.management.RuntimeErrorException)7 RuntimeMBeanException (javax.management.RuntimeMBeanException)7 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)7