Java Code Examples for org.springframework.jmx.access.NotificationListenerRegistrar#setNotificationListener()

The following examples show how to use org.springframework.jmx.access.NotificationListenerRegistrar#setNotificationListener() . 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: NotificationListenerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testNotificationListenerRegistrar() throws Exception {
	ObjectName objectName = ObjectName.getInstance("spring:name=Test");
	JmxTestBean bean = new JmxTestBean();

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

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

	CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();

	NotificationListenerRegistrar registrar = new NotificationListenerRegistrar();
	registrar.setServer(server);
	registrar.setNotificationListener(listener);
	registrar.setMappedObjectName(objectName);
	registrar.afterPropertiesSet();

	// update the attribute
	String attributeName = "Name";
	server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
	assertEquals("Listener not notified", 1, listener.getCount(attributeName));

	registrar.destroy();

	// try to update the attribute again
	server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
	assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName));
}
 
Example 2
Source File: NotificationListenerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testNotificationListenerRegistrarWithMultipleNames() throws Exception {
	ObjectName objectName = ObjectName.getInstance("spring:name=Test");
	ObjectName objectName2 = ObjectName.getInstance("spring:name=Test2");
	JmxTestBean bean = new JmxTestBean();
	JmxTestBean bean2 = new JmxTestBean();

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

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

	CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();

	NotificationListenerRegistrar registrar = new NotificationListenerRegistrar();
	registrar.setServer(server);
	registrar.setNotificationListener(listener);
	//registrar.setMappedObjectNames(new Object[] {objectName, objectName2});
	registrar.setMappedObjectNames("spring:name=Test", "spring:name=Test2");
	registrar.afterPropertiesSet();

	// update the attribute
	String attributeName = "Name";
	server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
	assertEquals("Listener not notified", 1, listener.getCount(attributeName));

	registrar.destroy();

	// try to update the attribute again
	server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
	assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName));
}
 
Example 3
Source File: NotificationListenerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testNotificationListenerRegistrar() throws Exception {
	ObjectName objectName = ObjectName.getInstance("spring:name=Test");
	JmxTestBean bean = new JmxTestBean();

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

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

	CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();

	NotificationListenerRegistrar registrar = new NotificationListenerRegistrar();
	registrar.setServer(server);
	registrar.setNotificationListener(listener);
	registrar.setMappedObjectName(objectName);
	registrar.afterPropertiesSet();

	// update the attribute
	String attributeName = "Name";
	server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
	assertEquals("Listener not notified", 1, listener.getCount(attributeName));

	registrar.destroy();

	// try to update the attribute again
	server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
	assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName));
}
 
Example 4
Source File: NotificationListenerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testNotificationListenerRegistrarWithMultipleNames() throws Exception {
	ObjectName objectName = ObjectName.getInstance("spring:name=Test");
	ObjectName objectName2 = ObjectName.getInstance("spring:name=Test2");
	JmxTestBean bean = new JmxTestBean();
	JmxTestBean bean2 = new JmxTestBean();

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

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

	CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();

	NotificationListenerRegistrar registrar = new NotificationListenerRegistrar();
	registrar.setServer(server);
	registrar.setNotificationListener(listener);
	//registrar.setMappedObjectNames(new Object[] {objectName, objectName2});
	registrar.setMappedObjectNames("spring:name=Test", "spring:name=Test2");
	registrar.afterPropertiesSet();

	// update the attribute
	String attributeName = "Name";
	server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
	assertEquals("Listener not notified", 1, listener.getCount(attributeName));

	registrar.destroy();

	// try to update the attribute again
	server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
	assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName));
}
 
Example 5
Source File: NotificationListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotificationListenerRegistrar() throws Exception {
	ObjectName objectName = ObjectName.getInstance("spring:name=Test");
	JmxTestBean bean = new JmxTestBean();

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

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

	CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();

	NotificationListenerRegistrar registrar = new NotificationListenerRegistrar();
	registrar.setServer(server);
	registrar.setNotificationListener(listener);
	registrar.setMappedObjectName(objectName);
	registrar.afterPropertiesSet();

	// update the attribute
	String attributeName = "Name";
	server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
	assertEquals("Listener not notified", 1, listener.getCount(attributeName));

	registrar.destroy();

	// try to update the attribute again
	server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
	assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName));
}
 
Example 6
Source File: NotificationListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotificationListenerRegistrarWithMultipleNames() throws Exception {
	ObjectName objectName = ObjectName.getInstance("spring:name=Test");
	ObjectName objectName2 = ObjectName.getInstance("spring:name=Test2");
	JmxTestBean bean = new JmxTestBean();
	JmxTestBean bean2 = new JmxTestBean();

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

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

	CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();

	NotificationListenerRegistrar registrar = new NotificationListenerRegistrar();
	registrar.setServer(server);
	registrar.setNotificationListener(listener);
	//registrar.setMappedObjectNames(new Object[] {objectName, objectName2});
	registrar.setMappedObjectNames(new String[] { "spring:name=Test", "spring:name=Test2" });
	registrar.afterPropertiesSet();

	// update the attribute
	String attributeName = "Name";
	server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
	assertEquals("Listener not notified", 1, listener.getCount(attributeName));

	registrar.destroy();

	// try to update the attribute again
	server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
	assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName));
}