Search in sources :

Example 51 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project ddf by codice.

the class RrdJmxCollector method updateSamples.

/**
     * Configures a scheduled threaded executor to poll the metric's MBean periodically and add a
     * sample to the RRD file with the metric's current value.
     *
     * @throws CollectorException
     */
public void updateSamples() throws CollectorException {
    LOGGER.trace("ENTERING: updateSamples");
    if (executor == null) {
        executor = new ScheduledThreadPoolExecutor(1);
    }
    final Runnable updater = new Runnable() {

        public void run() {
            Object attr = null;
            try {
                attr = localMBeanServer.getAttribute(new ObjectName(mbeanName), mbeanAttributeName);
                LOGGER.trace("Sampling attribute {} from MBean {}", mbeanAttributeName, mbeanName);
                // Cast the metric's sampled value to the appropriate data type
                double val = 0;
                if (attr instanceof Integer) {
                    val = (Integer) attr;
                } else if (attr instanceof Long) {
                    val = ((Long) attr).intValue();
                } else if (attr instanceof Float) {
                    val = ((Float) attr);
                } else if (attr instanceof Double) {
                    val = ((Double) attr);
                } else {
                    throw new IllegalArgumentException("Unsupported type " + attr + " for attribute " + mbeanAttributeName);
                }
                LOGGER.trace("MBean attribute {} has value = {}", mbeanAttributeName, val);
                // sample in the RRD file
                if (sample == null) {
                    sample = rrdDb.createSample();
                }
                try {
                    long now = System.currentTimeMillis() / MILLIS_PER_SECOND;
                    long lastUpdateTime = rrdDb.getLastUpdateTime();
                    // Add metric's sample to RRD file with current timestamp
                    if (now - rrdDb.getLastUpdateTime() >= minimumUpdateTimeDelta) {
                        updateSample(now, val);
                    } else {
                        LOGGER.debug("Skipping sample update because time between updates is less than {} seconds", minimumUpdateTimeDelta);
                        sampleSkipCount++;
                        LOGGER.debug("now = {},   lastUpdateTime = {}   (sampleSkipCount = {})", now, lastUpdateTime, sampleSkipCount);
                    }
                } catch (IllegalArgumentException iae) {
                    LOGGER.info("Dropping sample of datasource {}", rrdDataSourceName, iae);
                }
            } catch (MalformedObjectNameException | AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException e) {
                LOGGER.info("Problems getting MBean attribute {}", mbeanAttributeName, e);
            } catch (IOException e) {
                LOGGER.info("Error updating RRD", e);
            }
        }
    };
    // Setup threaded scheduler to retrieve this MBean attribute's value
    // at the specified sample rate
    LOGGER.debug("Setup ScheduledThreadPoolExecutor for MBean {}", mbeanName);
    executor.scheduleWithFixedDelay(updater, 0, sampleRate, TimeUnit.SECONDS);
    LOGGER.trace("EXITING: updateSamples");
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) AttributeNotFoundException(javax.management.AttributeNotFoundException) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) InstanceNotFoundException(javax.management.InstanceNotFoundException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) MBeanException(javax.management.MBeanException)

Example 52 with AttributeNotFoundException

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

the class AbstractDynamicMBean method setAttributes.

/**
 * Sets the manageable attributes, as specified by the DynamicMBean interface.
 */
public AttributeList setAttributes(AttributeList attributes) {
    AttributeList list = new AttributeList();
    if (attributes != null) {
        for (int i = 0; i < attributes.size(); ++i) {
            Attribute attribute = (Attribute) attributes.get(i);
            try {
                setAttribute(attribute);
                list.add(attribute);
            } catch (AttributeNotFoundException ignored) {
            } catch (InvalidAttributeValueException ignored) {
            } catch (MBeanException ignored) {
            } catch (ReflectionException ignored) {
            }
        }
    }
    return list;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) RuntimeMBeanException(javax.management.RuntimeMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

Example 53 with AttributeNotFoundException

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

the class AbstractDynamicMBean method getAttributes.

/**
 * Returns the manageable attributes, as specified by the DynamicMBean interface.
 */
public AttributeList getAttributes(String[] attributes) {
    AttributeList list = new AttributeList();
    if (attributes != null) {
        for (int i = 0; i < attributes.length; ++i) {
            String attribute = attributes[i];
            try {
                Object result = getAttribute(attribute);
                list.add(new Attribute(attribute, result));
            } catch (AttributeNotFoundException ignored) {
            } catch (MBeanException ignored) {
            } catch (ReflectionException ignored) {
            }
        }
    }
    return list;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) RuntimeMBeanException(javax.management.RuntimeMBeanException) MBeanException(javax.management.MBeanException)

Example 54 with AttributeNotFoundException

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

the class AbstractDynamicMBean method getAttribute.

/**
 * Returns the value of the manageable attribute, as specified by the DynamicMBean interface.
 * @see #createMBeanAttributeInfo
 */
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    if (attribute == null)
        throw new AttributeNotFoundException("Attribute " + attribute + " not found");
    Object resource = null;
    MBeanInfo info = null;
    synchronized (this) {
        resource = getResourceOrThis();
        info = getMBeanInfo();
    }
    MBeanAttributeInfo[] attrs = info.getAttributes();
    if (attrs == null || attrs.length == 0)
        throw new AttributeNotFoundException("No attributes defined for this MBean");
    for (int i = 0; i < attrs.length; ++i) {
        MBeanAttributeInfo attr = attrs[i];
        if (attr == null)
            continue;
        if (attribute.equals(attr.getName())) {
            if (!attr.isReadable())
                throw new ReflectionException(new NoSuchMethodException("No getter defined for attribute: " + attribute));
            // Found, invoke via reflection
            String prefix = null;
            if (attr.isIs())
                prefix = "is";
            else
                prefix = "get";
            try {
                return invoke(resource, prefix + attr.getName(), new Class[0], new Object[0]);
            } catch (InvalidAttributeValueException x) {
                throw new ReflectionException(x);
            }
        }
    }
    throw new AttributeNotFoundException("Attribute " + attribute + " not found");
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 55 with AttributeNotFoundException

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

the class AMXTest method testGetInterfaceName.

public void testGetInterfaceName() throws IOException, JMException {
    final Set<ObjectName> all = getQueryMgr().queryAllObjectNameSet();
    final MBeanServerConnection conn = Util.getExtra(getDomainRoot()).getConnectionSource().getExistingMBeanServerConnection();
    final Set<ObjectName> failedSet = new HashSet<ObjectName>();
    for (final ObjectName objectName : all) {
        try {
            final String value = (String) conn.getAttribute(objectName, AMXAttributes.ATTR_INTERFACE_NAME);
            assert (value != null);
            value.toString();
        } catch (AttributeNotFoundException e) {
            warning("Can't get InterfaceName for: " + objectName);
            failedSet.add(objectName);
        }
    }
    if (failedSet.size() != 0) {
        warning("The following MBeans did not return the Attribute InterfaceName:\n" + CollectionUtil.toString(failedSet, "\n"));
        assert (false);
        throw new Error();
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) HashSet(java.util.HashSet)

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