Search in sources :

Example 26 with AttributeChangeNotification

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()));
}
Also used : AttributeChangeNotification(javax.management.AttributeChangeNotification) AttributeChangeNotificationFilter(javax.management.AttributeChangeNotificationFilter) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest) AttributeChangeNotification(javax.management.AttributeChangeNotification) Notification(javax.management.Notification) ByteArrayInputStream(java.io.ByteArrayInputStream) NotificationListener(javax.management.NotificationListener) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 27 with AttributeChangeNotification

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);
}
Also used : AttributeChangeNotification(javax.management.AttributeChangeNotification) AttributeChangeNotification(javax.management.AttributeChangeNotification) Notification(javax.management.Notification)

Example 28 with AttributeChangeNotification

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()));
    }
}
Also used : AttributeChangeNotification(javax.management.AttributeChangeNotification)

Aggregations

AttributeChangeNotification (javax.management.AttributeChangeNotification)28 Notification (javax.management.Notification)14 NotificationListener (javax.management.NotificationListener)8 Test (org.junit.Test)6 ObjectName (javax.management.ObjectName)5 Bundle (org.osgi.framework.Bundle)4 ScanState (com.sun.jmx.examples.scandir.ScanManagerMXBean.ScanState)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 NotificationFilter (javax.management.NotificationFilter)3 LinkedList (java.util.LinkedList)2 ExecutorService (java.util.concurrent.ExecutorService)2 MBeanServer (javax.management.MBeanServer)2 NotificationEmitter (javax.management.NotificationEmitter)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 CompositeData (javax.management.openmbean.CompositeData)2 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)2 Call (com.sun.jmx.examples.scandir.ScanManagerTest.Call)1 DirectoryScannerConfig (com.sun.jmx.examples.scandir.config.DirectoryScannerConfig)1