use of javax.management.AttributeChangeNotification in project aries by apache.
the class BundleStateMBeanTest method testAttributeChangeNotifications.
@Test
public void testAttributeChangeNotifications() throws Exception {
final List<AttributeChangeNotification> attributeChanges = new ArrayList<AttributeChangeNotification>();
AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter();
filter.disableAllAttributes();
filter.enableAttribute("BundleIds");
mbeanServer.addNotificationListener(objectName, new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
attributeChanges.add((AttributeChangeNotification) notification);
}
}, filter, null);
long[] idsWithout = mbean.getBundleIds();
assertEquals("Precondition", 0, attributeChanges.size());
Manifest mf = new Manifest();
mf.getMainAttributes().putValue("Bundle-ManifestVersion", "2");
mf.getMainAttributes().putValue("Bundle-SymbolicName", "empty-test-bundle");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JarOutputStream jos = new JarOutputStream(baos, mf);
jos.closeEntry();
jos.close();
InputStream bais = new ByteArrayInputStream(baos.toByteArray());
Bundle bundle = bundleContext.installBundle("http://somelocation", bais);
long[] idsWith = new long[idsWithout.length + 1];
System.arraycopy(idsWithout, 0, idsWith, 0, idsWithout.length);
idsWith[idsWith.length - 1] = bundle.getBundleId();
Arrays.sort(idsWith);
waitForListToReachSize(attributeChanges, 1);
assertEquals(1, attributeChanges.size());
AttributeChangeNotification ac = attributeChanges.get(0);
assertEquals("BundleIds", ac.getAttributeName());
long oldSequence = ac.getSequenceNumber();
assertTrue(Arrays.equals(idsWithout, (long[]) ac.getOldValue()));
assertTrue(Arrays.equals(idsWith, (long[]) ac.getNewValue()));
bundle.uninstall();
waitForListToReachSize(attributeChanges, 2);
AttributeChangeNotification ac2 = attributeChanges.get(1);
assertEquals("BundleIds", ac2.getAttributeName());
assertEquals(oldSequence + 1, ac2.getSequenceNumber());
assertTrue(Arrays.equals(idsWith, (long[]) ac2.getOldValue()));
assertTrue(Arrays.equals(idsWithout, (long[]) ac2.getNewValue()));
}
use of javax.management.AttributeChangeNotification in project geode by apache.
the class CustomMBean method writeName.
@Override
public void writeName(String name) {
this.name = name;
Notification n = new AttributeChangeNotification(this, sequenceNumber++, System.currentTimeMillis(), "staticField changed", "staticField", "int", name, this.name);
sendNotification(n);
}
use of javax.management.AttributeChangeNotification in project sling by apache.
the class QueuesMBeanImpl method updateQueueMBean.
private void updateQueueMBean(QueueStatusEvent e) {
QueueMBeanHolder queueMBeanHolder = queues.get(e.getQueue().getName());
if (queueMBeanHolder != null) {
String[] oldQueue = getQueueNames();
names = null;
this.sendNotification(new AttributeChangeNotification(this, sequence.incrementAndGet(), System.currentTimeMillis(), "Queue " + e.getQueue().getName() + " updated ", "queueNames", "String[]", oldQueue, getQueueNames()));
}
}
Aggregations