本文整理汇总了Java中javax.management.monitor.GaugeMonitor.start方法的典型用法代码示例。如果您正苦于以下问题:Java GaugeMonitor.start方法的具体用法?Java GaugeMonitor.start怎么用?Java GaugeMonitor.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.monitor.GaugeMonitor
的用法示例。
在下文中一共展示了GaugeMonitor.start方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gaugeMonitorNotification
import javax.management.monitor.GaugeMonitor; //导入方法依赖的package包/类
/**
* 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;
}
示例2: main
import javax.management.monitor.GaugeMonitor; //导入方法依赖的package包/类
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();
}
示例3: gaugeMonitorNotification
import javax.management.monitor.GaugeMonitor; //导入方法依赖的package包/类
/**
* 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;
}