Search in sources :

Example 31 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project common by zenlunatics.

the class Admin method writeTomcatState.

// --------------------------------------------------------------------------
private void writeTomcatState(Request request) throws IOException {
    DecimalFormat df = new DecimalFormat();
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        request.writer.h4("Memory");
        Table table = new Table(request.writer).addClass("table table-condensed table-striped").addStyle("width", "auto");
        Runtime runtime = Runtime.getRuntime();
        table.tr().td("max").td(df.format(runtime.maxMemory()));
        table.tr().td("total").td(df.format(runtime.totalMemory()));
        table.tr().td("free").td(df.format(runtime.freeMemory()));
        table.tr().td("used").td(df.format(runtime.totalMemory() - runtime.freeMemory()));
        table.close();
        request.writer.h4("Sessions");
        String context = request.getContext();
        if (context == null || context.length() == 0)
            context = "/";
        ObjectName objectName = new ObjectName("Catalina:type=Manager,context=" + context + ",host=localhost");
        table = new Table(request.writer).addClass("table table-condensed table-striped").addStyle("width", "auto");
        table.tr().td("count").td(mBeanServer.getAttribute(objectName, "sessionCounter").toString());
        table.tr().td("active").td(mBeanServer.getAttribute(objectName, "activeSessions").toString());
        table.tr().td("expired").td(mBeanServer.getAttribute(objectName, "expiredSessions").toString());
        table.close();
    } catch (MalformedObjectNameException | AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException e) {
        System.out.println(e);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Table(web.Table) JDBCTable(db.JDBCTable) DecimalFormat(java.text.DecimalFormat) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 32 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project component-runtime by Talend.

the class ComponentManagerTest method doCheckJmx.

private Date doCheckJmx(final MBeanServer mBeanServer) throws Exception {
    final ObjectName name = new ObjectName("org.talend.test:value=plugin1,type=plugin");
    assertTrue(mBeanServer.isRegistered(name));
    assertFalse(Boolean.class.cast(mBeanServer.getAttribute(name, "closed")));
    assertTrue(() -> {
        try {
            return Date.class.isInstance(mBeanServer.getAttribute(name, "created"));
        } catch (final MBeanException | AttributeNotFoundException | ReflectionException | InstanceNotFoundException e) {
            return false;
        }
    });
    // ensure date is stable until reloading
    assertEquals(mBeanServer.getAttribute(name, "created"), mBeanServer.getAttribute(name, "created"));
    return Date.class.cast(mBeanServer.getAttribute(name, "created"));
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 33 with AttributeNotFoundException

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

the class JSONBean method writeAttribute.

private static void writeAttribute(JsonWriter writer, MBeanServer mBeanServer, ObjectName oname, boolean description, Pattern[] pattern, MBeanAttributeInfo attr) throws IOException {
    if (!attr.isReadable()) {
        return;
    }
    String attName = attr.getName();
    if ("modelerType".equals(attName)) {
        return;
    }
    if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0 || attName.indexOf(" ") >= 0) {
        return;
    }
    if (pattern != null) {
        boolean matchFound = false;
        for (Pattern compile : pattern) {
            // check if we have any match
            if (compile.matcher(attName).find()) {
                matchFound = true;
                break;
            }
        }
        if (!matchFound) {
            return;
        }
    }
    String descriptionStr = description ? attr.getDescription() : null;
    Object value = null;
    try {
        value = mBeanServer.getAttribute(oname, attName);
    } catch (RuntimeMBeanException e) {
        // so no need to log them as errors all the time.
        if (e.getCause() instanceof UnsupportedOperationException) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Getting attribute " + attName + " of " + oname + " threw " + e);
            }
        } else {
            LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e);
        }
        return;
    } catch (RuntimeErrorException e) {
        // RuntimeErrorException happens when an unexpected failure occurs in getAttribute
        // for example https://issues.apache.org/jira/browse/DAEMON-120
        LOG.debug("getting attribute " + attName + " of " + oname + " threw an exception", e);
        return;
    } catch (AttributeNotFoundException e) {
        // the attribute.
        return;
    } catch (MBeanException e) {
        // The code inside the attribute getter threw an exception so log it, and
        // skip outputting the attribute
        LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e);
        return;
    } catch (RuntimeException e) {
        // For some reason even with an MBeanException available to them Runtime exceptions
        // can still find their way through, so treat them the same as MBeanException
        LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e);
        return;
    } catch (ReflectionException e) {
        // This happens when the code inside the JMX bean (setter?? from the java docs)
        // threw an exception, so log it and skip outputting the attribute
        LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e);
        return;
    } catch (InstanceNotFoundException e) {
        // happens just don't output the attribute.
        return;
    }
    writeAttribute(writer, attName, descriptionStr, value);
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) Pattern(java.util.regex.Pattern) ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) RuntimeErrorException(javax.management.RuntimeErrorException) InstanceNotFoundException(javax.management.InstanceNotFoundException) RuntimeMBeanException(javax.management.RuntimeMBeanException) MBeanException(javax.management.MBeanException)

Example 34 with AttributeNotFoundException

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

the class JMXJsonServlet method listBeans.

// --------------------------------------------------------- Private Methods
private void listBeans(JsonGenerator jg, ObjectName qry, String attribute, HttpServletResponse response) throws IOException {
    LOG.debug("Listing beans for " + qry);
    Set<ObjectName> names = null;
    names = mBeanServer.queryNames(qry, null);
    jg.writeArrayFieldStart("beans");
    Iterator<ObjectName> it = names.iterator();
    while (it.hasNext()) {
        ObjectName oname = it.next();
        MBeanInfo minfo;
        String code = "";
        Object attributeinfo = null;
        try {
            minfo = mBeanServer.getMBeanInfo(oname);
            code = minfo.getClassName();
            String prs = "";
            try {
                if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) {
                    prs = "modelerType";
                    code = (String) mBeanServer.getAttribute(oname, prs);
                }
                if (attribute != null) {
                    prs = attribute;
                    attributeinfo = mBeanServer.getAttribute(oname, prs);
                }
            } catch (AttributeNotFoundException e) {
                // If the modelerType attribute was not found, the class name is used
                // instead.
                LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
            } catch (MBeanException e) {
                // The code inside the attribute getter threw an exception so log it,
                // and fall back on the class name
                LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
            } catch (RuntimeException e) {
                // For some reason even with an MBeanException available to them
                // Runtime exceptions can still find their way through, so treat them
                // the same as MBeanException
                LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
            } catch (ReflectionException e) {
                // This happens when the code inside the JMX bean (setter?? from the
                // java docs) threw an exception, so log it and fall back on the
                // class name
                LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
            }
        } catch (InstanceNotFoundException e) {
            // Ignored for some reason the bean was not found so don't output it
            continue;
        } catch (IntrospectionException e) {
            // This is an internal error, something odd happened with reflection so
            // log it and don't output the bean.
            LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e);
            continue;
        } catch (ReflectionException e) {
            // This happens when the code inside the JMX bean threw an exception, so
            // log it and don't output the bean.
            LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e);
            continue;
        }
        jg.writeStartObject();
        jg.writeStringField("name", oname.toString());
        jg.writeStringField("modelerType", code);
        if ((attribute != null) && (attributeinfo == null)) {
            jg.writeStringField("result", "ERROR");
            jg.writeStringField("message", "No attribute with name " + attribute + " was found.");
            jg.writeEndObject();
            jg.writeEndArray();
            jg.close();
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        if (attribute != null) {
            writeAttribute(jg, attribute, attributeinfo);
        } else {
            MBeanAttributeInfo[] attrs = minfo.getAttributes();
            for (int i = 0; i < attrs.length; i++) {
                writeAttribute(jg, oname, attrs[i]);
            }
        }
        jg.writeEndObject();
    }
    jg.writeEndArray();
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) RuntimeMBeanException(javax.management.RuntimeMBeanException) MBeanException(javax.management.MBeanException)

Example 35 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException 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)

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