use of javax.management.StandardMBean in project atlasdb by palantir.
the class JMXUtils method registerMBeanWeakRefPlusCatchAndLogExceptions.
/**
* You must retain a reference to the returned {@link DynamicMBean} for as
* long as you wish this bean to be registered.
* <p>
* Some mbeans have references to some pretty big classes and we have no
* good way to de-register these beans because these objects don't have good
* life-cyle management.
* <p>
* This method will register your mbean with JMX but JMX will hold onto it
* weakly so the large object may be GC'ed as usual.
* <p>
* When there is no more reference to the underlying MBean from anywhere
* else it may be freed. If this happens, the next call to this objectName
* will fail with an {@link IllegalStateException}. When this happens, this
* objectName will also be unregisterd with
* {@link #unregisterMBeanCatchAndLogExceptions(String)}
* <p>
* Because of the weird JMX naming conventions, this method uses
* {@link StandardMBean} to proxy the bean as a {@link DynamicMBean} to get
* it through the framework
*
* @return the DynamicMBean whose lifecycle controls how long this bean is
* registered. null will be returned if this bean is not regsitered
* correctly
*/
public static <T> DynamicMBean registerMBeanWeakRefPlusCatchAndLogExceptions(final T mbean, final Class<T> clazz, final String objectName) {
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
try {
final DynamicMBean bean = new StandardMBean(mbean, clazz);
final DynamicMBean weakMBean = new WeakMBeanHandler(objectName, bean);
final ObjectName on = new ObjectName(objectName);
server.registerMBean(weakMBean, on);
return bean;
} catch (final Exception e) {
AssertUtils.assertAndLogWithException(log, false, "Failed to register mbean for name " + objectName, e);
return null;
}
}
use of javax.management.StandardMBean in project scheduling by ow2-proactive.
the class SchedulerJMXHelper method registerMBeans.
/**
* {@inheritDoc}
*/
@Override
public void registerMBeans(final MBeanServer mbs) {
// Register the Scheduler runtime MBean into the MBean server
try {
this.schedulerRuntimeMBean = new RuntimeDataMBeanImpl(dbManager);
final ObjectName name = new ObjectName(RUNTIMEDATA_MBEAN_NAME);
mbs.registerMBean(this.schedulerRuntimeMBean, name);
String dataBaseName = PASchedulerProperties.SCHEDULER_HOME.getValueAsString() + System.getProperty("file.separator") + PASchedulerProperties.SCHEDULER_RRD_DATABASE_NAME.getValueAsString();
FileUtils.forceMkdir(new File(dataBaseName).getParentFile());
if (PASchedulerProperties.SCHEDULER_DB_HIBERNATE_DROPDB.getValueAsBoolean()) {
// dropping the RDD data base
File rrdDataBase = new File(dataBaseName);
if (rrdDataBase.exists()) {
rrdDataBase.delete();
}
}
setDataStore(new RRDDataStore((StandardMBean) schedulerRuntimeMBean, dataBaseName, PASchedulerProperties.SCHEDULER_RRD_STEP.getValueAsInt(), Logger.getLogger(SchedulerJMXHelper.class)));
} catch (Exception e) {
LOGGER.error("Unable to register the RuntimeDataMBean", e);
}
// Register the MyAccount MBean into the MBean server
try {
final MyAccountMBeanImpl myAccountMBean = new MyAccountMBeanImpl(this.accountsManager);
final ObjectName name = new ObjectName(MYACCOUNT_MBEAN_NAME);
mbs.registerMBean(myAccountMBean, name);
} catch (Exception e) {
LOGGER.error("Unable to register the MyAccountMBean", e);
}
// Register the ViewAccount MBean into the MBean server
try {
final AllAccountsMBeanImpl viewAccountMBean = new AllAccountsMBeanImpl(this.accountsManager);
final ObjectName name = new ObjectName(ALLACCOUNTS_MBEAN_NAME);
mbs.registerMBean(viewAccountMBean, name);
} catch (Exception e) {
LOGGER.error("Unable to register the AllAccountsMBean", e);
}
// Register the Management MBean into the MBean server
try {
final ManagementMBeanImpl managementMBean = new ManagementMBeanImpl(this.accountsManager);
final ObjectName name = new ObjectName(MANAGEMENT_MBEAN_NAME);
mbs.registerMBean(managementMBean, name);
} catch (Exception e) {
LOGGER.error("Unable to register the ManagementMBean", e);
}
}
use of javax.management.StandardMBean in project spring-framework by spring-projects.
the class JmxUtilsTests method isMBeanWithStandardMBeanInherited.
@Test
void isMBeanWithStandardMBeanInherited() throws NotCompliantMBeanException {
StandardMBean mbean = new StandardMBeanImpl();
assertThat(JmxUtils.isMBean(mbean.getClass())).as("Standard MBean not detected correctly").isTrue();
}
use of javax.management.StandardMBean in project aries by apache.
the class JMXAgentImpl method registerMBeans.
/**
* @see org.apache.aries.jmx.agent.JMXAgent#registerMBeans(javax.management.MBeanServer)
*/
public synchronized void registerMBeans(final MBeanServer server) {
for (MBeanHandler mbeanHandler : mbeansHandlers.keySet()) {
if (mbeansHandlers.get(mbeanHandler) == Boolean.TRUE) {
String name = mbeanHandler.getName();
StandardMBean mbean = mbeanHandler.getMbean();
if (mbean != null) {
try {
logger.log(LogService.LOG_INFO, "Registering " + mbean.getMBeanInterface().getName() + " to MBeanServer " + server + " with name " + name);
server.registerMBean(mbean, new ObjectName(name));
} catch (InstanceAlreadyExistsException e) {
logger.log(LogService.LOG_ERROR, "MBean is already registered", e);
} catch (MBeanRegistrationException e) {
logger.log(LogService.LOG_ERROR, "Can't register MBean", e);
} catch (NotCompliantMBeanException e) {
logger.log(LogService.LOG_ERROR, "MBean is not compliant MBean", e);
} catch (MalformedObjectNameException e) {
logger.log(LogService.LOG_ERROR, "Try to register with no valid objectname", e);
} catch (NullPointerException e) {
logger.log(LogService.LOG_ERROR, "Name of objectname can't be null", e);
}
}
}
}
mbeanServers.put(server, Boolean.TRUE);
}
use of javax.management.StandardMBean in project aries by apache.
the class JMXAgentImpl method registerMBean.
/**
* @see org.apache.aries.jmx.agent.JMXAgent#registerMBean(org.apache.aries.jmx.MBeanHandler)
*/
public synchronized void registerMBean(final MBeanHandler mBeanHandler) {
for (MBeanServer server : mbeanServers.keySet()) {
String name = mBeanHandler.getName();
StandardMBean mbean = mBeanHandler.getMbean();
try {
logger.log(LogService.LOG_INFO, "Registering " + mbean.getMBeanInterface().getName() + " to MBeanServer " + server + " with name " + name);
server.registerMBean(mbean, new ObjectName(name));
} catch (InstanceAlreadyExistsException e) {
logger.log(LogService.LOG_ERROR, "MBean is already registered", e);
} catch (MBeanRegistrationException e) {
logger.log(LogService.LOG_ERROR, "Can't register MBean", e);
} catch (NotCompliantMBeanException e) {
logger.log(LogService.LOG_ERROR, "MBean is not compliant MBean, Stopping registration", e);
return;
} catch (MalformedObjectNameException e) {
logger.log(LogService.LOG_ERROR, "Try to register with no valid objectname, Stopping registration", e);
return;
} catch (NullPointerException e) {
logger.log(LogService.LOG_ERROR, "Name of objectname can't be null, Stopping registration", e);
return;
}
}
mbeansHandlers.put(mBeanHandler, Boolean.TRUE);
}
Aggregations