List of usage examples for javax.management MBeanServer registerMBean
public ObjectInstance registerMBean(Object object, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException;
Registers a pre-existing object as an MBean with the MBean server.
From source file:org.openadaptor.spring.SpringAdaptor.java
private static void attemptToRegisterBean(Object bean, MBeanServer mbeanServer, String beanName) { if (!(bean instanceof MBeanServer)) { try {//from w ww . j a v a2s .c o m ObjectName name = new ObjectName("openadaptor:id=" + beanName); mbeanServer.registerMBean(bean, name); log.info("registered bean " + beanName); } catch (NotCompliantMBeanException e) { log.debug("bean " + beanName + " is not compliant : " + e.getMessage()); } catch (Exception e) { log.error("failed to register mbean " + beanName, e); } } }
From source file:com.bigdata.dastor.service.StorageProxy.java
public static void init() // BIGDATA: use init() { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try {/*from w w w . ja v a 2 s . c o m*/ mbs.registerMBean(new StorageProxy(), new ObjectName(MBEAN_OBJECT_NAME)); // BIGDATA } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.rhq.core.server.PersistenceUtility.java
/** * Enables the hibernate statistics mbean to provide access to information on the ejb3 persistence tier. * * @param entityManager an inject entity manager whose session factory will be tracked with these statistics * @param server the MBeanServer where the statistics MBean should be registered; if <code>null</code>, the * first one in the list returned by MBeanServerFactory.findMBeanServer(null) is used *///from ww w . j ava 2 s. com public static void enableHibernateStatistics(EntityManager entityManager, MBeanServer server) { try { SessionFactory sessionFactory = PersistenceUtility.getHibernateSession(entityManager) .getSessionFactory(); if (server == null) { ArrayList<MBeanServer> list = MBeanServerFactory.findMBeanServer(null); server = list.get(0); } ObjectName objectName = new ObjectName(HIBERNATE_STATISTICS_MBEAN_OBJECTNAME); StatisticsService mBean = new StatisticsService(); mBean.setSessionFactory(sessionFactory); server.registerMBean(mBean, objectName); sessionFactory.getStatistics().setStatisticsEnabled(true); } catch (InstanceAlreadyExistsException iaee) { LOG.info("Duplicate mbean registration ignored: " + HIBERNATE_STATISTICS_MBEAN_OBJECTNAME); } catch (Exception e) { LOG.warn("Couldn't register hibernate statistics mbean", e); } }
From source file:com.continuent.tungsten.common.jmx.JmxManager.java
/** * Server helper method to register a JMX MBean. MBeans are registered by a * combination of their MBean interface and the custom mbeanName argument. * The mbeanName permits multiple mBeans to be registered under the same * name./*from w w w. ja v a2 s .c o m*/ * * @param mbean The MBean instance that should be registered * @param mbeanClass The base class for the mbean * @throws ServerRuntimeException */ public static void registerMBean(Object mbean, Class<?> mbeanClass) { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { if (logger.isDebugEnabled()) logger.debug("Registering mbean: " + mbean.getClass()); ObjectName name = generateMBeanObjectName(mbeanClass); if (mbs.isRegistered(name)) mbs.unregisterMBean(name); mbs.registerMBean(mbean, name); } catch (Exception e) { throw new ServerRuntimeException( String.format("Unable to register mbean for class %s because '%s'", mbeanClass.getName(), e), e); } }
From source file:org.springframework.boot.context.SpringApplicationLifecycleRegistrar.java
@Override public void afterPropertiesSet() throws Exception { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); server.registerMBean(new SpringApplicationLifecycle(), objectName); if (logger.isDebugEnabled()) { logger.debug("Application lifecycle MBean registered with name '" + objectName + "'"); }//from w w w .ja va 2s .c om }
From source file:org.sonatype.nexus.apachehttpclient.PoolingClientConnectionManagerMBeanInstaller.java
/** * Registers the connection manager to JMX. *//*from w w w . ja v a2 s. co m*/ public synchronized void register(final PoolingHttpClientConnectionManager connectionManager) { if (jmxName == null) { try { jmxName = ObjectName.getInstance(JMX_DOMAIN, "name", PoolingHttpClientConnectionManager.class.getSimpleName()); final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); server.registerMBean(new PoolingClientConnectionManagerMBeanImpl(connectionManager), jmxName); } catch (final Exception e) { LOGGER.warn("Failed to register mbean {} due to {}:{}", jmxName, e.getClass(), e.getMessage()); jmxName = null; } } else { LOGGER.warn("Already registered mbean {}", jmxName); } }
From source file:org.sonatype.nexus.internal.httpclient.PoolingClientConnectionManagerMBeanInstaller.java
/** * Registers the connection manager to JMX. *//*from w w w .j a v a 2s. c o m*/ synchronized void register(final PoolingHttpClientConnectionManager connectionManager) { if (jmxName == null) { try { jmxName = ObjectName.getInstance(JMX_DOMAIN, "name", PoolingHttpClientConnectionManager.class.getSimpleName()); final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); server.registerMBean(new PoolingClientConnectionManagerMBeanImpl(connectionManager), jmxName); } catch (final Exception e) { LOGGER.warn("Failed to register mbean {} due to {}:{}", jmxName, e.getClass(), e.getMessage()); jmxName = null; } } else { LOGGER.warn("Already registered mbean {}", jmxName); } }
From source file:com.jagornet.dhcp.server.JagornetDhcpServer.java
/** * Register Log4J in JMX to allow dynamic configuration * of server logging using JMX client (e.g. jconsole). *///from www.j a v a 2s . co m @SuppressWarnings("unchecked") public static void registerLog4jInJmx() { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { // Create and Register the top level Log4J MBean HierarchyDynamicMBean hdm = new HierarchyDynamicMBean(); ObjectName mbo = new ObjectName("log4j:hiearchy=default"); mbs.registerMBean(hdm, mbo); // Add the root logger to the Hierarchy MBean org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger(); hdm.addLoggerMBean(rootLogger.getName()); // Get each logger from the Log4J Repository and add it to // the Hierarchy MBean created above. LoggerRepository r = LogManager.getLoggerRepository(); Enumeration<Logger> loggers = r.getCurrentLoggers(); if (loggers != null) { while (loggers.hasMoreElements()) { org.apache.log4j.Logger logger = (org.apache.log4j.Logger) loggers.nextElement(); hdm.addLoggerMBean(logger.getName()); } } } catch (Exception ex) { log.error("Failure registering Log4J in JMX: " + ex); } }
From source file:org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar.java
@Override public void afterPropertiesSet() throws Exception { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); server.registerMBean(new SpringApplicationAdmin(), this.objectName); if (logger.isDebugEnabled()) { logger.debug("Application Admin MBean registered with name '" + this.objectName + "'"); }//from w w w. jav a 2 s . c o m }
From source file:com.continuent.tungsten.common.jmx.JmxManager.java
/** * Server helper method to register a JMX MBean. MBeans are registered by a * combination of their MBean interface and the custom mbeanName argument. * The mbeanName permits multiple mBeans to be registered under the same * name.// w w w . j a va 2 s.co m * * @param mbean The MBean instance that should be registered * @param mbeanInterface The MBean interface this instance implements * @param mbeanName A custom name for this MBean * @throws ServerRuntimeException */ public static void registerMBean(Object mbean, Class<?> mbeanInterface, String mbeanName, boolean ignored) { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { if (logger.isDebugEnabled()) logger.debug("Registering mbean: " + mbean.getClass()); ObjectName name = generateMBeanObjectName(mbeanInterface.getName(), mbeanName); if (mbs.isRegistered(name)) mbs.unregisterMBean(name); mbs.registerMBean(mbean, name); } catch (Exception e) { throw new ServerRuntimeException("Unable to register mbean: class=" + mbean.getClass() + " interface=" + mbeanInterface + " name=" + mbeanName, e); } }