Search in sources :

Example 16 with Attribute

use of javax.management.Attribute in project hive by apache.

the class MetricsMBeanImpl method setAttributes.

@Override
public AttributeList setAttributes(AttributeList arg0) {
    AttributeList attributesSet = new AttributeList();
    for (Attribute attr : arg0.asList()) {
        try {
            setAttribute(attr);
            attributesSet.add(attr);
        } catch (AttributeNotFoundException e) {
        // ignore exception - we simply don't add this attribute
        // back in to the resultant set.
        } catch (InvalidAttributeValueException e) {
        // ditto
        } catch (MBeanException e) {
        // likewise
        } catch (ReflectionException e) {
        // and again, one last time.
        }
    }
    return attributesSet;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

Example 17 with Attribute

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

the class JMXProxyServlet method setAttributeInternal.

/**
     * Sets an MBean attribute's value.
     */
private void setAttributeInternal(String onameStr, String attributeName, String value) throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname = new ObjectName(onameStr);
    String type = registry.getType(oname, attributeName);
    Object valueObj = registry.convertValue(type, value);
    mBeanServer.setAttribute(oname, new Attribute(attributeName, valueObj));
}
Also used : Attribute(javax.management.Attribute) ObjectName(javax.management.ObjectName)

Example 18 with Attribute

use of javax.management.Attribute 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("Attribute is null"), "Attribute is null");
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
    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, "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) {
        log.error("Exception invoking method " + name, e);
        throw new MBeanException(e, "Exception invoking method " + name);
    }
    try {
        sendAttributeChangeNotification(new Attribute(name, oldValue), attribute);
    } catch (Exception ex) {
        log.error("Error sending notification " + 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 19 with Attribute

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

the class BaseModelMBean method setAttributes.

/**
     * Set the values of several attributes of this MBean.
     *
     * @param attributes THe names and values to be set
     *
     * @return The list of attributes that were set and their new values
     */
@Override
public AttributeList setAttributes(AttributeList attributes) {
    AttributeList response = new AttributeList();
    // Validate the input parameters
    if (attributes == null)
        return response;
    // Prepare and return our response, eating all exceptions
    String[] names = new String[attributes.size()];
    int n = 0;
    Iterator<?> items = attributes.iterator();
    while (items.hasNext()) {
        Attribute item = (Attribute) items.next();
        names[n++] = item.getName();
        try {
            setAttribute(item);
        } catch (Exception e) {
        // Ignore all exceptions
        }
    }
    return (getAttributes(names));
}
Also used : Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) 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)

Example 20 with Attribute

use of javax.management.Attribute in project jetty.project by eclipse.

the class ObjectMBean method setAttributes.

/* ------------------------------------------------------------ */
public AttributeList setAttributes(AttributeList attrs) {
    if (LOG.isDebugEnabled())
        LOG.debug("setAttributes");
    AttributeList results = new AttributeList(attrs.size());
    Iterator<Object> iter = attrs.iterator();
    while (iter.hasNext()) {
        try {
            Attribute attr = (Attribute) iter.next();
            setAttribute(attr);
            results.add(new Attribute(attr.getName(), getAttribute(attr.getName())));
        } catch (Exception e) {
            LOG.warn(Log.EXCEPTION, e);
        }
    }
    return results;
}
Also used : ManagedAttribute(org.eclipse.jetty.util.annotation.ManagedAttribute) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) AttributeNotFoundException(javax.management.AttributeNotFoundException) ReflectionException(javax.management.ReflectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException)

Aggregations

Attribute (javax.management.Attribute)157 ObjectName (javax.management.ObjectName)94 MBeanServer (javax.management.MBeanServer)56 AttributeList (javax.management.AttributeList)46 Test (org.junit.Test)38 ReflectionException (javax.management.ReflectionException)29 MBeanException (javax.management.MBeanException)25 HashMap (java.util.HashMap)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)22 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)21 AttributeNotFoundException (javax.management.AttributeNotFoundException)20 MBeanServerConnection (javax.management.MBeanServerConnection)15 MBeanInfo (javax.management.MBeanInfo)14 JMXConnector (javax.management.remote.JMXConnector)13 RuntimeOperationsException (javax.management.RuntimeOperationsException)12 List (java.util.List)10 BacklogTracerEventMessage (org.apache.camel.api.management.mbean.BacklogTracerEventMessage)10 IOException (java.io.IOException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ArrayList (java.util.ArrayList)9