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


Java Monitor.start方法代码示例

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


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

示例1: main

import javax.management.monitor.Monitor; //导入方法依赖的package包/类
public static void main (String args[]) throws Exception {

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

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

            for (int i = 0; i < 6; i++) {
                mbeanNames[i] =
                    new ObjectName(":type=ObservedObject,instance=" + i);
                monitored[i] = new ObservedObject();
                echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
                server.registerMBean(monitored[i], mbeanNames[i]);

                switch (i) {
                    case 0:
                    case 3:
                        monitorNames[i] =
                            new ObjectName(":type=CounterMonitor,instance=" + i);
                        monitor[i] = new CounterMonitor();
                        break;
                    case 1:
                    case 4:
                        monitorNames[i] =
                            new ObjectName(":type=GaugeMonitor,instance=" + i);
                        monitor[i] = new GaugeMonitor();
                        break;
                    case 2:
                    case 5:
                        monitorNames[i] =
                            new ObjectName(":type=StringMonitor,instance=" + i);
                        monitor[i] = new StringMonitor();
                        break;
                }

                echo(">>> CREATE Monitor = " + monitorNames[i].toString());
                server.registerMBean(monitor[i], monitorNames[i]);
                monitor[i].addObservedObject(mbeanNames[i]);
                monitor[i].setObservedAttribute(attributes[i % 3]);
                monitor[i].setGranularityPeriod(500);
                final Monitor m = monitor[i];
                Subject subject = new Subject();
                echo(">>> RUN Principal = " + principals[i / 3]);
                subject.getPrincipals().add(new JMXPrincipal(principals[i / 3]));
                PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
                    public Void run() {
                        m.start();
                        return null;
                    }
                };
                Subject.doAs(subject, action);
            }

            while(!testPrincipals(monitored, monitorNames, monitor, principals));

        } finally {
            for (int i = 0; i < 6; i++)
                if (monitor[i] != null)
                    monitor[i].stop();
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:68,代码来源:ThreadPoolAccTest.java

示例2: addNotificationListener

import javax.management.monitor.Monitor; //导入方法依赖的package包/类
@Override
protected void addNotificationListener() throws Exception {
    
    JMXEndpoint ep = (JMXEndpoint) getEndpoint();
    // create the monitor bean
    Monitor bean = null;
    if (ep.getMonitorType().equals("counter")) {
        CounterMonitor counter = new CounterMonitor();
        Number initThreshold = convertNumberToAttributeType(ep.getInitThreshold(), ep.getJMXObjectName(), ep.getObservedAttribute());
        Number offset = convertNumberToAttributeType(ep.getOffset(), ep.getJMXObjectName(), ep.getObservedAttribute());
        Number modulus = convertNumberToAttributeType(ep.getModulus(), ep.getJMXObjectName(), ep.getObservedAttribute());
        counter.setInitThreshold(initThreshold);
        counter.setOffset(offset);
        counter.setModulus(modulus);
        counter.setDifferenceMode(ep.isDifferenceMode());
        counter.setNotify(true);
        bean = counter;
    } else if (ep.getMonitorType().equals("gauge")) {
        GaugeMonitor gm = new GaugeMonitor();
        gm.setNotifyHigh(ep.isNotifyHigh());
        gm.setNotifyLow(ep.isNotifyLow());
        gm.setDifferenceMode(ep.isDifferenceMode());
        Number highValue = convertNumberToAttributeType(ep.getThresholdHigh(), ep.getJMXObjectName(), ep.getObservedAttribute());
        Number lowValue = convertNumberToAttributeType(ep.getThresholdLow(), ep.getJMXObjectName(), ep.getObservedAttribute());
        gm.setThresholds(highValue, lowValue);
        bean = gm;
    } else if (ep.getMonitorType().equals("string")) {
        StringMonitor sm = new StringMonitor();
        sm.setNotifyDiffer(ep.isNotifyDiffer());
        sm.setNotifyMatch(ep.isNotifyMatch());
        sm.setStringToCompare(ep.getStringToCompare());
        bean = sm;
    }
    
    bean.addObservedObject(ep.getJMXObjectName());
    bean.setObservedAttribute(ep.getObservedAttribute());
    bean.setGranularityPeriod(ep.getGranularityPeriod());

    // register the bean
    mMonitorObjectName = new ObjectName(ep.getObjectDomain(), "name", "camel-jmx-monitor-" + UUID.randomUUID());
    ManagementFactory.getPlatformMBeanServer().registerMBean(bean, mMonitorObjectName); 
    
    // add ourselves as a listener to it
    NotificationFilter nf = ep.getNotificationFilter();
    getServerConnection().addNotificationListener(mMonitorObjectName, this, nf, bean);
    bean.start();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:48,代码来源:JMXMonitorConsumer.java


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