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);
}
}
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);
}
}
}
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);
}
}
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;
}
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();
}
}
Aggregations