Java Code Examples for javax.management.monitor.GaugeMonitor#setThresholds()

The following examples show how to use javax.management.monitor.GaugeMonitor#setThresholds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamicMBeanExample.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void main(String[] args) throws Exception
{
   // Let's create the MBeanServer
   MBeanServer server = MBeanServerFactory.newMBeanServer();

   // Let's create a dynamic MBean and register it
   DynamicService serviceMBean = new DynamicService();
   ObjectName serviceName = new ObjectName("examples", "mbean", "dynamic");
   server.registerMBean(serviceMBean, serviceName);

   // Now let's register a Monitor
   // We would like to know if we have peaks in activity, so we can use JMX's
   // GaugeMonitor
   GaugeMonitor monitorMBean = new GaugeMonitor();
   ObjectName monitorName = new ObjectName("examples", "monitor", "gauge");
   server.registerMBean(monitorMBean, monitorName);

   // Setup the monitor: we want to be notified if we have too many clients or too less
   monitorMBean.setThresholds(new Integer(8), new Integer(4));
   // Setup the monitor: we want to know if a threshold is exceeded
   monitorMBean.setNotifyHigh(true);
   monitorMBean.setNotifyLow(true);
   // Setup the monitor: we're interested in absolute values of the number of clients
   monitorMBean.setDifferenceMode(false);
   // Setup the monitor: link to the service MBean
   monitorMBean.addObservedObject(serviceName);
   monitorMBean.setObservedAttribute("ConcurrentClients");
   // Setup the monitor: a short granularity period
   monitorMBean.setGranularityPeriod(50L);
   // Setup the monitor: register a listener
   monitorMBean.addNotificationListener(new NotificationListener()
   {
      public void handleNotification(Notification notification, Object handback)
      {
         System.out.println(notification);
      }
   }, null, null);
   // Setup the monitor: start it
   monitorMBean.start();

   // Now start also the service
   serviceMBean.start();
}
 
Example 2
Source File: ReflectionExceptionTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Wait for granularity period (multiplied by 2 for sure)
        //
        Thread.sleep(granularityperiod * 2);

        // Check if notification was received
        //
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 3
Source File: RuntimeExceptionTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Wait for granularity period (multiplied by 2 for sure)
        //
        Thread.sleep(granularityperiod * 2);

        // Check if notification was received
        //
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 4
Source File: ReflectionExceptionTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Wait for granularity period (multiplied by 2 for sure)
        //
        Thread.sleep(granularityperiod * 2);

        // Check if notification was received
        //
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 5
Source File: RuntimeExceptionTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Wait for granularity period (multiplied by 2 for sure)
        //
        Thread.sleep(granularityperiod * 2);

        // Check if notification was received
        //
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 6
Source File: ReflectionExceptionTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 7
Source File: RuntimeExceptionTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 8
Source File: ReflectionExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 9
Source File: RuntimeExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 10
Source File: ReflectionExceptionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 11
Source File: RuntimeExceptionTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 12
Source File: ReflectionExceptionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 13
Source File: RuntimeExceptionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 14
Source File: ReflectionExceptionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 15
Source File: RuntimeExceptionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 16
Source File: RuntimeExceptionTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 17
Source File: RuntimeExceptionTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 18
Source File: ReflectionExceptionTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 19
Source File: RuntimeExceptionTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}
 
Example 20
Source File: ReflectionExceptionTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

    GaugeMonitor gaugeMonitor = new GaugeMonitor();
    try {
        // Create a new GaugeMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new GaugeMonitor MBean");
        ObjectName gaugeMonitorName = new ObjectName(
                        domain + ":type=" + GaugeMonitor.class.getName());
        server.registerMBean(gaugeMonitor, gaugeMonitorName);

        echo(">>> ADD a listener to the GaugeMonitor");
        gaugeMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the GaugeMonitor:");

        gaugeMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        gaugeMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

        int granularityperiod = 500;
        gaugeMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: GaugeMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (gaugeMonitor != null)
            gaugeMonitor.stop();
    }

    return 0;
}