Java Code Examples for org.springframework.jmx.JmxTestBean#setName()

The following examples show how to use org.springframework.jmx.JmxTestBean#setName() . 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: MBeanExporterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testExportJdkProxy() throws Exception {
	JmxTestBean bean = new JmxTestBean();
	bean.setName("Rob Harrop");

	ProxyFactory factory = new ProxyFactory();
	factory.setTarget(bean);
	factory.addAdvice(new NopInterceptor());
	factory.setInterfaces(IJmxTestBean.class);

	IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
	String name = "bean:mmm=whatever";

	Map<String, Object> beans = new HashMap<>();
	beans.put(name, proxy);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.registerBeans();

	ObjectName oname = ObjectName.getInstance(name);
	Object nameValue = server.getAttribute(oname, "Name");
	assertEquals("Rob Harrop", nameValue);
}
 
Example 2
Source File: MBeanExporterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testExportJdkProxy() throws Exception {
	JmxTestBean bean = new JmxTestBean();
	bean.setName("Rob Harrop");

	ProxyFactory factory = new ProxyFactory();
	factory.setTarget(bean);
	factory.addAdvice(new NopInterceptor());
	factory.setInterfaces(IJmxTestBean.class);

	IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
	String name = "bean:mmm=whatever";

	Map<String, Object> beans = new HashMap<>();
	beans.put(name, proxy);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.registerBeans();

	ObjectName oname = ObjectName.getInstance(name);
	Object nameValue = server.getAttribute(oname, "Name");
	assertEquals("Rob Harrop", nameValue);
}
 
Example 3
Source File: MBeanExporterTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testExportJdkProxy() throws Exception {
	JmxTestBean bean = new JmxTestBean();
	bean.setName("Rob Harrop");

	ProxyFactory factory = new ProxyFactory();
	factory.setTarget(bean);
	factory.addAdvice(new NopInterceptor());
	factory.setInterfaces(IJmxTestBean.class);

	IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
	String name = "bean:mmm=whatever";

	Map<String, Object> beans = new HashMap<String, Object>();
	beans.put(name, proxy);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.registerBeans();

	ObjectName oname = ObjectName.getInstance(name);
	Object nameValue = server.getAttribute(oname, "Name");
	assertEquals("Rob Harrop", nameValue);
}
 
Example 4
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 5
Source File: MBeanExporterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testWithExposeClassLoader() throws Exception {
	String name = "Rob Harrop";
	String otherName = "Juergen Hoeller";

	JmxTestBean bean = new JmxTestBean();
	bean.setName(name);
	ObjectName objectName = ObjectNameManager.getInstance("spring:type=Test");

	Map<String, Object> beans = new HashMap<>();
	beans.put(objectName.toString(), bean);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.setBeans(beans);
	exporter.setExposeManagedResourceClassLoader(true);
	start(exporter);

	assertIsRegistered("Bean instance not registered", objectName);

	Object result = server.invoke(objectName, "add", new Object[] {new Integer(2), new Integer(3)}, new String[] {
			int.class.getName(), int.class.getName()});

	assertEquals("Incorrect result return from add", result, new Integer(5));
	assertEquals("Incorrect attribute value", name, server.getAttribute(objectName, "Name"));

	server.setAttribute(objectName, new Attribute("Name", otherName));
	assertEquals("Incorrect updated name.", otherName, bean.getName());
}
 
Example 6
Source File: MBeanExporterOperationsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testRegisterManagedResourceWithUserSuppliedObjectName() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance("spring:name=Foo");

	JmxTestBean bean = new JmxTestBean();
	bean.setName("Rob Harrop");

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.registerManagedResource(bean, objectName);

	String name = (String) getServer().getAttribute(objectName, "Name");
	assertEquals("Incorrect name on MBean", name, bean.getName());
}
 
Example 7
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 8
Source File: MBeanExporterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testWithExposeClassLoader() throws Exception {
	String name = "Rob Harrop";
	String otherName = "Juergen Hoeller";

	JmxTestBean bean = new JmxTestBean();
	bean.setName(name);
	ObjectName objectName = ObjectNameManager.getInstance("spring:type=Test");

	Map<String, Object> beans = new HashMap<>();
	beans.put(objectName.toString(), bean);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.setBeans(beans);
	exporter.setExposeManagedResourceClassLoader(true);
	start(exporter);

	assertIsRegistered("Bean instance not registered", objectName);

	Object result = server.invoke(objectName, "add", new Object[] {new Integer(2), new Integer(3)}, new String[] {
			int.class.getName(), int.class.getName()});

	assertEquals("Incorrect result return from add", result, new Integer(5));
	assertEquals("Incorrect attribute value", name, server.getAttribute(objectName, "Name"));

	server.setAttribute(objectName, new Attribute("Name", otherName));
	assertEquals("Incorrect updated name.", otherName, bean.getName());
}
 
Example 9
Source File: MBeanExporterOperationsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testRegisterManagedResourceWithUserSuppliedObjectName() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance("spring:name=Foo");

	JmxTestBean bean = new JmxTestBean();
	bean.setName("Rob Harrop");

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.registerManagedResource(bean, objectName);

	String name = (String) getServer().getAttribute(objectName, "Name");
	assertEquals("Incorrect name on MBean", name, bean.getName());
}
 
Example 10
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 11
Source File: MBeanExporterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithExposeClassLoader() throws Exception {
	String name = "Rob Harrop";
	String otherName = "Juergen Hoeller";

	JmxTestBean bean = new JmxTestBean();
	bean.setName(name);
	ObjectName objectName = ObjectNameManager.getInstance("spring:type=Test");

	Map<String, Object> beans = new HashMap<String, Object>();
	beans.put(objectName.toString(), bean);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.setBeans(beans);
	exporter.setExposeManagedResourceClassLoader(true);
	start(exporter);

	assertIsRegistered("Bean instance not registered", objectName);

	Object result = server.invoke(objectName, "add", new Object[] {new Integer(2), new Integer(3)}, new String[] {
			int.class.getName(), int.class.getName()});

	assertEquals("Incorrect result return from add", result, new Integer(5));
	assertEquals("Incorrect attribute value", name, server.getAttribute(objectName, "Name"));

	server.setAttribute(objectName, new Attribute("Name", otherName));
	assertEquals("Incorrect updated name.", otherName, bean.getName());
}
 
Example 12
Source File: MBeanExporterOperationsTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterManagedResourceWithUserSuppliedObjectName() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance("spring:name=Foo");

	JmxTestBean bean = new JmxTestBean();
	bean.setName("Rob Harrop");

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.registerManagedResource(bean, objectName);

	String name = (String) getServer().getAttribute(objectName, "Name");
	assertEquals("Incorrect name on MBean", name, bean.getName());
}