org.springframework.jmx.export.MBeanExporter Java Examples

The following examples show how to use org.springframework.jmx.export.MBeanExporter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringMBeanExporterBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    // 创造 MBeanServer 对象
    MBeanServer mBeanServerFromCreate = MBeanServerFactory.createMBeanServer();
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    // 注册 SpringMBeanExporterBootstrap
    context.register(SpringMBeanExporterBootstrap.class);
    // 启动应用上下文
    context.refresh();
    // 获取 "mBeanExporter" Bean
    MBeanExporter mBeanExporter = context.getBean("mBeanExporter", MBeanExporter.class);
    // 从 "mBeanExporter" Bean 获取 MBeanServer
    MBeanServer mBeanServerFromBean = mBeanExporter.getServer();
    // 比较 mBeanServerFromBean 是否与平台 MBeanServer 相同
    System.out.printf("来自于 MBeanExporter Bean 的 MBeanServer 是否相当于 ManagementFactory.getPlatformMBeanServer() : %b\n",
            mBeanServerFromBean == ManagementFactory.getPlatformMBeanServer());
    System.out.printf("来自于 MBeanExporter Bean 的 MBeanServer 是否相当于 ManagementFactory.createMBeanServer() : %b\n",
            mBeanServerFromBean == mBeanServerFromCreate);
    System.out.println("按任意键结束...");
    System.in.read();
    // 关闭应用上下文
    context.close();
}
 
Example #2
Source File: SpringMBeanServerBeanBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    // 注册当前 Class
    context.register(SpringMBeanServerBeanBootstrap.class);
    // 启动应用上下文
    context.refresh();
    // 获取名为 "mBeanExporter" Bean,来自于 mBeanExporter() 方法 @Bean 定义
    MBeanExporter mBeanExporter = context.getBean("mBeanExporter", MBeanExporter.class);
    // 获取名为 "mBeanServer" Bean,来自于 mBeanServer() 方法 @Bean 定义
    MBeanServer mBeanServer = context.getBean("mBeanServer", MBeanServer.class);
    // 从 "mBeanExporter" Bean 中获取来自于其afterPropertiesSet()方法创建 "mBeanServer" 对象
    MBeanServer mBeanServerFromMBeanExporter = mBeanExporter.getServer();
    System.out.printf("来自 mBeanExporter Bean 关联的 MBeanServer 实例是否等于平台 MBeanServer : %b \n",
            mBeanServerFromMBeanExporter == ManagementFactory.getPlatformMBeanServer()
    );

    System.out.printf("来自 mBeanExporter Bean 关联的 MBeanServer 实例是否等于 mBeanServer Bean : %b \n",
            mBeanServerFromMBeanExporter == mBeanServer
    );
    // 关闭应用上下文
    context.close();
}
 
Example #3
Source File: MBeanClientInterceptorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void onSetUp() throws Exception {
	target = new JmxTestBean();
	target.setAge(100);
	target.setName("Rob Harrop");

	MBeanExporter adapter = new MBeanExporter();
	Map<String, Object> beans = new HashMap<>();
	beans.put(OBJECT_NAME, target);
	adapter.setServer(getServer());
	adapter.setBeans(beans);
	adapter.setAssembler(new ProxyTestAssembler());
	start(adapter);
}
 
Example #4
Source File: AbstractMetadataAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithCglibProxy() throws Exception {
	IJmxTestBean tb = createJmxTestBean();
	ProxyFactory pf = new ProxyFactory();
	pf.setTarget(tb);
	pf.addAdvice(new NopInterceptor());
	Object proxy = pf.getProxy();

	MetadataMBeanInfoAssembler assembler = (MetadataMBeanInfoAssembler) getAssembler();

	MBeanExporter exporter = new MBeanExporter();
	exporter.setBeanFactory(getContext());
	exporter.setAssembler(assembler);

	String objectName = "spring:bean=test,proxy=true";

	Map<String, Object> beans = new HashMap<String, Object>();
	beans.put(objectName, proxy);
	exporter.setBeans(beans);
	start(exporter);

	MBeanInfo inf = getServer().getMBeanInfo(ObjectNameManager.getInstance(objectName));
	assertEquals("Incorrect number of operations", getExpectedOperationCount(), inf.getOperations().length);
	assertEquals("Incorrect number of attributes", getExpectedAttributeCount(), inf.getAttributes().length);

	assertTrue("Not included in autodetection", assembler.includeBean(proxy.getClass(), "some bean name"));
}
 
Example #5
Source File: MBeanClientInterceptorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void onSetUp() throws Exception {
	target = new JmxTestBean();
	target.setAge(100);
	target.setName("Rob Harrop");

	MBeanExporter adapter = new MBeanExporter();
	Map<String, Object> beans = new HashMap<String, Object>();
	beans.put(OBJECT_NAME, target);
	adapter.setServer(getServer());
	adapter.setBeans(beans);
	adapter.setAssembler(new ProxyTestAssembler());
	start(adapter);
}
 
Example #6
Source File: MBeanConfiguration.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Bean
@Lazy(false)
public MBeanExporter mBeanExporter() {
    MBeanExporter exporter = new MBeanExporter();
    exporter.setAutodetect(true);
    exporter.setNamingStrategy(namingStrategy());
    exporter.setAssembler(infoAssembler());
    exporter.setEnsureUniqueRuntimeObjectNames(false);
    return exporter;
}
 
Example #7
Source File: ProcessStepsConfiguration.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
@Inject
@Bean
public MBeanExporter jmxExporter(Metrics metrics, DataSource dataSource) {
    MBeanExporter mBeanExporter = new MBeanExporter();
    Map<String, Object> beans = new HashMap<>();
    beans.put(METRICS_BEAN, metrics);
    if (dataSource instanceof DelegatingDataSource) {
        dataSource = ((DelegatingDataSource) dataSource).getTargetDataSource();
    }
    beans.put(DATASOURCE_BEAN, dataSource);
    mBeanExporter.setBeans(beans);
    return mBeanExporter;
}
 
Example #8
Source File: DynamicMBeanExporter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Instantiates a new dynamic MBean exporter.
 */
public DynamicMBeanExporter() 
{ 
    // For consistency, try to continue to use the last MBeanServer used in the same thread 
    MBeanServer server = threadServer.get(); 
    if (server != null) 
    { 
        setServer(server); 
    } 

    // Make replace existing the default registration behavior
    setRegistrationPolicy(RegistrationPolicy.IGNORE_EXISTING);
    setAutodetectMode(MBeanExporter.AUTODETECT_NONE);
}
 
Example #9
Source File: SpringMBeanExporterBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
@Bean
public MBeanExporter mBeanExporter(Calculator calculator) {
    MBeanExporter exporter = new MBeanExporter();
    Map<String, Object> beans = new HashMap<>();
    beans.put("production.ready.jmx.spring:name=Calculator", calculator);
    exporter.setBeans(beans);
    return exporter;
}
 
Example #10
Source File: ServerJmxConfig.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean
public MBeanExporter mbeanExporter(final MBeanExample mBeanExample) {
	final Map<String, Object> beans = new HashMap<>();
	beans.put("beans:name=MBeanExample", mBeanExample);

	final MBeanExporter exporter = new MBeanExporter();
	exporter.setBeans(beans);
	return exporter;
}
 
Example #11
Source File: AbstractMetadataAssemblerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testWithCglibProxy() throws Exception {
	IJmxTestBean tb = createJmxTestBean();
	ProxyFactory pf = new ProxyFactory();
	pf.setTarget(tb);
	pf.addAdvice(new NopInterceptor());
	Object proxy = pf.getProxy();

	MetadataMBeanInfoAssembler assembler = (MetadataMBeanInfoAssembler) getAssembler();

	MBeanExporter exporter = new MBeanExporter();
	exporter.setBeanFactory(getContext());
	exporter.setAssembler(assembler);

	String objectName = "spring:bean=test,proxy=true";

	Map<String, Object> beans = new HashMap<>();
	beans.put(objectName, proxy);
	exporter.setBeans(beans);
	start(exporter);

	MBeanInfo inf = getServer().getMBeanInfo(ObjectNameManager.getInstance(objectName));
	assertEquals("Incorrect number of operations", getExpectedOperationCount(), inf.getOperations().length);
	assertEquals("Incorrect number of attributes", getExpectedAttributeCount(), inf.getAttributes().length);

	assertTrue("Not included in autodetection", assembler.includeBean(proxy.getClass(), "some bean name"));
}
 
Example #12
Source File: MBeanClientInterceptorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void onSetUp() throws Exception {
	target = new JmxTestBean();
	target.setAge(100);
	target.setName("Rob Harrop");

	MBeanExporter adapter = new MBeanExporter();
	Map<String, Object> beans = new HashMap<>();
	beans.put(OBJECT_NAME, target);
	adapter.setServer(getServer());
	adapter.setBeans(beans);
	adapter.setAssembler(new ProxyTestAssembler());
	start(adapter);
}
 
Example #13
Source File: AbstractMetadataAssemblerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testWithCglibProxy() throws Exception {
	IJmxTestBean tb = createJmxTestBean();
	ProxyFactory pf = new ProxyFactory();
	pf.setTarget(tb);
	pf.addAdvice(new NopInterceptor());
	Object proxy = pf.getProxy();

	MetadataMBeanInfoAssembler assembler = (MetadataMBeanInfoAssembler) getAssembler();

	MBeanExporter exporter = new MBeanExporter();
	exporter.setBeanFactory(getContext());
	exporter.setAssembler(assembler);

	String objectName = "spring:bean=test,proxy=true";

	Map<String, Object> beans = new HashMap<>();
	beans.put(objectName, proxy);
	exporter.setBeans(beans);
	start(exporter);

	MBeanInfo inf = getServer().getMBeanInfo(ObjectNameManager.getInstance(objectName));
	assertEquals("Incorrect number of operations", getExpectedOperationCount(), inf.getOperations().length);
	assertEquals("Incorrect number of attributes", getExpectedAttributeCount(), inf.getAttributes().length);

	assertTrue("Not included in autodetection", assembler.includeBean(proxy.getClass(), "some bean name"));
}
 
Example #14
Source File: SpringMBeanServerBeanBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 4 votes vote down vote up
@Bean
public MBeanExporter mBeanExporter() {
    MBeanExporter exporter = new MBeanExporter();
    return exporter;
}
 
Example #15
Source File: AbstractMBeanServerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Start the specified {@link MBeanExporter}.
 */
protected void start(MBeanExporter exporter) {
	exporter.afterPropertiesSet();
	exporter.afterSingletonsInstantiated();
}
 
Example #16
Source File: MgmtConfig.java    From secrets-proxy with Apache License 2.0 4 votes vote down vote up
/** Exports actuator metrics to JMX. */
@Bean
@ExportMetricWriter
public MetricWriter metricWriter(MBeanExporter exporter) {
  return new JmxMetricWriter(exporter);
}
 
Example #17
Source File: AbstractMBeanServerTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Start the specified {@link MBeanExporter}.
 */
protected void start(MBeanExporter exporter) {
	exporter.afterPropertiesSet();
	exporter.afterSingletonsInstantiated();
}
 
Example #18
Source File: AbstractMBeanServerTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Start the specified {@link MBeanExporter}.
 */
protected void start(MBeanExporter exporter) {
	exporter.afterPropertiesSet();
	exporter.afterSingletonsInstantiated();
}
 
Example #19
Source File: InfinispanJmxConfiguration.java    From infinispan-spring-boot with Apache License 2.0 4 votes vote down vote up
InfinispanJmxConfiguration(ObjectProvider<MBeanExporter> mBeanExporter) {
   this.mBeanExporter = mBeanExporter;
}
 
Example #20
Source File: JMXControl.java    From cougar with Apache License 2.0 4 votes vote down vote up
public JMXControl(MBeanExporter exporter) {
	this.exporter = exporter;
}