Search in sources :

Example 36 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project tomcat 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(sm.getString("managedMBean.noAttribute", aname, resource));
    }
    String getMethod = attrInfo.getGetMethod();
    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, sm.getString("managedMBean.noGet", getMethod, resource));
    }
    return m;
}
Also used : MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Method(java.lang.reflect.Method)

Example 37 with AttributeNotFoundException

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

the class BaseModelMBean method setAttribute.

/**
 * Set the value of a specific attribute of this MBean.
 *
 * @param attribute The identification of the attribute to be set
 *  and the new value
 *
 * @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 void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    if (log.isDebugEnabled()) {
        log.debug("Setting attribute " + this + " " + attribute);
    }
    if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
        try {
            ((DynamicMBean) resource).setAttribute(attribute);
        } catch (InvalidAttributeValueException e) {
            throw new MBeanException(e);
        }
        return;
    }
    // Validate the input parameters
    if (attribute == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(sm.getString("baseModelMBean.nullAttribute")), sm.getString("baseModelMBean.nullAttribute"));
    }
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(sm.getString("baseModelMBean.nullAttributeName")), sm.getString("baseModelMBean.nullAttributeName"));
    }
    Object oldValue = null;
    // if( getAttMap.get(name) != null )
    // oldValue=getAttribute( name );
    Method m = managedBean.getSetter(name, this, resource);
    try {
        if (m.getDeclaringClass().isAssignableFrom(this.getClass())) {
            m.invoke(this, new Object[] { value });
        } else {
            m.invoke(resource, new Object[] { value });
        }
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t == null) {
            t = e;
        }
        if (t instanceof RuntimeException) {
            throw new RuntimeOperationsException((RuntimeException) t, sm.getString("baseModelMBean.invokeError", name));
        } else if (t instanceof Error) {
            throw new RuntimeErrorException((Error) t, sm.getString("baseModelMBean.invokeError", name));
        } else {
            throw new MBeanException(e, sm.getString("baseModelMBean.invokeError", name));
        }
    } catch (Exception e) {
        log.error(sm.getString("baseModelMBean.invokeError", name), e);
        throw new MBeanException(e, sm.getString("baseModelMBean.invokeError", name));
    }
    try {
        sendAttributeChangeNotification(new Attribute(name, oldValue), attribute);
    } catch (Exception ex) {
        log.error(sm.getString("baseModelMBean.notificationError", name), ex);
    }
// attributes.put( name, value );
// if( source != null ) {
// // this mbean is associated with a source - maybe we want to persist
// source.updateField(oname, name, value);
// }
}
Also used : DynamicMBean(javax.management.DynamicMBean) RuntimeErrorException(javax.management.RuntimeErrorException) Attribute(javax.management.Attribute) Method(java.lang.reflect.Method) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) 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 38 with AttributeNotFoundException

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

the class ContextResourceMBean method getAttribute.

/**
 * 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(sm.getString("mBean.nullName")), sm.getString("mBean.nullName"));
    }
    ContextResource cr = doGetManagedResource();
    String value = null;
    if ("auth".equals(name)) {
        return cr.getAuth();
    } else if ("description".equals(name)) {
        return cr.getDescription();
    } else if ("name".equals(name)) {
        return cr.getName();
    } else if ("scope".equals(name)) {
        return cr.getScope();
    } else if ("type".equals(name)) {
        return cr.getType();
    } else {
        value = (String) cr.getProperty(name);
        if (value == null) {
            throw new AttributeNotFoundException(sm.getString("mBean.attributeNotFound", name));
        }
    }
    return value;
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

Example 39 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project jmxtrans by jmxtrans.

the class TreeWalker3 method walkTree.

public void walkTree(MBeanServerConnection connection, Server server) throws Exception {
    // key here is null, null returns everything!
    Set<ObjectName> mbeans = connection.queryNames(null, null);
    Map<String, String> output = newHashMap();
    for (ObjectName name : mbeans) {
        MBeanInfo info = connection.getMBeanInfo(name);
        MBeanAttributeInfo[] attrs = info.getAttributes();
        Query.Builder queryBuilder = Query.builder().setObj(name.getCanonicalName());
        ResultCapture resultCapture = new ResultCapture();
        queryBuilder.addOutputWriterFactory(resultCapture);
        for (MBeanAttributeInfo attrInfo : attrs) {
            queryBuilder.addAttr(attrInfo.getName());
        }
        Query query = queryBuilder.build();
        try {
            Iterable<Result> results = server.execute(query);
            query.runOutputWritersForQuery(server, results);
        } catch (AttributeNotFoundException anfe) {
            log.error("Error", anfe);
        }
        for (Result result : resultCapture.results) {
            output.put(result.getTypeName(), query.getAttr().toString());
        }
    }
    for (Entry<String, String> entry : output.entrySet()) {
        log.debug(entry.getKey());
        log.debug(entry.getValue());
        log.debug("-----------------------------------------");
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) Query(com.googlecode.jmxtrans.model.Query) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Result(com.googlecode.jmxtrans.model.Result)

Example 40 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project Payara by payara.

the class AbstractDynamicMBeanImpl method getAttributes.

public final AttributeList getAttributes(String[] attributes) {
    AttributeList r = new AttributeList(attributes.length);
    for (String name : attributes) {
        Object value = null;
        try {
            value = getAttribute(name);
        } catch (AttributeNotFoundException e) {
        // error is reported as the lack of value
        } catch (MBeanException e) {
        // error is reported as the lack of value
        } catch (ReflectionException e) {
        // error is reported as the lack of value
        }
        r.add(new Attribute(name, value));
    }
    return r;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) MBeanException(javax.management.MBeanException)

Aggregations

AttributeNotFoundException (javax.management.AttributeNotFoundException)78 ReflectionException (javax.management.ReflectionException)57 MBeanException (javax.management.MBeanException)53 InstanceNotFoundException (javax.management.InstanceNotFoundException)40 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)31 Attribute (javax.management.Attribute)25 ObjectName (javax.management.ObjectName)24 RuntimeOperationsException (javax.management.RuntimeOperationsException)16 IntrospectionException (javax.management.IntrospectionException)13 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)13 Method (java.lang.reflect.Method)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 AttributeList (javax.management.AttributeList)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 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