/**
* Test for the method
* removeNotificationListener(javax.management.NotificationListener,
* javax.management.NotificationFilter, java.lang.Object)
*
* @see javax.management.NotificationBroadcasterSupport#removeNotificationListener(javax.management.NotificationListener,
* javax.management.NotificationFilter, java.lang.Object)
*/
public final void testRemoveNotificationListenerNotificationListenerNotificationFilterObject() {
Hello h = new Hello();
// Test exception.
try {
h.removeNotificationListener(this, null, null);
fail("ListenerNotFoundException not thrown!");
} catch (Throwable ex) {
assertTrue("Wrong exception thrown: " + ex,
(ex instanceof ListenerNotFoundException));
}
h.addNotificationListener(this, null, null);
h.addNotificationListener(this, null, null);
removeNL(h, null, null);
h.sayHello();
assertNotNull("Notification has not been received!", n);
removeNL(h, null, null);
n = null;
h.sayHello();
assertNull("Notification has been received!", n);
AttributeChangeNotificationFilter acf = new AttributeChangeNotificationFilter();
acf.enableAttribute("Name");
NotificationFilterSupport f = new NotificationFilterSupport();
f.enableType(Hello.SAY_HELLO_INVOKED);
h.addNotificationListener(this, acf, "handback1");
h.addNotificationListener(this, f, handback);
removeNL(h, f, handback);
n = null;
h.setName("New name");
assertNotNull("Notification has not been received!", n);
assertTrue("Wrong notification received: " + n,
(n instanceof AttributeChangeNotification));
}
java类javax.management.NotificationFilterSupport的实例源码
NotificationBroadcasterSupportTest.java 文件源码
项目:freeVM
阅读 25
收藏 0
点赞 0
评论 0
RMIConnector.java 文件源码
项目:openjdk-icedtea7
阅读 28
收藏 0
点赞 0
评论 0
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
ClientGUI.java 文件源码
项目:log4j2
阅读 19
收藏 0
点赞 0
评论 0
private void registerListeners() throws InstanceNotFoundException,
MalformedObjectNameException, IOException {
final NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(StatusLoggerAdminMBean.NOTIF_TYPE_MESSAGE);
final ObjectName objName = new ObjectName(StatusLoggerAdminMBean.NAME);
client.getConnection().addNotificationListener(objName, this, filter,
null);
}
ClientGui.java 文件源码
项目:logging-log4j2
阅读 25
收藏 0
点赞 0
评论 0
public ClientGui(final Client client) throws IOException, JMException {
this.client = Objects.requireNonNull(client, "client");
createWidgets();
populateWidgets();
// register for Notifications if LoggerContext MBean was added/removed
final ObjectName addRemoveNotifs = MBeanServerDelegate.DELEGATE_NAME;
final NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(Server.DOMAIN); // only interested in Log4J2 MBeans
client.getConnection().addNotificationListener(addRemoveNotifs, this, null, null);
}
ClientGui.java 文件源码
项目:logging-log4j2
阅读 26
收藏 0
点赞 0
评论 0
private void registerListeners(final StatusLoggerAdminMBean status) throws InstanceNotFoundException,
MalformedObjectNameException, IOException {
final NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(StatusLoggerAdminMBean.NOTIF_TYPE_MESSAGE);
final ObjectName objName = status.getObjectName();
// System.out.println("Add listener for " + objName);
client.getConnection().addNotificationListener(objName, this, filter, status.getContextName());
}
MemoryMXBeanImplTest.java 文件源码
项目:cn1
阅读 19
收藏 0
点赞 0
评论 0
public final void testRemoveNotificationListenerNotificationListenerNotificationFilterObject()
throws Exception {
// Register a listener
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED);
SimpleTestListener listener = new SimpleTestListener();
notifierBean.addNotificationListener(listener, filter, null);
// Fire off a notification and ensure that the listener receives it.
MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
MemoryNotificationInfo info = new MemoryNotificationInfo("Tim", mu, 42);
CompositeData cd = ManagementUtils
.toMemoryNotificationInfoCompositeData(info);
Notification notification = new Notification(
MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
notification.setUserData(cd);
notifierBean.sendNotification(notification);
assertEquals(1, listener.getNotificationsReceivedCount());
// Remove the listener
notifierBean.removeNotificationListener(listener, filter, null);
// Fire off a notification and ensure that the listener does
// *not* receive it.
listener.resetNotificationsReceivedCount();
notification = new Notification(
MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
notification.setUserData(cd);
notifierBean.sendNotification(notification);
assertEquals(0, listener.getNotificationsReceivedCount());
// Try and remove the listener one more time. Should result in a
// ListenerNotFoundException being thrown.
try {
notifierBean.removeNotificationListener(listener, filter, null);
fail("Should have thrown a ListenerNotFoundException!");
} catch (ListenerNotFoundException e) {
}
}
MemoryMXBeanImplTest.java 文件源码
项目:freeVM
阅读 19
收藏 0
点赞 0
评论 0
public final void testRemoveNotificationListenerNotificationListenerNotificationFilterObject()
throws Exception {
// Register a listener
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED);
SimpleTestListener listener = new SimpleTestListener();
notifierBean.addNotificationListener(listener, filter, null);
// Fire off a notification and ensure that the listener receives it.
MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
MemoryNotificationInfo info = new MemoryNotificationInfo("Tim", mu, 42);
CompositeData cd = ManagementUtils
.toMemoryNotificationInfoCompositeData(info);
Notification notification = new Notification(
MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
notification.setUserData(cd);
notifierBean.sendNotification(notification);
assertEquals(1, listener.getNotificationsReceivedCount());
// Remove the listener
notifierBean.removeNotificationListener(listener, filter, null);
// Fire off a notification and ensure that the listener does
// *not* receive it.
listener.resetNotificationsReceivedCount();
notification = new Notification(
MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
notification.setUserData(cd);
notifierBean.sendNotification(notification);
assertEquals(0, listener.getNotificationsReceivedCount());
// Try and remove the listener one more time. Should result in a
// ListenerNotFoundException being thrown.
try {
notifierBean.removeNotificationListener(listener, filter, null);
fail("Should have thrown a ListenerNotFoundException!");
} catch (ListenerNotFoundException e) {
}
}
MemoryMXBeanImplTest.java 文件源码
项目:freeVM
阅读 17
收藏 0
点赞 0
评论 0
public final void testRemoveNotificationListenerNotificationListenerNotificationFilterObject()
throws Exception {
// Register a listener
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED);
SimpleTestListener listener = new SimpleTestListener();
notifierBean.addNotificationListener(listener, filter, null);
// Fire off a notification and ensure that the listener receives it.
MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
MemoryNotificationInfo info = new MemoryNotificationInfo("Tim", mu, 42);
CompositeData cd = ManagementUtils
.toMemoryNotificationInfoCompositeData(info);
Notification notification = new Notification(
MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
notification.setUserData(cd);
notifierBean.sendNotification(notification);
assertEquals(1, listener.getNotificationsReceivedCount());
// Remove the listener
notifierBean.removeNotificationListener(listener, filter, null);
// Fire off a notification and ensure that the listener does
// *not* receive it.
listener.resetNotificationsReceivedCount();
notification = new Notification(
MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
notification.setUserData(cd);
notifierBean.sendNotification(notification);
assertEquals(0, listener.getNotificationsReceivedCount());
// Try and remove the listener one more time. Should result in a
// ListenerNotFoundException being thrown.
try {
notifierBean.removeNotificationListener(listener, filter, null);
fail("Should have thrown a ListenerNotFoundException!");
} catch (ListenerNotFoundException e) {
}
}
StructureTest.java 文件源码
项目:freeVM
阅读 18
收藏 0
点赞 0
评论 0
/**
* This testcase verifies MBeanToUnregister field in notifications.
*/
public Result testRemovalNotification() throws Exception {
incorrectNotificationFlag = false;
MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();
RelationService relationService = new RelationService(true);
ObjectName relationServiceName = new ObjectName(
"mBeanServer:type=RelationService,name=rs");
mBeanServer.registerMBean(relationService, relationServiceName);
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType("jmx.relation");
relationService.addNotificationListener(this, filter, null);
checkNotifications = true;
RoleInfo[] roleInfo = new RoleInfo[1];
roleInfo[0] = new RoleInfo("unitRole", classPath, true, true, 1, 2,
"Unit role");
// Creating an Internal Relation Type
relationService.createRelationType("internalRelationType", roleInfo);
UnitMBean unit = new Unit();
ObjectName unitName = new ObjectName("mBeanServer:type=Unit,name=Unit");
mBeanServer.registerMBean(unit, unitName);
ArrayList unitList = new ArrayList();
unitList.add(unitName);
Role unitRole = new Role("unitRole", unitList);
RoleList unitRoles = new RoleList();
unitRoles.add(unitRole);
// Now Create relations between unit MBeans
// Notification Data
relationNotification = new RelationNotificationForCompare(
"jmx.relation.creation.basic", relationService, 1, 10,
"Creation of relation internalRelation", "internalRelation",
"internalRelationType", null, null);
relationService.createRelation("internalRelation",
"internalRelationType", unitRoles);
// Notification Data
relationNotification = new RelationNotificationForCompare(
"jmx.relation.removal.basic", relationService, 2, 10,
"Removal of relation internalRelation", "internalRelation",
"internalRelationType", null, new ArrayList());
relationService.removeRelation("internalRelation");
if (incorrectNotificationFlag) {
return failed("IncorrectNotifications (see log for more information)");
}
return passed();
}
ConnectorClientTest.java 文件源码
项目:freeVM
阅读 15
收藏 0
点赞 0
评论 0
/**
* Test perfom operation with connector client through RMI protocol
*/
public Result testRMIConnectorClient() throws Exception {
try {
log.info("Create JMX Service URL");
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
// Create a JMXConnectorServer
log.info("Create JMXConnectorServer");
JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, enviroment, mbeanServer);
log.info("Start the server");
server.start();
JMXConnector client = server.toJMXConnector(enviroment);
log.info("Connect client to the server");
client.connect(enviroment);
client.getClass();
log.info("Connection id - " + client.getConnectionId());
MBeanServerConnection mbsc = client.getMBeanServerConnection();
//Add than remove notification listener on MBean
log.info("Add than remove notification listener on MBean");
Listener listener = new Listener();
Object obj = new Object();
NotificationFilterSupport filter = new NotificationFilterSupport();
client.addConnectionNotificationListener(listener,filter,obj );
client.removeConnectionNotificationListener(listener);
client.addConnectionNotificationListener(listener,filter,obj );
client.removeConnectionNotificationListener(listener,filter,obj );
log.info("Close client connection");
client.close();
log.info("Stop the server");
server.stop();
} catch (Exception e) {
e.printStackTrace();
return failed("Unexpected exception");
}
return result();
}