@Test public void withLocateExistingAndFallbackToPlatformServer() { MBeanServerFactoryBean bean = new MBeanServerFactoryBean(); bean.setLocateExistingServerIfPossible(true); bean.afterPropertiesSet(); try { assertSame(ManagementFactory.getPlatformMBeanServer(), bean.getObject()); } finally { bean.destroy(); } }
/** * Creates the {@code MBeanServer} instance. */ @Override public void afterPropertiesSet() throws MBeanServerNotFoundException { // Try to locate existing MBeanServer, if desired. if (this.locateExistingServerIfPossible || this.agentId != null) { try { this.server = locateMBeanServer(this.agentId); } catch (MBeanServerNotFoundException ex) { // If agentId was specified, we were only supposed to locate that // specific MBeanServer; so let's bail if we can't find it. if (this.agentId != null) { throw ex; } logger.debug("No existing MBeanServer found - creating new one"); } } // Create a new MBeanServer and register it, if desired. if (this.server == null) { this.server = createMBeanServer(this.defaultDomain, this.registerWithFactory); this.newlyRegistered = this.registerWithFactory; } }
@Bean public MBeanServerFactoryBean server() throws Exception { return new MBeanServerFactoryBean(); } }
@BeforeClass public static void setupClass() { factoryBean = new MBeanServerFactoryBean(); factoryBean.afterPropertiesSet(); server = factoryBean.getObject(); }
@Bean public MBeanServerFactoryBean fb() { MBeanServerFactoryBean fb = new MBeanServerFactoryBean(); fb.setLocateExistingServerIfPossible(true); return fb; }
@BeforeClass public static void setupClass() { serverFactoryBean = new MBeanServerFactoryBean(); serverFactoryBean.afterPropertiesSet(); }
@Bean public MBeanServerFactoryBean mbeanServerFactoryBean() { log.debug("Creating mbean server factory bean"); MBeanServerFactoryBean bean = new MBeanServerFactoryBean(); bean.setRegisterWithFactory(true); return bean; }
@Before public void setup() throws Exception { this.server = serverFactoryBean.getObject(); MBeanExporter exporter = new MBeanExporter(); exporter.setServer(this.server); exporter.afterPropertiesSet(); this.objectName = ObjectNameManager.getInstance("si:name=numberHolder"); exporter.registerManagedResource(this.numberHolder, this.objectName); }
@AfterClass public static void tearDown() { factoryBean.destroy(); }
@Bean public MBeanServerFactoryBean server() throws Exception { return new MBeanServerFactoryBean(); }
@Bean public MBeanServerFactoryBean fb() { MBeanServerFactoryBean fb = new MBeanServerFactoryBean(); fb.setLocateExistingServerIfPossible(true); return fb; }
public void init() throws Exception { log.debug("Registering Tomcat JDBC datasource with JMX"); DataSource ds = dataSource(); if (!ds.isJmxEnabled()) { log.debug("JMX disabled on Tomcat JDBC datasource"); return; } MBeanServer mb = server.getObject(); ds.createPool(); ds.preRegister(mb, new ObjectName("org.apache.tomcat:context=HibernateDataSource")); }
@AfterClass public static void tearDown() { serverFactoryBean.destroy(); }
@Test public void withEmptyAgentIdAndFallbackToPlatformServer() { MBeanServerFactoryBean bean = new MBeanServerFactoryBean(); bean.setAgentId(""); bean.afterPropertiesSet(); try { assertSame(ManagementFactory.getPlatformMBeanServer(), bean.getObject()); } finally { bean.destroy(); } }
@Bean public MBeanServerFactoryBean server() throws Exception { return new MBeanServerFactoryBean(); }
/** * Creates the {@code MBeanServer} instance. */ @Override public void afterPropertiesSet() throws MBeanServerNotFoundException { // Try to locate existing MBeanServer, if desired. if (this.locateExistingServerIfPossible || this.agentId != null) { try { this.server = locateMBeanServer(this.agentId); } catch (MBeanServerNotFoundException ex) { // If agentId was specified, we were only supposed to locate that // specific MBeanServer; so let's bail if we can't find it. if (this.agentId != null) { throw ex; } logger.debug("No existing MBeanServer found - creating new one"); } } // Create a new MBeanServer and register it, if desired. if (this.server == null) { this.server = createMBeanServer(this.defaultDomain, this.registerWithFactory); this.newlyRegistered = this.registerWithFactory; } }
@AfterClass public static void tearDown() { factoryBean.destroy(); }
@Test public void getObject() throws Exception { MBeanServerFactoryBean bean = new MBeanServerFactoryBean(); bean.afterPropertiesSet(); try { MBeanServer server = bean.getObject(); assertNotNull("The MBeanServer should not be null", server); } finally { bean.destroy(); } }
@Bean public MBeanServerFactoryBean server() throws Exception { return new MBeanServerFactoryBean(); }
/** * Creates the {@code MBeanServer} instance. */ @Override public void afterPropertiesSet() throws MBeanServerNotFoundException { // Try to locate existing MBeanServer, if desired. if (this.locateExistingServerIfPossible || this.agentId != null) { try { this.server = locateMBeanServer(this.agentId); } catch (MBeanServerNotFoundException ex) { // If agentId was specified, we were only supposed to locate that // specific MBeanServer; so let's bail if we can't find it. if (this.agentId != null) { throw ex; } logger.debug("No existing MBeanServer found - creating new one"); } } // Create a new MBeanServer and register it, if desired. if (this.server == null) { this.server = createMBeanServer(this.defaultDomain, this.registerWithFactory); this.newlyRegistered = this.registerWithFactory; } }