public void addAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, IllegalArgumentException { if (listener == null) throw new RuntimeOperationsException(new IllegalArgumentException( LocalizedStrings.MX4JModelMBean_LISTENER_CANNOT_BE_NULL.toLocalizedString())); AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter(); if (attributeName != null) { filter.enableAttribute(attributeName); } else { MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes(); for (int i = 0; i < ai.length; i++) { Descriptor d = ((ModelMBeanAttributeInfo) ai[i]).getDescriptor(); filter.enableAttribute((String) d.getFieldValue("name")); } } getAttributeChangeBroadcaster().addNotificationListener(listener, filter, handback); Logger logger = getLogger(); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Listener " + listener + " for attribute " + attributeName + " added successfully, handback is " + handback); }
private void removeAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, ListenerNotFoundException { if (listener == null) throw new RuntimeOperationsException(new IllegalArgumentException( LocalizedStrings.MX4JModelMBean_LISTENER_CANNOT_BE_NULL.toLocalizedString())); AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter(); if (attributeName != null) { filter.enableAttribute(attributeName); } else { MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes(); for (int i = 0; i < ai.length; i++) { Descriptor d = ((ModelMBeanAttributeInfo) ai[i]).getDescriptor(); filter.enableAttribute((String) d.getFieldValue("name")); } } getAttributeChangeBroadcaster().removeNotificationListener(listener, filter, handback); Logger logger = getLogger(); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Listener " + listener + " for attribute " + attributeName + " removed successfully, handback is " + handback); }
public void addAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, IllegalArgumentException { if (listener == null) throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_LISTENER_CANNOT_BE_NULL.toLocalizedString())); AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter(); if (attributeName != null) { filter.enableAttribute(attributeName); } else { MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes(); for (int i = 0; i < ai.length; i++) { Descriptor d = ((ModelMBeanAttributeInfo)ai[i]).getDescriptor(); filter.enableAttribute((String)d.getFieldValue("name")); } } getAttributeChangeBroadcaster().addNotificationListener(listener, filter, handback); Logger logger = getLogger(); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Listener " + listener + " for attribute " + attributeName + " added successfully, handback is " + handback); }
private void removeAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, ListenerNotFoundException { if (listener == null) throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_LISTENER_CANNOT_BE_NULL.toLocalizedString())); AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter(); if (attributeName != null) { filter.enableAttribute(attributeName); } else { MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes(); for (int i = 0; i < ai.length; i++) { Descriptor d = ((ModelMBeanAttributeInfo)ai[i]).getDescriptor(); filter.enableAttribute((String)d.getFieldValue("name")); } } getAttributeChangeBroadcaster().removeNotificationListener(listener, filter, handback); Logger logger = getLogger(); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Listener " + listener + " for attribute " + attributeName + " removed successfully, handback is " + handback); }
/** * Initialize the notofocation listener and filter. */ public void init() { listener = new SimpleNotificationListener(); AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter(); filter.enableAttribute("Attribute1"); filter.disableAttribute("Attribute2"); this.filter = filter; mbsd = new MBeanServerDelegate(); n1 = new AttributeChangeNotification(this, 1, System .currentTimeMillis(), "Attribute1 changed", "Attribute1", "java.lang.String", "oldVal1", "newVal1"); n2 = new AttributeChangeNotification(this, 2, System .currentTimeMillis(), "Attribute2 changed", "Attribute2", "java.lang.String", "oldVal2", "newVal2"); }
/** * 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)); }
public final void setUpDisableAllAttributes() throws Exception { f = new AttributeChangeNotificationFilter(); f.enableAttribute("Name"); f.disableAllAttributes(); mbs.addNotificationListener(name, this, f, "handback"); freeze(100); mbs.setAttribute(name, new Attribute("Name", "New name")); }
public final void setUpDisableAttribute() throws Exception { f = new AttributeChangeNotificationFilter(); f.enableAttribute("Name"); f.disableAttribute("Name"); mbs.addNotificationListener(name, this, f, "handback"); freeze(100); mbs.setAttribute(name, new Attribute("Name", "New name123")); }
public final void setUpEnableAttribute() throws Exception { f = new AttributeChangeNotificationFilter(); f.enableAttribute("Name"); mbs.addNotificationListener(name, this, f, "handback"); freeze(100); mbs.setAttribute(name, new Attribute("Name", "New name")); }
/** * Test for the method enableAttribute(java.lang.String) * * @see javax.management.AttributeChangeNotificationFilter#enableAttribute(java.lang.String) */ public final void testEnableAttribute() { assertNotNull("Notification has not been received!", n); // Test exception. f = new AttributeChangeNotificationFilter(); try { f.enableAttribute(null); fail("IllegalArgumentException not thrown!"); } catch (Throwable ex) { assertTrue("Wrong exception thrown: " + ex, (ex instanceof IllegalArgumentException)); } }
public final void setUpGetEnabledAttributes() throws Exception { f = new AttributeChangeNotificationFilter(); f.enableAttribute("Name"); f.enableAttribute("Attribute1"); f.enableAttribute("Attribute2"); f.disableAttribute("Attribute2"); mbs.addNotificationListener(name, this, f, "handback"); freeze(100); mbs.setAttribute(name, new Attribute("Name", "New name")); }
public final void setUpIsNotificationEnabled() throws Exception { f = new AttributeChangeNotificationFilter(); f.enableAttribute("Name"); mbs.addNotificationListener(name, this, f, "handback"); freeze(100); mbs.setAttribute(name, new Attribute("Name", "New name")); }
/** * Test for the constructor AttributeChangeNotificationFilter() * * @see javax.management.AttributeChangeNotificationFilter#AttributeChangeNotificationFilter() */ public final void testAttributeChangeNotificationFilter() { AttributeChangeNotificationFilter f = new AttributeChangeNotificationFilter(); assertEquals(0, f.getEnabledAttributes().size()); }