Search in sources :

Example 91 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project atlasdb by palantir.

the class JMXUtils method registerMBeanCatchAndLogExceptions.

/**
 * Simple method to register a bean with the server. The server used is the
 * one returned by {@code ManagementFactory.getPlatformMBeanServer()}.
 * <p>
 * This bean will remain registered until manually unregistered. If you want
 * life-cycle management, use
 * {@link #registerMBeanWeakRefPlusCatchAndLogExceptions(Object, Class, String)}
 */
public static void registerMBeanCatchAndLogExceptions(final Object mbean, final String objectName) {
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    try {
        final ObjectName on = new ObjectName(objectName);
        try {
            // throws exception if bean doesn't exist
            server.getMBeanInfo(on);
            server.unregisterMBean(on);
        } catch (final InstanceNotFoundException e) {
        // if the bean wasn't already there.
        }
        server.registerMBean(mbean, on);
    } catch (InstanceAlreadyExistsException e) {
        // The bean was registered concurrently; log an error, but don't fail tests
        log.error("Failed to register mbean for name {}", objectName, e);
    } catch (Exception e) {
        AssertUtils.assertAndLogWithException(log, false, "Failed to register mbean for name " + objectName, e);
    }
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 92 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project wicket by apache.

the class Initializer method init.

@Override
public void init(final org.apache.wicket.Application application) {
    try {
        String name = application.getName();
        String agentId = null;
        try {
            agentId = System.getProperty("wicket.mbean.server.agentid");
        } catch (SecurityException e) {
            // Ignore - we're not allowed to read this property.
            log.warn("not allowed to read property wicket.mbean.server.agentid due to security settings; ignoring");
        }
        if (agentId != null) {
            ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(agentId);
            if (!mbeanServers.isEmpty()) {
                // get first
                mbeanServer = mbeanServers.get(0);
            } else {
                log.error("unable to find mbean server with agent id " + agentId);
            }
        }
        if (mbeanServer == null) {
            String impl = null;
            try {
                impl = System.getProperty("wicket.mbean.server.class");
            } catch (SecurityException e) {
                // Ignore - we're not allowed to read this property.
                log.warn("not allowed to read property wicket.mbean.server.class due to security settings; ignoring");
            }
            if (impl != null) {
                ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null);
                if (!mbeanServers.isEmpty()) {
                    for (MBeanServer mbs : mbeanServers) {
                        if (mbs.getClass().getName().equals(impl)) {
                            mbeanServer = mbs;
                            break;
                        }
                    }
                }
                if (mbeanServer == null) {
                    log.error("unable to find mbean server of type '{}'", impl);
                }
            }
        }
        if (mbeanServer == null) {
            mbeanServer = ManagementFactory.getPlatformMBeanServer();
        // never null
        }
        log.info("registering Wicket mbeans with server '{}'", mbeanServer);
        // register top level application object, but first check whether
        // multiple instances of the same application (name) are running and
        // if so adjust the name
        String domain = "org.apache.wicket.app." + name;
        ObjectName appBeanName = new ObjectName(domain + ":type=Application");
        String tempDomain = domain;
        int i = 0;
        while (mbeanServer.isRegistered(appBeanName)) {
            tempDomain = name + "-" + i++;
            appBeanName = new ObjectName(tempDomain + ":type=Application");
        }
        domain = tempDomain;
        Application appBean = new Application(application);
        register(application, appBean, appBeanName);
        register(application, new ApplicationSettings(application), new ObjectName(domain + ":type=Application,name=ApplicationSettings"));
        register(application, new DebugSettings(application), new ObjectName(domain + ":type=Application,name=DebugSettings"));
        register(application, new MarkupSettings(application), new ObjectName(domain + ":type=Application,name=MarkupSettings"));
        register(application, new ResourceSettings(application), new ObjectName(domain + ":type=Application,name=ResourceSettings"));
        register(application, new PageSettings(application), new ObjectName(domain + ":type=Application,name=PageSettings"));
        register(application, new RequestCycleSettings(application), new ObjectName(domain + ":type=Application,name=RequestCycleSettings"));
        register(application, new SecuritySettings(application), new ObjectName(domain + ":type=Application,name=SecuritySettings"));
        register(application, new SessionSettings(application), new ObjectName(domain + ":type=Application,name=SessionSettings"));
        register(application, new StoreSettings(application), new ObjectName(domain + ":type=Application,name=StoreSettings"));
        RequestLogger sessionsBean = new RequestLogger(application);
        ObjectName sessionsBeanName = new ObjectName(domain + ":type=RequestLogger");
        register(application, sessionsBean, sessionsBeanName);
    } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
        throw new WicketRuntimeException(e);
    }
}
Also used : MarkupSettings(org.apache.wicket.jmx.wrapper.MarkupSettings) MalformedObjectNameException(javax.management.MalformedObjectNameException) RequestCycleSettings(org.apache.wicket.jmx.wrapper.RequestCycleSettings) PageSettings(org.apache.wicket.jmx.wrapper.PageSettings) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) SecuritySettings(org.apache.wicket.jmx.wrapper.SecuritySettings) SessionSettings(org.apache.wicket.jmx.wrapper.SessionSettings) ObjectName(javax.management.ObjectName) DebugSettings(org.apache.wicket.jmx.wrapper.DebugSettings) StoreSettings(org.apache.wicket.jmx.wrapper.StoreSettings) ApplicationSettings(org.apache.wicket.jmx.wrapper.ApplicationSettings) ResourceSettings(org.apache.wicket.jmx.wrapper.ResourceSettings) RequestLogger(org.apache.wicket.jmx.wrapper.RequestLogger) Application(org.apache.wicket.jmx.wrapper.Application) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer)

Example 93 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project herddb by diennea.

the class JMXUtils method registerTableSpaceManagerStatsMXBean.

public static void registerTableSpaceManagerStatsMXBean(String tableSpaceName, TableSpaceManagerStatsMXBean bean) {
    if (platformMBeanServer == null) {
        throw new HerdDBInternalException("PlatformMBeanServer not available", mBeanServerLookupError);
    }
    String safeTableSpaceName = safeName(tableSpaceName);
    try {
        ObjectName name = new ObjectName("herddb.server:type=TableSpace,Name=" + safeTableSpaceName);
        LOG.log(Level.FINE, "Publishing stats for table {0} at {1}", new Object[] { tableSpaceName, name });
        if (platformMBeanServer.isRegistered(name)) {
            try {
                platformMBeanServer.unregisterMBean(name);
            } catch (InstanceNotFoundException noProblem) {
            }
        }
        platformMBeanServer.registerMBean(bean, name);
    } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
        throw new HerdDBInternalException("Could not register MXBean " + e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) HerdDBInternalException(herddb.core.HerdDBInternalException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 94 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project wikidata-query-rdf by wikimedia.

the class MonitoredFilter method init.

/**
 * Register a Filter as an MBean.
 *
 * On successful registration, the {@link ObjectName} used for registration
 * is stored into an instance field so that the MBean can be released on
 * {@link Filter#destroy()}.
 */
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    String filterName = filterConfig.getFilterName();
    ObjectName name = null;
    try {
        name = new ObjectName(this.getClass().getName(), "filterName", filterName);
        MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
        platformMBeanServer.registerMBean(this, name);
        log.info("ThrottlingFilter MBean registered as {}.", name);
    } catch (MalformedObjectNameException e) {
        log.error("filter name {} is invalid as an MBean property.", filterName, e);
    } catch (InstanceAlreadyExistsException e) {
        log.error("MBean for {}} has already been registered.", filterName, e);
    } catch (NotCompliantMBeanException | MBeanRegistrationException e) {
        log.error("Could not register MBean for Filter {}.", filterName, e);
    }
    objectName = name;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 95 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project quasar by puniverse.

the class JMXActorsMonitor method registerMBean.

@SuppressWarnings({ "CallToPrintStackTrace", "CallToThreadDumpStack" })
private void registerMBean() {
    try {
        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        final ObjectName mxbeanName = new ObjectName(mbeanName);
        mbs.registerMBean(this, mxbeanName);
        this.registered = true;
    } catch (InstanceAlreadyExistsException ex) {
        throw new RuntimeException(ex);
    } catch (MBeanRegistrationException ex) {
        ex.printStackTrace();
    } catch (NotCompliantMBeanException ex) {
        throw new AssertionError(ex);
    } catch (MalformedObjectNameException ex) {
        throw new AssertionError(ex);
    }
    MonitoringServices.getInstance().addPerfNotificationListener(this, mbeanName);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)116 ObjectName (javax.management.ObjectName)87 MBeanRegistrationException (javax.management.MBeanRegistrationException)73 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)70 MalformedObjectNameException (javax.management.MalformedObjectNameException)64 MBeanServer (javax.management.MBeanServer)48 InstanceNotFoundException (javax.management.InstanceNotFoundException)37 IOException (java.io.IOException)13 ObjectInstance (javax.management.ObjectInstance)12 Test (org.junit.Test)12 StandardMBean (javax.management.StandardMBean)9 MBeanException (javax.management.MBeanException)7 ReflectionException (javax.management.ReflectionException)7 HashMap (java.util.HashMap)5 JMRuntimeException (javax.management.JMRuntimeException)4 RuntimeOperationsException (javax.management.RuntimeOperationsException)4 MalformedURLException (java.net.MalformedURLException)3 AttributeNotFoundException (javax.management.AttributeNotFoundException)3 DynamicMBean (javax.management.DynamicMBean)3 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3