本文整理汇总了Java中javax.management.monitor.CounterMonitorMBean.setOffset方法的典型用法代码示例。如果您正苦于以下问题:Java CounterMonitorMBean.setOffset方法的具体用法?Java CounterMonitorMBean.setOffset怎么用?Java CounterMonitorMBean.setOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.monitor.CounterMonitorMBean
的用法示例。
在下文中一共展示了CounterMonitorMBean.setOffset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runTest
import javax.management.monitor.CounterMonitorMBean; //导入方法依赖的package包/类
public static void runTest(int offset,
int counter[],
int derivedGauge[],
int threshold[]) throws Exception {
// Retrieve the platform MBean server
//
System.out.println("\nRetrieve the platform MBean server");
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
String domain = mbs.getDefaultDomain();
// Create and register TestMBean
//
ObjectName name =
new ObjectName(domain +
":type=" + Test.class.getName() +
",offset=" + offset);
mbs.createMBean(Test.class.getName(), name);
TestMBean mbean = (TestMBean)
MBeanServerInvocationHandler.newProxyInstance(
mbs, name, TestMBean.class, false);
// Create and register CounterMonitorMBean
//
ObjectName cmn =
new ObjectName(domain +
":type=" + CounterMonitor.class.getName() +
",offset=" + offset);
CounterMonitor m = new CounterMonitor();
mbs.registerMBean(m, cmn);
CounterMonitorMBean cm = (CounterMonitorMBean)
MBeanServerInvocationHandler.newProxyInstance(
mbs, cmn, CounterMonitorMBean.class, true);
((NotificationEmitter) cm).addNotificationListener(
new Listener(), null, null);
cm.addObservedObject(name);
cm.setObservedAttribute("Counter");
cm.setGranularityPeriod(100);
cm.setInitThreshold(1);
cm.setOffset(offset);
cm.setModulus(5);
cm.setNotify(true);
// Start the monitor
//
System.out.println("\nStart monitoring...");
cm.start();
// Play with counter
//
for (int i = 0; i < counter.length; i++) {
mbean.setCounter(counter[i]);
System.out.println("\nCounter = " + mbean.getCounter());
Integer derivedGaugeValue;
// either pass or test timeout (killed by test harness)
// see 8025207
do {
Thread.sleep(150);
derivedGaugeValue = (Integer) cm.getDerivedGauge(name);
} while (derivedGaugeValue.intValue() != derivedGauge[i]);
Number thresholdValue = cm.getThreshold(name);
System.out.println("Threshold = " + thresholdValue);
if (thresholdValue.intValue() != threshold[i]) {
System.out.println("Wrong threshold! Current value = " +
thresholdValue + " Expected value = " + threshold[i]);
System.out.println("\nStop monitoring...");
cm.stop();
throw new IllegalArgumentException("wrong threshold");
}
}
// Stop the monitor
//
System.out.println("\nStop monitoring...");
cm.stop();
}
示例2: runTest
import javax.management.monitor.CounterMonitorMBean; //导入方法依赖的package包/类
public static void runTest(int offset,
int counter[],
int derivedGauge[],
int threshold[]) throws Exception {
// Retrieve the platform MBean server
//
System.out.println("\nRetrieve the platform MBean server");
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
String domain = mbs.getDefaultDomain();
// Create and register TestMBean
//
ObjectName name =
new ObjectName(domain +
":type=" + Test.class.getName() +
",offset=" + offset);
mbs.createMBean(Test.class.getName(), name);
TestMBean mbean = (TestMBean)
MBeanServerInvocationHandler.newProxyInstance(
mbs, name, TestMBean.class, false);
// Create and register CounterMonitorMBean
//
ObjectName cmn =
new ObjectName(domain +
":type=" + CounterMonitor.class.getName() +
",offset=" + offset);
CounterMonitor m = new CounterMonitor();
mbs.registerMBean(m, cmn);
CounterMonitorMBean cm = (CounterMonitorMBean)
MBeanServerInvocationHandler.newProxyInstance(
mbs, cmn, CounterMonitorMBean.class, true);
((NotificationEmitter) cm).addNotificationListener(
new Listener(), null, null);
cm.addObservedObject(name);
cm.setObservedAttribute("Counter");
cm.setGranularityPeriod(100);
cm.setInitThreshold(1);
cm.setOffset(offset);
cm.setModulus(5);
cm.setNotify(true);
// Start the monitor
//
System.out.println("\nStart monitoring...");
cm.start();
// Play with counter
//
for (int i = 0; i < counter.length; i++) {
mbean.setCounter(counter[i]);
System.out.println("\nCounter = " + mbean.getCounter());
Thread.sleep(300);
Integer derivedGaugeValue = (Integer) cm.getDerivedGauge(name);
System.out.println("Derived Gauge = " + derivedGaugeValue);
if (derivedGaugeValue.intValue() != derivedGauge[i]) {
System.out.println("Wrong derived gauge! Current value = " +
derivedGaugeValue + " Expected value = " + derivedGauge[i]);
System.out.println("\nStop monitoring...");
cm.stop();
throw new IllegalArgumentException("wrong derived gauge");
}
Number thresholdValue = cm.getThreshold(name);
System.out.println("Threshold = " + thresholdValue);
if (thresholdValue.intValue() != threshold[i]) {
System.out.println("Wrong threshold! Current value = " +
thresholdValue + " Expected value = " + threshold[i]);
System.out.println("\nStop monitoring...");
cm.stop();
throw new IllegalArgumentException("wrong threshold");
}
Thread.sleep(300);
}
// Stop the monitor
//
System.out.println("\nStop monitoring...");
cm.stop();
}