Search in sources :

Example 51 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project druid by alibaba.

the class JMXUtils method register.

public static ObjectName register(String name, Object mbean) {
    try {
        ObjectName objectName = new ObjectName(name);
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        try {
            mbeanServer.registerMBean(mbean, objectName);
        } catch (InstanceAlreadyExistsException ex) {
            mbeanServer.unregisterMBean(objectName);
            mbeanServer.registerMBean(mbean, objectName);
        }
        return objectName;
    } catch (JMException e) {
        throw new IllegalArgumentException(name, e);
    }
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) JMException(javax.management.JMException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 52 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project ddf by codice.

the class KeystoreEditor method registerMbean.

private void registerMbean() {
    ObjectName objectName = null;
    MBeanServer mBeanServer = null;
    try {
        objectName = new ObjectName(KeystoreEditor.class.getName() + ":service=keystore");
        mBeanServer = ManagementFactory.getPlatformMBeanServer();
    } catch (MalformedObjectNameException e) {
        LOGGER.info("Unable to create Keystore Editor MBean.", e);
    }
    if (mBeanServer != null) {
        try {
            try {
                mBeanServer.registerMBean(this, objectName);
                LOGGER.debug("Registered Keystore Editor MBean under object name: {}", objectName);
            } catch (InstanceAlreadyExistsException e) {
                // Try to remove and re-register
                mBeanServer.unregisterMBean(objectName);
                mBeanServer.registerMBean(this, objectName);
                LOGGER.debug("Re-registered Keystore Editor MBean");
            }
        } catch (Exception e) {
            LOGGER.info("Could not register MBean [{}].", objectName, e);
        }
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) KeyManagementException(java.security.KeyManagementException) MalformedObjectNameException(javax.management.MalformedObjectNameException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CertificateEncodingException(java.security.cert.CertificateEncodingException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NoSuchProviderException(java.security.NoSuchProviderException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 53 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project ddf by codice.

the class LoggingService method init.

public void init() throws MBeanRegistrationException, MalformedObjectNameException, InstanceAlreadyExistsException, InstanceNotFoundException, NotCompliantMBeanException {
    try {
        if (logEvents == null) {
            logEvents = EvictingQueue.create(DEFAULT_LOG_EVENTS_LIMIT);
        }
        objectName = new ObjectName(MBEAN_OBJECT_NAME);
        mBeanServer.registerMBean(this, objectName);
        LOGGER.debug("Registered [{}] MBean under object name: [{}].", CLASS_NAME, objectName);
    } catch (InstanceAlreadyExistsException e) {
        LOGGER.debug("[{}] already registered as an MBean. Re-registering.", CLASS_NAME);
        mBeanServer.unregisterMBean(objectName);
        mBeanServer.registerMBean(this, objectName);
        LOGGER.debug("Successfully re-registered [{}] as an MBean.", CLASS_NAME);
    }
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectName(javax.management.ObjectName)

Example 54 with InstanceAlreadyExistsException

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

the class JMXMPConnectorStarter method startJMXMPConnectorServer.

private JMXConnectorServer startJMXMPConnectorServer(final int port) throws MalformedURLException, IOException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
    final Map<String, Object> env = new HashMap<String, Object>();
    env.put("jmx.remote.protocol.provider.pkgs", "com.sun.jmx.remote.protocol");
    env.put("jmx.remote.protocol.provider.class.loader", this.getClass().getClassLoader());
    env.put("jmx.remote.rmi.server.credential.types", new String[] { String[].class.getName(), String.class.getName() });
    JMXAuthenticator authenticator = getAccessController();
    if (authenticator != null) {
        env.put("jmx.remote.authenticator", authenticator);
    }
    final JMXServiceURL serviceURL = new JMXServiceURL("service:jmx:" + JMXMP + "://" + hostname() + ":" + port);
    JMXConnectorServer jmxmp = null;
    boolean startedOK = false;
    try {
        jmxmp = new JMXMPConnectorServer(serviceURL, env, mMBeanServer);
        if (mBootListener != null) {
            jmxmp.addNotificationListener(mBootListener, null, serviceURL.toString());
        }
        jmxmp.start();
        startedOK = true;
    } catch (final Exception e) {
        e.printStackTrace();
    } finally {
        // we do it this way so that the original exeption will be thrown out
        if (!startedOK) {
            try {
                if (jmxmp != null) {
                    jmxmp.stop();
                }
            } catch (Exception e) {
                ignore(e);
            }
        }
    }
    mJMXServiceURL = serviceURL;
    mConnectorServer = jmxmp;
    return mConnectorServer;
}
Also used : HashMap(java.util.HashMap) JMXMPConnectorServer(javax.management.remote.jmxmp.JMXMPConnectorServer) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MalformedURLException(java.net.MalformedURLException) MBeanRegistrationException(javax.management.MBeanRegistrationException) IOException(java.io.IOException)

Example 55 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project streamsx.kafka by IBMStreams.

the class CrKafkaConsumerGroupClient method setup.

/**
 * JMX setup of MBeans, Proxy, and Notification listener
 * This method is called every time a connection to the Job Control Plane is made.
 *
 * @throws IOException
 * @throws MBeanException
 * @throws ReflectionException
 * @throws NotCompliantMBeanException
 * @throws MBeanRegistrationException
 * @see com.ibm.streams.operator.control.Controllable#setup(javax.management.MBeanServerConnection, com.ibm.streams.operator.OperatorContext)
 */
@Override
public void setup(MBeanServerConnection jcp, OperatorContext context) throws InstanceNotFoundException, MBeanRegistrationException, NotCompliantMBeanException, ReflectionException, MBeanException, IOException {
    try {
        ConsistentRegionContext crContext = getCrContext();
        ObjectName groupMbeanName = createMBeanObjectName("consumergroup");
        this.crGroupCoordinatorMXBeanName = groupMbeanName.getCanonicalName();
        // Try to register the MBean for checkpoint coordination in JCP. One of the operators in the consumer group wins.
        trace.log(DEBUG_LEVEL, "Trying to register MBean in JCP: " + crGroupCoordinatorMXBeanName);
        if (jcp.isRegistered(groupMbeanName)) {
            trace.log(DEBUG_LEVEL, crGroupCoordinatorMXBeanName + " already registered");
        } else {
            try {
                // Constructor signature: (String groupId, Integer consistentRegionIndex, String traceLevel)
                jcp.createMBean(CrConsumerGroupCoordinator.class.getName(), groupMbeanName, new Object[] { getGroupId(), new Integer(crContext.getIndex()), DEBUG_LEVEL.toString() }, new String[] { "java.lang.String", "java.lang.Integer", "java.lang.String" });
                trace.log(DEBUG_LEVEL, "MBean registered: " + crGroupCoordinatorMXBeanName);
            } catch (InstanceAlreadyExistsException e) {
                // another operator managed to create it first. that is ok, just use that one.
                trace.log(DEBUG_LEVEL, MsgFormatter.format("another operator just created {0}: {1}", crGroupCoordinatorMXBeanName, e.getMessage()));
            }
        }
        try {
            jcp.removeNotificationListener(groupMbeanName, this);
        } catch (ListenerNotFoundException | InstanceNotFoundException e) {
            trace.log(DEBUG_LEVEL, "removeNotificationListener failed: " + e.getLocalizedMessage());
        }
        trace.log(DEBUG_LEVEL, "adding client as notification listener to " + crGroupCoordinatorMXBeanName);
        jcp.addNotificationListener(groupMbeanName, this, /*filter=*/
        null, /*handback=*/
        null);
        trace.log(DEBUG_LEVEL, "creating Proxies ...");
        crMxBean = JMX.newMXBeanProxy(jcp, getCrContext().getConsistentRegionMXBeanName(), ConsistentRegionMXBean.class);
        crGroupCoordinatorMxBean = JMX.newMXBeanProxy(jcp, groupMbeanName, CrConsumerGroupCoordinatorMXBean.class, /*notificationEmitter=*/
        true);
        trace.log(DEBUG_LEVEL, "MBean Proxy get test: group-ID = " + crGroupCoordinatorMxBean.getGroupId() + "; CR index = " + crGroupCoordinatorMxBean.getConsistentRegionIndex());
        crGroupCoordinatorMxBean.registerConsumerOperator(getOperatorContext().getName());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        jmxSetupLatch.countDown();
    }
}
Also used : ConsistentRegionContext(com.ibm.streams.operator.state.ConsistentRegionContext) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ListenerNotFoundException(javax.management.ListenerNotFoundException) ConsistentRegionMXBean(com.ibm.streams.operator.control.ConsistentRegionMXBean) SerializationException(org.apache.kafka.common.errors.SerializationException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ReflectionException(javax.management.ReflectionException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) KafkaOperatorResetFailedException(com.ibm.streamsx.kafka.KafkaOperatorResetFailedException) KafkaClientInitializationException(com.ibm.streamsx.kafka.KafkaClientInitializationException) KafkaOperatorRuntimeException(com.ibm.streamsx.kafka.KafkaOperatorRuntimeException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ListenerNotFoundException(javax.management.ListenerNotFoundException) KafkaOperatorNotRegisteredException(com.ibm.streamsx.kafka.KafkaOperatorNotRegisteredException) MBeanRegistrationException(javax.management.MBeanRegistrationException) UnsupportedControlPortActionException(com.ibm.streamsx.kafka.UnsupportedControlPortActionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) IOException(java.io.IOException) KafkaConfigurationException(com.ibm.streamsx.kafka.KafkaConfigurationException) MBeanException(javax.management.MBeanException) 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