Search in sources :

Example 96 with JMException

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

the class JmxServiceUrlsResource method getJmxServiceUrl.

@GET
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
public ActionReportResult getJmxServiceUrl() {
    try {
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        JMXServiceURL[] urls = (JMXServiceURL[]) mBeanServer.getAttribute(getBootAMXMBeanObjectName(), "JMXServiceURLs");
        List<String> jmxUrls = new ArrayList<String>();
        for (JMXServiceURL url : urls) {
            jmxUrls.add(url.getURLPath());
        }
        RestActionReporter ar = new RestActionReporter();
        ar.setActionDescription("Get JMX Service URLs");
        ar.setSuccess();
        ar.getExtraProperties().put("jmxServiceUrls", jmxUrls);
        return new ActionReportResult(ar);
    } catch (final JMException e) {
        throw new RuntimeException(e);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ArrayList(java.util.ArrayList) JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 97 with JMException

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

the class RuntimeRootImpl method getJMXServiceURLs.

public String[] getJMXServiceURLs() {
    try {
        final AMXGlassfish amxg = AMXGlassfish.DEFAULT;
        final JMXServiceURL[] items = (JMXServiceURL[]) getMBeanServer().getAttribute(amxg.getBootAMXMBeanObjectName(), "JMXServiceURLs");
        final String[] urls = new String[items.length];
        for (int i = 0; i < items.length; ++i) {
            urls[i] = "" + items[i];
        }
        return urls;
    } catch (final JMException e) {
        throw new RuntimeException(e);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) AMXGlassfish(org.glassfish.external.amx.AMXGlassfish) JMException(javax.management.JMException)

Example 98 with JMException

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

the class NotificationListenerBase method cleanup.

/**
 *    Reset everything so that no listening is occuring and
 *    all lists are empty.
 */
public synchronized void cleanup() {
    try {
        if (mDelegateListener != null) {
            // it's crucial we listen for registration/unregistration events
            // so that any patterns are maintained.
            getConn().removeNotificationListener(JMXUtil.getMBeanServerDelegateObjectName(), mDelegateListener, null, null);
            mDelegateListener = null;
        }
        for (final ObjectName objectName : mListenees) {
            getConn().removeNotificationListener(objectName, this, mFilter, null);
        }
    } catch (JMException e) {
    } catch (IOException e) {
    }
    mListenees.clear();
}
Also used : JMException(javax.management.JMException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName)

Example 99 with JMException

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

the class BootAMX method bootAMX.

/**
 * We need to dynamically load the AMX module. HOW? we can't depend on the amx-impl module.
 *
 * For now though, assume that a well-known MBean is available through other means via the amx-impl module.
 * @return
 */
@Override
public synchronized ObjectName bootAMX() {
    if (mDomainRootObjectName == null) {
        getLoader();
        final ObjectName startupON = AMXStartupServiceMBean.OBJECT_NAME;
        if (!mMBeanServer.isRegistered(startupON)) {
            JMX_LOGGER.log(Level.FINEST, "Booter.bootAMX(): AMX MBean not yet available: {0}", startupON);
            throw new IllegalStateException("AMX MBean not yet available: " + startupON);
        }
        try {
            JMX_LOGGER.log(Level.FINEST, "Booter.bootAMX: invoking loadAMXMBeans() on {0}", startupON);
            mDomainRootObjectName = (ObjectName) mMBeanServer.invoke(startupON, "loadAMXMBeans", null, null);
            JMX_LOGGER.log(Level.FINEST, "Booter.bootAMX: domainRoot = {0}", mDomainRootObjectName);
        } catch (final JMException e) {
            JMX_LOGGER.log(Level.SEVERE, null, e);
            throw new RuntimeException(e);
        }
    }
    return mDomainRootObjectName;
}
Also used : JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Example 100 with JMException

use of javax.management.JMException in project metrics by dropwizard.

the class BufferPoolMetricSet method getMetrics.

@Override
public Map<String, Metric> getMetrics() {
    final Map<String, Metric> gauges = new HashMap<>();
    for (String pool : POOLS) {
        for (int i = 0; i < ATTRIBUTES.length; i++) {
            final String attribute = ATTRIBUTES[i];
            final String name = NAMES[i];
            try {
                final ObjectName on = new ObjectName("java.nio:type=BufferPool,name=" + pool);
                mBeanServer.getMBeanInfo(on);
                gauges.put(name(pool, name), new JmxAttributeGauge(mBeanServer, on, attribute));
            } catch (JMException ignored) {
                LOGGER.debug("Unable to load buffer pool MBeans, possibly running on Java 6");
            }
        }
    }
    return Collections.unmodifiableMap(gauges);
}
Also used : HashMap(java.util.HashMap) JMException(javax.management.JMException) Metric(com.codahale.metrics.Metric) ObjectName(javax.management.ObjectName)

Aggregations

JMException (javax.management.JMException)116 ObjectName (javax.management.ObjectName)66 MBeanServer (javax.management.MBeanServer)33 IOException (java.io.IOException)22 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)13 MBeanInfo (javax.management.MBeanInfo)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)9 SnmpStatusException (com.sun.management.snmp.SnmpStatusException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 StandardMBean (javax.management.StandardMBean)7 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)6 Date (java.util.Date)5 Attribute (javax.management.Attribute)5 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)5 Element (org.w3c.dom.Element)5 PostConstruct (javax.annotation.PostConstruct)4 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)4