Examples of MutableInteger


Examples of test.MutableInteger

         // Register an MBean Emitter
         ObjectName emitterName = ObjectName.getInstance(":mbean=emitter");
         MBeanEmitter emitter = new MBeanEmitter();
         server.registerMBean(emitter, emitterName);

         final MutableInteger counter = new MutableInteger(0);
         NotificationListener listener = new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               counter.set(counter.get() + 1);
            }
         };

         JMXServiceURL url = createJMXConnectorServerAddress();
         cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), server);
         cntorServer.start();
         sleep(5000);

         cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
         MBeanServerConnection mbsc1 = cntor.getMBeanServerConnection();

         mbsc1.addNotificationListener(emitterName, listener, null, null);
         // Wait for notification threads to start
         sleep(1000);

         Notification notification = new Notification("type", emitter, 0);
         emitter.emit(notification);

         // Wait for the notification to arrive
         sleep(1000);

         // Be sure it's received
         assertEquals(counter.get(), 1);

         // Be sure I can remove the same listener from another MBeanServerConnection
         MBeanServerConnection mbsc2 = cntor.getMBeanServerConnection();
         mbsc2.removeNotificationListener(emitterName, listener, null, null);

         emitter.emit(notification);

         // Be sure no listeners anymore
         assertEquals(counter.get(), 1);
      } catch (Exception x)
      {
         x.printStackTrace();
         throw x;
      } finally
View Full Code Here

Examples of test.MutableInteger

         return super.getImpact(info);
      }

      private void increment()
      {
         if (count == null) count = new MutableInteger(0);
         count.set(count.get() + 1);
      }
View Full Code Here

Examples of test.MutableInteger

      MBeanServer server = newMBeanServer();
      IdentityEmitter emitter = new IdentityEmitter();
      ObjectName objectName = ObjectName.getInstance("test:type=emitter");
      server.registerMBean(emitter, objectName);

      final MutableInteger count = new MutableInteger(0);
      final MutableObject source = new MutableObject(null);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            source.set(notification.getSource());
            count.set(count.get() + 1);
         }
      };

      // Add same listener twice, with different handbacks
      Object handback = new Object();
      server.addNotificationListener(objectName, listener, null, null);
      server.addNotificationListener(objectName, listener, null, handback);
      assertEquals(emitter.getNotificationListeners().size(), 2);

      Notification notification = new Notification("type", emitter, 0);
      emitter.sendNotification(notification);
      assertEquals(objectName, source.get());
      assertEquals(count.get(), 2);

      server.removeNotificationListener(objectName, listener, null, null);
      assertEquals(emitter.getNotificationListeners().size(), 1);

      server.removeNotificationListener(objectName, listener, null, handback);
View Full Code Here

Examples of test.MutableInteger

      ObjectName name1 = ObjectName.getInstance(":name=one");
      monitor.addObservedObject(name1);
      monitor.setGranularityPeriod(1000);
      monitor.setObservedAttribute("dummy");

      final MutableInteger counter = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      monitor.addNotificationListener(new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            counter.set(counter.get() + 1);
            holder.set(notification);
         }
      }, null, null);
      monitor.start();

      try
      {
         // Wait for notification to arrive
         while (holder.get() == null) sleep(10);

         // Be sure only one arrived
         sleep(5000);
         assertEquals(counter.get(), 1);

         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.OBSERVED_OBJECT_ERROR);
      }
      finally
View Full Code Here

Examples of test.MutableInteger

      ObjectName name1 = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
      monitor.addObservedObject(name1);
      monitor.setGranularityPeriod(1000);
      monitor.setObservedAttribute("dummy");

      final MutableInteger counter = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      monitor.addNotificationListener(new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            counter.set(counter.get() + 1);
            holder.set(notification);
         }
      }, null, null);
      monitor.start();

      try
      {
         // Wait for notification to arrive
         while (holder.get() == null) sleep(10);

         // Be sure only one arrived
         sleep(5000);
         assertEquals(counter.get(), 1);

         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.OBSERVED_ATTRIBUTE_ERROR);
      }
      finally
View Full Code Here

Examples of test.MutableInteger

      MonitorTarget target = new MonitorTarget();
      int value = low.intValue() - 1;
      target.setInteger(value);
      server.registerMBean(target, name);

      final MutableInteger times = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            times.set(times.get() + 1);
            holder.set(notification);
         }
      };
      server.addNotificationListener(monitorName, listener, null, null);
      monitor.start();

      try
      {
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());

         // Set gauge above high threshold
         value = value + high.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);

         // Set gauge inside threshold
         value = value + low.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());

         // Set gauge above threshold again
         value = value + high.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);
      }
      finally
      {
View Full Code Here

Examples of test.MutableInteger

      MonitorTarget target = new MonitorTarget();
      int value = low.intValue() + 1;
      target.setInteger(value);
      server.registerMBean(target, name);

      final MutableInteger times = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            times.set(times.get() + 1);
            holder.set(notification);
         }
      };
      server.addNotificationListener(monitorName, listener, null, null);
      monitor.start();

      try
      {
         // Inside the thresholds, be sure low notification
         sleep(period * 3);
         assertEquals(times.get(), 1);
         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED);

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);

         // Monitoring takes time, so I disable low notification to be sure to get only the high one
         // The monitor is in difference mode, so the first time will get the high notification, but
         // the second time will get zero, since the gauge did not change, which will triggers a low notification
         monitor.setNotifyLow(false);
         // Set gauge above high threshold
         value = value + high.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);

         monitor.setNotifyHigh(false);
         monitor.setNotifyLow(true);
         // Set gauge above high threshold, so just after goes below low threshold
         value = value + high.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED);

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);

         // Set gauge inside threshold
         value = value + low.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());
      }
      finally
      {
         monitor.stop();
View Full Code Here

Examples of test.MutableInteger

      monitor.addObservedObject(counterName);
      monitor.setGranularityPeriod(1000);
      monitor.setObservedAttribute("ObjectCounter");

      final MutableInteger times = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      monitor.addNotificationListener(new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            times.set(times.get() + 1);
            holder.set(notification);
         }
      }, null, null);
      monitor.start();

      try
      {
         // Wait for notification to arrive
         while (holder.get() == null) sleep(10);

         // Be sure only one arrived
         sleep(5000);
         assertEquals(times.get(), 1);

         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR);
      }
      finally
View Full Code Here

Examples of test.MutableInteger

      monitor.setNotify(true);
      // No modulus, no offset

      counter.setIntegerCounter(initThreshold.intValue() - 1);

      final MutableInteger times = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      monitor.addNotificationListener(new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            times.set(times.get() + 1);
            holder.set(notification);
         }
      }, null, null);
      monitor.start();

      try
      {
         // Below threshold, no notifications should be sent
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());

         // Above threshold, just one notification should be sent
         counter.setIntegerCounter(initThreshold.intValue() + 1);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_VALUE_EXCEEDED);

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);
      }
      finally
      {
         monitor.stop();
      }
View Full Code Here

Examples of test.MutableInteger

      monitor.setOffset(offset);
      // No modulus

      counter.setIntegerCounter(initThreshold.intValue() - 1);

      final MutableInteger times = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      monitor.addNotificationListener(new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            times.set(times.get() + 1);
            holder.set(notification);
         }
      }, null, null);
      monitor.start();

      try
      {
         // Below threshold, no notifications should be sent
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());

         // Above threshold, just one notification should be sent
         counter.setIntegerCounter(initThreshold.intValue() + 1);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
         // The threshold should have offset
         Number threshold = monitor.getThreshold(counterName);
         assertEquals(threshold.intValue(), monitor.getInitThreshold().intValue() + offset.intValue());

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);

         // Above threshold by more than 1 offset
         counter.setIntegerCounter(initThreshold.intValue() + offset.intValue() * 2 + 1);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
         // The threshold should have offset correctly
         threshold = monitor.getThreshold(counterName);
         assertEquals(threshold.intValue(), monitor.getInitThreshold().intValue() + offset.intValue() * 3);

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);
      }
      finally
      {
         monitor.stop();
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.