Search in sources :

Example 96 with InstanceAlreadyExistsException

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

the class JMXActorMonitor method registerMBean.

private void registerMBean() {
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName mxbeanName = new ObjectName(name);
        if (mbs.isRegistered(mxbeanName)) {
            try {
                LOG.info("MBean named {} is already registered. Unregistering it.", name);
                mbs.unregisterMBean(mxbeanName);
            } catch (InstanceNotFoundException e) {
            }
        }
        mbs.registerMBean(this, mxbeanName);
        MonitoringServices.getInstance().addPerfNotificationListener(this, name);
        this.registered = true;
    } catch (InstanceAlreadyExistsException ex) {
        throw new RuntimeException(ex);
    } catch (MBeanRegistrationException ex) {
        ex.printStackTrace();
    } catch (NotCompliantMBeanException | MalformedObjectNameException ex) {
        throw new AssertionError(ex);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 97 with InstanceAlreadyExistsException

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

the class MonitoringServices method registerMBean.

private void registerMBean() {
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName mxbeanName = new ObjectName("co.paralleluniverse:name=MonitoringServices");
        mbs.registerMBean(this, mxbeanName);
    } 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);
    }
}
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)

Example 98 with InstanceAlreadyExistsException

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

the class JMXForkJoinPoolMonitor method registerMBean.

protected 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);
    }
}
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)

Example 99 with InstanceAlreadyExistsException

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

the class JMXFibersMonitor method registerMBean.

@SuppressWarnings({ "CallToPrintStackTrace", "CallToThreadDumpStack" })
protected 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)

Example 100 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project scylla-jmx by scylladb.

the class APIMBean method checkRegistration.

/**
 * Helper method to add/remove dynamically created MBeans from a server
 * instance.
 *
 * @param server
 *            The {@link MBeanServer} to check
 * @param all
 *            All {@link ObjectName}s that should be bound
 * @param predicate
 *            {@link QueryExp} predicate to filter relevant object names.
 * @param generator
 *            {@link Function} to create a new MBean instance for a given
 *            {@link ObjectName}
 * @return
 * @throws MalformedObjectNameException
 */
public static boolean checkRegistration(JmxMBeanServer server, Set<ObjectName> all, EnumSet<RegistrationMode> mode, final Predicate<ObjectName> predicate, Function<ObjectName, Object> generator) throws MalformedObjectNameException {
    Set<ObjectName> registered = queryNames(server, predicate);
    if (mode.contains(RegistrationMode.Remove)) {
        for (ObjectName name : registered) {
            if (!all.contains(name)) {
                try {
                    server.getMBeanServerInterceptor().unregisterMBean(name);
                } catch (MBeanRegistrationException | InstanceNotFoundException e) {
                }
            }
        }
    }
    int added = 0;
    if (mode.contains(RegistrationMode.Add)) {
        for (ObjectName name : all) {
            if (!registered.contains(name)) {
                try {
                    server.getMBeanServerInterceptor().registerMBean(generator.apply(name), name);
                    added++;
                } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
                }
            }
        }
    }
    return added > 0;
}
Also used : NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) 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