Package javax.management.monitor

Examples of javax.management.monitor.CounterMonitor


    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public void createCounterMonitor(ObjectName objectName,String serviceName,Long monitoringFrequency,Long threshold){
    CounterMonitor cm = new CounterMonitor();
    cm.addObservedObject(objectName);
    cm.setObservedAttribute("TotalRequestCount");
    cm.setGranularityPeriod(monitoringFrequency);
    cm.setNotify(true);
    cm.setInitThreshold(new Long(threshold));
    cm.setDifferenceMode(true);
    cm.setNotify(true);
    cm.addNotificationListener(new CounterListener(),null,null);
    try {
      ObjectName objectNameC = new ObjectName("XFire:name="+serviceName+"CounterMonitor,"+"type=management");
      cm.start();
      mbs.registerMBean(cm, objectNameC);
   
    } catch (Exception e) {
      e.printStackTrace();
    }   
View Full Code Here


      expected.add(MonitorNotification.OBSERVED_OBJECT_ERROR);
      expected.add(MonitorNotification.RUNTIME_ERROR);
      expected.add(MonitorNotification.THRESHOLD_ERROR);
      expected.add(MonitorNotification.THRESHOLD_VALUE_EXCEEDED);

      MBeanNotificationInfo[] mbni = new CounterMonitor().getNotificationInfo();
      checkNotificationInfo("Counter", mbni, expected);
   }
View Full Code Here

   private void initCounterMonitor(boolean notify, Number threshold,
        boolean differenceMode, Number offset, Number modulus)
   {
      try
      {
         CounterMonitor counterMonitor = new CounterMonitor();
         counterMonitor.setNotify(notify);
         counterMonitor.setThreshold(threshold);
         counterMonitor.setDifferenceMode(differenceMode);
         counterMonitor.setOffset(offset);
         counterMonitor.setModulus(modulus);
         CounterSupport support = new CounterSupport();
         monitor = counterMonitor;
         monitored = support;
         initMonitor();
      }
View Full Code Here

      super(name);
   }

   protected Monitor createMonitor()
   {
      return new CounterMonitor();
   }
View Full Code Here

      return new CounterMonitor();
   }

   public void testCorrectInitialization() throws Exception
   {
      CounterMonitor monitor = (CounterMonitor)createMonitor();
      assertEquals(new Integer(0), monitor.getInitThreshold());
      assertEquals(new Integer(0), monitor.getModulus());
      assertEquals(new Integer(0), monitor.getOffset());
      assertFalse(monitor.getDifferenceMode());
      assertFalse(monitor.getNotify());
   }
View Full Code Here

      assertFalse(monitor.getNotify());
   }

   public void testSetThreshold() throws Exception
   {
      CounterMonitor monitor = (CounterMonitor)createMonitor();
      try
      {
         monitor.setThreshold(new Integer(-1));
         fail();
      }
      catch (IllegalArgumentException x)
      {
      }
      try
      {
         monitor.setInitThreshold(new Integer(-1));
         fail();
      }
      catch (IllegalArgumentException x)
      {
      }

      Integer threshold = new Integer(1);
      monitor.setThreshold(threshold);
      assertEquals(monitor.getInitThreshold(), threshold);

      threshold = new Integer(2);
      monitor.setInitThreshold(threshold);
      assertEquals(monitor.getInitThreshold(), threshold);
   }
View Full Code Here

      assertEquals(monitor.getInitThreshold(), threshold);
   }

   public void testSetModulus() throws Exception
   {
      CounterMonitor monitor = (CounterMonitor)createMonitor();
      try
      {
         monitor.setModulus(new Integer(-1));
         fail();
      }
      catch (IllegalArgumentException x)
      {
      }

      Integer modulus = new Integer(1);
      monitor.setModulus(modulus);
      assertEquals(monitor.getModulus(), modulus);
   }
View Full Code Here

      assertEquals(monitor.getModulus(), modulus);
   }

   public void testSetOffset() throws Exception
   {
      CounterMonitor monitor = (CounterMonitor)createMonitor();
      try
      {
         monitor.setOffset(new Integer(-1));
         fail();
      }
      catch (IllegalArgumentException x)
      {
      }

      Integer offset = new Integer(1);
      monitor.setOffset(offset);
      assertEquals(monitor.getOffset(), offset);
   }
View Full Code Here

   }

   public void testIntegerCounter() throws Exception
   {
      MBeanServer server = newMBeanServer();
      CounterMonitor monitor = (CounterMonitor)createMonitor();
      server.registerMBean(monitor, ObjectName.getInstance(":service=monitor"));

      Counter counter = new Counter();
      ObjectName counterName = ObjectName.getInstance(":mbean=counter");
      server.registerMBean(counter, counterName);

      long period = 1000;
      monitor.addObservedObject(counterName);
      monitor.setGranularityPeriod(period);
      monitor.setObservedAttribute("IntegerCounter");
      Integer initThreshold = new Integer(3);
      monitor.setInitThreshold(initThreshold);
      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

   }

   public void testIntegerCounterWithOffset() throws Exception
   {
      MBeanServer server = newMBeanServer();
      CounterMonitor monitor = (CounterMonitor)createMonitor();
      server.registerMBean(monitor, ObjectName.getInstance(":service=monitor"));

      Counter counter = new Counter();
      ObjectName counterName = ObjectName.getInstance(":mbean=counter");
      server.registerMBean(counter, counterName);

      long period = 1000;
      monitor.addObservedObject(counterName);
      monitor.setGranularityPeriod(period);
      monitor.setObservedAttribute("IntegerCounter");
      Integer initThreshold = new Integer(3);
      monitor.setInitThreshold(initThreshold);
      monitor.setNotify(true);
      Integer offset = new Integer(5);
      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

Related Classes of javax.management.monitor.CounterMonitor

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.