Package javax.management

Examples of javax.management.NotificationEmitter


      MBeanServer server = newMBeanServer();
      ObjectName name = new ObjectName("domain:key=value");
      LocalEmitterService mbean = new LocalEmitterService();
      server.registerMBean(mbean, name);

      NotificationEmitter proxy = (NotificationEmitter)MBeanServerInvocationHandler.newProxyInstance(server, name, NotificationEmitter.class, true);
      MBeanNotificationInfo[] infos = proxy.getNotificationInfo();
      if (!infos[0].getDescription().equals(LocalEmitterService.DESC)) fail();
   }
View Full Code Here


      MBeanServer server = newMBeanServer();
      ObjectName name = new ObjectName("domain:key=value");
      LocalEmitterService mbean = new LocalEmitterService();
      server.registerMBean(mbean, name);

      NotificationEmitter proxy = (NotificationEmitter)MBeanServerInvocationHandler.newProxyInstance(server, name, NotificationEmitter.class, true);
      TestListener listener = new TestListener();
      proxy.addNotificationListener(listener, null, null);
      proxy.removeNotificationListener(listener);
      mbean.test();
      if (listener.received) fail();
   }
View Full Code Here

      MBeanServer server = newMBeanServer();
      ObjectName name = new ObjectName("domain:key=value");
      LocalEmitterService mbean = new LocalEmitterService();
      server.registerMBean(mbean, name);

      NotificationEmitter proxy = (NotificationEmitter)MBeanServerInvocationHandler.newProxyInstance(server, name, NotificationEmitter.class, true);
      TestListener listener = new TestListener();
      TestFilter filter = new TestFilter();
      Object handback = new Object();
      proxy.addNotificationListener(listener, filter, handback);
      proxy.removeNotificationListener(listener, filter, handback);
      mbean.test();
      if (listener.received) fail();
   }
View Full Code Here

      MBeanServer server = newMBeanServer();
      ObjectName name = new ObjectName("domain:key=value");
      LocalEmitterService mbean = new LocalEmitterService();
      server.registerMBean(mbean, name);

      NotificationEmitter proxy = (NotificationEmitter)MBeanServerInvocationHandler.newProxyInstance(server, name, NotificationEmitter.class, true);
      TestListener listener1 = new TestListener();
      TestFilter filter = new TestFilter();
      Object handback = new Object();
      proxy.addNotificationListener(listener1, filter, handback);

      TestListener listener2 = new TestListener();
      proxy.addNotificationListener(listener2, null, null);

      mbean.test();
      if (!listener1.received) fail();
      if (!listener2.received) fail();

      try
      {
         proxy.removeNotificationListener(listener2, filter, handback);
         fail("Listener is not registered");
      }
      catch (ListenerNotFoundException x)
      {
      }

      proxy.removeNotificationListener(listener2, null, null);
      listener1.received = false;
      listener2.received = false;

      mbean.test();
      if (!listener1.received) fail();
View Full Code Here

              // entirely handled.

              _gc_callback -= (_gc_callback>>3);
            }
          }
          NotificationEmitter emitter = (NotificationEmitter) _allMemBean;
          emitter.addNotificationListener(this, null, m);
          ++c;
        }
      }
      assert c == 1;
    }
View Full Code Here

            throw new ListenerNotFoundException("Unknown listener");

        if (removeAll)
            broadcaster.removeNotificationListener(listenerWrapper);
        else {
            NotificationEmitter emitter = (NotificationEmitter) broadcaster;
            emitter.removeNotificationListener(listenerWrapper,
                                               filter,
                                               handback);
        }
    }
View Full Code Here

            }
        };
        NotificationFilter filter = null;
        Object handback = null;
        final ScanState before;
        final NotificationEmitter emitter = (NotificationEmitter)
                makeNotificationEmitter(proxy,DirectoryScannerMXBean.class);
        emitter.addNotificationListener(listener, filter, handback);
        before = proxy.getState();
        op.call();
        try {
            final Notification notification =
                    queue.poll(3000,TimeUnit.MILLISECONDS);
            assertEquals(AttributeChangeNotification.ATTRIBUTE_CHANGE,
                    notification.getType());
            assertEquals(AttributeChangeNotification.class,
                    notification.getClass());
            assertEquals(getObjectName(proxy),
                    notification.getSource());
            AttributeChangeNotification acn =
                    (AttributeChangeNotification)notification;
            assertEquals("State",acn.getAttributeName());
            assertEquals(ScanState.class.getName(),acn.getAttributeType());
            assertEquals(before,ScanState.valueOf((String)acn.getOldValue()));
            assertContained(after,ScanState.valueOf((String)acn.getNewValue()));
            emitter.removeNotificationListener(listener,filter,handback);
        } finally {
            try {
                op.cancel();
            } catch (Exception x) {
                System.err.println("Failed to cleanup: "+x);
View Full Code Here

            }
        };
        NotificationFilter filter = null;
        Object handback = null;
        final ScanState before;
        final NotificationEmitter emitter = (NotificationEmitter)proxy;
        emitter.addNotificationListener(listener, filter, handback);
        before = proxy.getState();
        op.call();
        try {
            final Notification notification =
                    queue.poll(3000,TimeUnit.MILLISECONDS);
            assertEquals(AttributeChangeNotification.ATTRIBUTE_CHANGE,
                    notification.getType());
            assertEquals(AttributeChangeNotification.class,
                    notification.getClass());
            assertEquals(ScanManager.SCAN_MANAGER_NAME,
                    notification.getSource());
            AttributeChangeNotification acn =
                    (AttributeChangeNotification)notification;
            assertEquals("State",acn.getAttributeName());
            assertEquals(ScanState.class.getName(),acn.getAttributeType());
            assertEquals(before,ScanState.valueOf((String)acn.getOldValue()));
            assertContained(after,ScanState.valueOf((String)acn.getNewValue()));
            emitter.removeNotificationListener(listener,filter,handback);
        } finally {
            try {
                op.cancel();
            } catch (Exception x) {
                System.err.println("Failed to cleanup: "+x);
View Full Code Here

    tenuredGenPool.setCollectionUsageThreshold((int) Math.floor(tenuredGenPool.getUsage().getMax() * threshold));
    tenuredGenPool.setUsageThreshold((int) Math.floor(tenuredGenPool.getUsage().getMax() * threshold));

    final Runnable r = run;
    MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
    NotificationEmitter emitter = (NotificationEmitter) mbean;
    NotificationListener l = new NotificationListener() {
      public void handleNotification(Notification n, Object hb) {
        if (n.getType().equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
          // this is th warning we want
          r.run();
        } else if (n.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
          // just FYI
          // System.out.println("memory threshold exceeded !!! : \n "+memString());
        }
      }
    };
    emitter.addNotificationListener(l,null,null);
   
    // remove previous listeners
    for(NotificationListener n : listeners){
      try {
        emitter.removeNotificationListener(n);
      } catch (ListenerNotFoundException e) {
        e.printStackTrace();
      }
    }
    listeners.clear();
View Full Code Here

    tenuredGenPool.setCollectionUsageThreshold((int) Math.floor(tenuredGenPool.getUsage().getMax() * threshold));
    tenuredGenPool.setUsageThreshold((int) Math.floor(tenuredGenPool.getUsage().getMax() * threshold));

    final Runnable r = run;
    MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
    NotificationEmitter emitter = (NotificationEmitter) mbean;
    NotificationListener l = new NotificationListener() {
      public void handleNotification(Notification n, Object hb) {
        if (n.getType().equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
          // this is th warning we want
          r.run();
        } else if (n.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
          // just FYI
          // System.out.println("memory threshold exceeded !!! : \n "+memString());
        }
      }
    };
    emitter.addNotificationListener(l,null,null);
   
    // remove previous listeners
    for(NotificationListener n : listeners){
      try {
        emitter.removeNotificationListener(n);
      } catch (ListenerNotFoundException e) {
        e.printStackTrace();
      }
    }
    listeners.clear();
View Full Code Here

TOP

Related Classes of javax.management.NotificationEmitter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.