use of javax.management.JMException in project fabric8 by jboss-fuse.
the class ManagedApiFeature method initialize.
@Override
public void initialize(Server server, Bus bus) {
final ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
final InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
if (iMgr != null) {
try {
iMgr.register(mApi);
final ServerLifeCycleManager slcMgr = bus.getExtension(ServerLifeCycleManager.class);
if (slcMgr != null) {
slcMgr.registerListener(mApi);
slcMgr.startServer(server);
}
// Register notification listener to propagate unregistration of endpoint MBeans
final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
if (mBeanServer == null) {
return;
}
NotificationListener listener = new NotificationListener() {
@Override
public void handleNotification(Notification notification, Object handback) {
MBeanServerNotification mbsNotification = (MBeanServerNotification) notification;
ObjectName objectName = mbsNotification.getMBeanName();
String type = mbsNotification.getType();
try {
if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(type) && mApi.isCompanion(objectName)) {
if (slcMgr != null) {
slcMgr.unRegisterListener(mApi);
}
iMgr.unregister(mApi);
mBeanServer.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, this);
}
} catch (JMException e) {
LOG.log(Level.WARNING, "Unregistering ManagedApi failed.", e);
}
}
};
mBeanServer.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, mBeanServerNotificationFilter, null);
} catch (JMException jmex) {
jmex.printStackTrace();
LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
}
}
}
use of javax.management.JMException in project netvirt by opendaylight.
the class BgpAlarmBroadcaster method close.
@Override
@PreDestroy
public void close() {
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = objectName();
if (mbs.isRegistered(objectName)) {
mbs.unregisterMBean(objectName);
}
} catch (JMException e) {
LOG.error("Error unregistering MXBean", e);
}
}
use of javax.management.JMException in project derby by apache.
the class JMXManagementService method registerMBean.
/**
* Registers an MBean with the MBean server as a StandardMBean.
* Use of the StandardMBean allows the implementation details
* of Derby's mbeans to be hidden from JMX, thus only exposing
* the MBean's interface in org.apache.derby.mbeans.
*
* @param bean The MBean to wrap with a StandardMBean and register
* @param beanInterface The management interface for the MBean.
* @param keyProperties The String representation of the MBean's key properties,
* they will be added into the ObjectName with Derby's domain. Key
* type should be first with a short name for the bean, typically the
* class name without the package.
*/
public synchronized <T> Object registerMBean(final T bean, final Class<T> beanInterface, final String keyProperties) throws StandardException {
try {
final ObjectName beanName = new ObjectName(DERBY_JMX_DOMAIN + ":" + keyProperties + ",system=" + systemIdentifier);
final StandardMBean standardMBean = new StandardMBean(bean, beanInterface) {
/**
* Hide the implementation name from JMX clients
* by providing the interface name as the class
* name for the MBean. Allows the permissions
* in a policy file to be granted to the public
* MBean interfaces.
*/
protected String getClassName(MBeanInfo info) {
return beanInterface.getName();
}
};
// new StandardMBean(bean, beanInterface);
registeredMbeans.put(beanName, standardMBean);
if (mbeanServer != null)
jmxRegister(standardMBean, beanName);
return beanName;
} catch (JMException jme) {
throw StandardException.plainWrapException(jme);
}
}
use of javax.management.JMException in project fuse-karaf by jboss-fuse.
the class Activator method addingService.
@Override
public MBeanServer addingService(ServiceReference<MBeanServer> serviceReference) {
mbeanServerReference = serviceReference;
MBeanServer server = context.getService(serviceReference);
try {
installFilteringRuntimeBean(context, server);
} catch (JMException e) {
LOG.error(e.getMessage(), e);
}
return server;
}
use of javax.management.JMException in project spring-integration by spring-projects.
the class IntegrationMBeanExporter method registerBeanInstance.
/**
* Copy of private method in super class. Needed so we can avoid using the bean factory to extract the bean again,
* and risk it being a proxy (which it almost certainly is by now).
*
* @param bean the bean instance to register
* @param beanKey the bean name or human readable version if auto-generated
* @return the JMX object name of the MBean that was registered
*/
private ObjectName registerBeanInstance(Object bean, String beanKey) {
try {
ObjectName objectName = getObjectName(bean, beanKey);
Object mbeanToExpose = null;
if (isMBean(bean.getClass())) {
mbeanToExpose = bean;
} else {
DynamicMBean adaptedBean = adaptMBeanIfPossible(bean);
if (adaptedBean != null) {
mbeanToExpose = adaptedBean;
}
}
if (mbeanToExpose != null) {
if (logger.isInfoEnabled()) {
logger.info("Located MBean '" + beanKey + "': registering with JMX server as MBean [" + objectName + "]");
}
doRegister(mbeanToExpose, objectName);
} else {
if (logger.isInfoEnabled()) {
logger.info("Located managed bean '" + beanKey + "': registering with JMX server as MBean [" + objectName + "]");
}
ModelMBean mbean = createAndConfigureMBean(bean, beanKey);
doRegister(mbean, objectName);
// injectNotificationPublisherIfNecessary(bean, mbean, objectName);
}
return objectName;
} catch (JMException e) {
throw new UnableToRegisterMBeanException("Unable to register MBean [" + bean + "] with key '" + beanKey + "'", e);
}
}
Aggregations