当前位置: 首页>>代码示例>>Java>>正文


Java MBeanServer.getDefaultDomain方法代码示例

本文整理汇总了Java中javax.management.MBeanServer.getDefaultDomain方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServer.getDefaultDomain方法的具体用法?Java MBeanServer.getDefaultDomain怎么用?Java MBeanServer.getDefaultDomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.management.MBeanServer的用法示例。


在下文中一共展示了MBeanServer.getDefaultDomain方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runTest

import javax.management.MBeanServer; //导入方法依赖的package包/类
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {


    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            server.registerMBean(monitored[i], mbeanNames[i]);
            switch (monitorType) {
            case 1:
                monitorNames[i] = new ObjectName(":type=CounterMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new CounterMonitor();
                break;
            case 2:
                monitorNames[i] = new ObjectName(":type=GaugeMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new GaugeMonitor();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
            monitor[i].start();
        }

        if (!waiter.waiting(MAX_WAITING_TIME)) {
            echo("Error, not all "+nTasks+" monitor tasks are called after "
                 +MAX_WAITING_TIME);
            return 1;
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    echo("All "+nTasks+" monitors are called.");
    return 0;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:67,代码来源:ThreadPoolTest.java

示例2: runTest

import javax.management.MBeanServer; //导入方法依赖的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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:77,代码来源:CounterMonitorThresholdTest.java


注:本文中的javax.management.MBeanServer.getDefaultDomain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。