Search in sources :

Example 16 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project jackrabbit-oak by apache.

the class HybridIndexTest method getOpenFileCount.

private static long getOpenFileCount() throws Exception {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = new ObjectName("java.lang:type=OperatingSystem");
    Long val = null;
    try {
        val = (Long) server.getAttribute(name, "OpenFileDescriptorCount");
    } catch (AttributeNotFoundException e) {
        // This attribute is only present if the os is unix i.e. when UnixOperatingSystemMXBean
        // is the mbean in use. If running on windows the test would be assumed to be true
        assumeNoException(e);
    }
    // dumpOpenFilePaths();
    return val;
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 17 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project com.revolsys.open by revolsys.

the class JmxService method getAttribute.

/**
 * Get the value for the attribute for an object on a server.
 *
 * @param mapWriter The writer to write the attributes to.
 * @param serverId The name of the server.
 * @param objectId The name of the object.
 * @param attributeId The name of the attribute.
 * @return The attribute value.
 */
public Object getAttribute(final String serverId, final String objectId, final String attributeId) {
    if (hasAttribute(serverId, objectId, attributeId)) {
        final MBeanServerConnection connection = getConnection(serverId);
        try {
            final ObjectName objectName = getObjectName(serverId, objectId);
            final Object object = connection.getAttribute(objectName, attributeId);
            return object;
        } catch (final InstanceNotFoundException e) {
            return "Unavailable";
        } catch (final MalformedObjectNameException e) {
            throw new IllegalArgumentException("MBean name not valid " + serverId + " " + objectId);
        } catch (final AttributeNotFoundException e) {
            throw new IllegalArgumentException("MBean attribute not found " + serverId + " " + objectId + "." + attributeId);
        } catch (final Throwable e) {
            return Exceptions.throwUncheckedException(e);
        }
    } else {
        throw new IllegalArgumentException("Attribute not configured " + serverId + " " + objectId + "." + attributeId);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 18 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project jmeter-plugins by undera.

the class JMXMonSampler method generateSamples.

public void generateSamples(JMXMonSampleGenerator collector) {
    try {
        if (hasFailed && !canRetry) {
            return;
        }
        // Construct the fully qualified name of the bean.
        ObjectName beanName = new ObjectName(objectName);
        MBeanServerConnection activeRemote = null;
        if (remote == null) {
            activeRemote = pool.getConnection(url.getStringValue(), connectionAttributes);
            if (activeRemote == null) {
                hasFailed = true;
            }
        } else {
            activeRemote = remote;
        }
        final double val;
        if (activeRemote != null) {
            Object o = activeRemote.getAttribute(beanName, attribute);
            if (o instanceof CompositeDataSupport) {
                if (key == null || "".equals(key)) {
                    log.error("Got composite object from JMX, but no key specified ");
                    return;
                }
                CompositeDataSupport cds = (CompositeDataSupport) o;
                // log.info("CDS: " + cds.toString());
                val = Double.parseDouble(cds.get(key).toString());
            } else {
                if (key != null && !key.equals("")) {
                    log.error("key specified, but didnt get composite object from JMX. Will continue anyway.");
                }
                val = Double.parseDouble(o.toString());
            }
        } else {
            val = 0;
        }
        if (sampleDeltaValue) {
            if (!Double.isNaN(oldValue)) {
                collector.generateSample(val - oldValue, metricName);
            }
            oldValue = val;
        } else {
            collector.generateSample(val, metricName);
        }
    } catch (MalformedURLException ex) {
        log.error(ex.getMessage());
    } catch (ConnectException ex) {
        log.warn("Connection lost", ex);
        pool.notifyConnectionDirty(url.getStringValue());
        if (sampleDeltaValue) {
            if (!Double.isNaN(oldValue)) {
                collector.generateSample(0 - oldValue, metricName);
            }
            oldValue = 0;
        } else {
            collector.generateSample(0, metricName);
        }
    } catch (IOException ex) {
        log.error(ex.getMessage());
    } catch (ReflectionException ex) {
        log.error(ex.getMessage());
    } catch (MalformedObjectNameException ex) {
        log.error(ex.getMessage());
    } catch (NullPointerException ex) {
        log.error(ex.getMessage());
    } catch (MBeanException ex) {
        log.error(ex.getMessage());
    } catch (AttributeNotFoundException ex) {
        log.error(ex.getMessage());
    } catch (InstanceNotFoundException ex) {
        log.error(ex.getMessage());
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedURLException(java.net.MalformedURLException) MalformedObjectNameException(javax.management.MalformedObjectNameException) AttributeNotFoundException(javax.management.AttributeNotFoundException) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) InstanceNotFoundException(javax.management.InstanceNotFoundException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) MBeanException(javax.management.MBeanException) MBeanServerConnection(javax.management.MBeanServerConnection) ConnectException(java.rmi.ConnectException)

Example 19 with AttributeNotFoundException

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

the class SimpleMBean method setAttribute.

public void setAttribute(Attribute attr) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    Method m;
    String mname = "set" + StringUtils.capitalize(attr.getName());
    m = findGetterSetter(getClass(), mname, attr.getValue().getClass());
    if (m == null)
        throw new AttributeNotFoundException(attr.getName());
    Object[] args = { attr.getValue() };
    try {
        m.invoke(this, args);
    } catch (IllegalArgumentException e) {
        throw new InvalidAttributeValueException("Faulty argument: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new ReflectionException(e, "Cannot access attribute " + e.getMessage());
    } catch (InvocationTargetException e) {
        throw new ReflectionException(e, "Cannot invoke attribute " + e.getMessage());
    }
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Method(java.lang.reflect.Method) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 20 with AttributeNotFoundException

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

the class SimpleMBean method setAttributes.

public AttributeList setAttributes(AttributeList arg0) {
    AttributeList result = new AttributeList();
    for (Iterator<Object> i = arg0.iterator(); i.hasNext(); ) {
        Attribute attr = (Attribute) i.next();
        // 
        try {
            setAttribute(attr);
            result.add(attr);
        } catch (AttributeNotFoundException e) {
            // TODO Auto-generated catch block
            LOG.error(e.getMessage(), e);
        } catch (InvalidAttributeValueException e) {
            // TODO Auto-generated catch block
            LOG.error(e.getMessage(), e);
        } catch (MBeanException e) {
            // TODO Auto-generated catch block
            LOG.error(e.getMessage(), e);
        } catch (ReflectionException e) {
            // TODO Auto-generated catch block
            LOG.error(e.getMessage(), e);
        }
    }
    return result;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

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