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


Java MBeanServerFactory.newMBeanServer方法代码示例

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


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

示例1: testNonCompliant

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
private static void testNonCompliant(Class<?> iface, Object bean) throws Exception {
    try {
        System.out.println("Registering a non-compliant MBean " +
                            iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=NonCompliant");

        mbs.registerMBean(bean, on);

        fail("Registered a non-compliant MBean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            success("MBean not registered");
        } else {
            throw e;
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:MBeanTest.java

示例2: testCompliant

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
private static void testCompliant(Class<?> iface, Object bean) throws Exception {
    try {
        System.out.println("Registering a compliant MBean " +
                            iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Compliant");

        mbs.registerMBean(bean, on);
        success("Registered a compliant MBean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("MBean not registered");
        } else {
            throw e;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:MBeanTest.java

示例3: testPrivate

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
private static void testPrivate(Class<?> iface, Object bean) throws Exception {
    try {
        System.out.println("Registering a private MBean " +
                            iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Compliant");

        mbs.registerMBean(bean, on);
        success("Registered a private MBean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("MBean not registered");
        } else {
            throw e;
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:MBeanFallbackTest.java

示例4: testCaseProb

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
private static void testCaseProb() throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    mbs.registerMBean(new CaseProbImpl(), name);
    CaseProbMXBean proxy = JMX.newMXBeanProxy(mbs, name, CaseProbMXBean.class);
    try {
        CaseProb prob = proxy.getCaseProb();
        fail("No exception from proxy method getCaseProb");
    } catch (IllegalArgumentException e) {
        String messageChain = messageChain(e);
        if (messageChain.contains("URLPath")) {
            System.out.println("Message chain contains URLPath as required: "
                    + messageChain);
        } else {
            fail("Exception chain for CaseProb does not mention property" +
                    " URLPath differing only in case");
            System.out.println("Full stack trace:");
            e.printStackTrace(System.out);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ExceptionDiagnosisTest.java

示例5: testNonCompliant

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
private static void testNonCompliant(Class<?> iface, boolean isMx) throws Exception {
    try {
        System.out.println("Creating a proxy for non-compliant " +
                           (isMx ? "MXBean" : "MBean") + " " +
                           iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Proxy");

        if (isMx) {
            JMX.newMXBeanProxy(mbs, on, iface);
        } else {
            JMX.newMBeanProxy(mbs, on, iface);
        }
        fail("Created a proxy for non-compliant " +
             (isMx ? "MXBean" : "MBean") + " - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            success("Proxy not created");
        } else {
            throw e;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:JMXProxyTest.java

示例6: call

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public MBeanServerConnection call() {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    try {
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
        JMXConnectorServer cs =
            JMXConnectorServerFactory.newJMXConnectorServer(
                url, null, mbs);
        cs.start();
        JMXServiceURL addr = cs.getAddress();
        connector = JMXConnectorFactory.connect(addr);
        return connector.getMBeanServerConnection();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:OldMBeanServerTest.java

示例7: testIndirectMXBean

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
private static void testIndirectMXBean() throws Exception {
    System.out.println("Indirect MXBean test...");
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName on = new ObjectName("test:type=Indirect");
    Indirect indirect = new Indirect();
    mbs.registerMBean(indirect, on);
    testMXBean(mbs, on);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:MXBeanTest.java

示例8: main

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    StupidMXBean stupid = new StupidImpl();
    mbs.registerMBean(stupid, name);
    ObjectName referName = new ObjectName("a:c=d");
    mbs.registerMBean(new ReferImpl(stupid), referName);
    System.out.println(mbs.getMBeanInfo(name));
    StupidMXBean stupid2 = (StupidMXBean)
            Proxy.newProxyInstance(StupidMXBean.class.getClassLoader(),
                new Class<?>[] {StupidMXBean.class},
                new WrapInvocationHandler(stupid));
    ObjectName stupidName2 = new ObjectName("a:d=e");
    mbs.registerMBean(stupid2, stupidName2);
    Field zero = StupidMXBean.class.getField("ZERO");
    System.out.println("Zero field = " + zero.get(null));
    test(mbs, MerlinMXBean.class);
    test(mbs, TigerMXBean.class);

    StupidMXBean proxy = JMX.newMXBeanProxy(mbs, name, StupidMXBean.class);
    System.out.println("Zero = " + proxy.getZero());
    System.out.println("One = " + proxy.identity(1));
    ReferMXBean referProxy =
            JMX.newMXBeanProxy(mbs, referName, ReferMXBean.class);
    StupidMXBean stupidProxy2 = referProxy.getStupid();
    System.out.println("Same proxy: " + (proxy == stupidProxy2));
    Method[] methods = StupidMXBean.class.getMethods();
    for (Method method : methods) {
        if (method.getParameterTypes().length == 0)
            method.invoke(proxy, new Object[0]);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:RandomMXBeanTest.java

示例9: main

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    mbs.registerMBean(new TestImpl(), name);

    for (String attr : new String[] {"SortedSet", "SortedMap"}) {
        try {
            Object value = mbs.getAttribute(name, attr);
            fail("get " + attr + " did not throw exception");
        } catch (Exception e) {
            Throwable t = e;
            while (!(t instanceof IllegalArgumentException)) {
                if (t == null)
                    break;
                t = t.getCause();
            }
            if (t != null)
                System.out.println("Correct exception for " + attr);
            else {
                fail("get " + attr + " got wrong exception");
                e.printStackTrace(System.out);
            }
        }
    }

    if (failure != null)
        throw new Exception(failure);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ComparatorExceptionTest.java

示例10: testExplicitMXBean

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
private static void testExplicitMXBean() throws Exception {
    System.out.println("Explicit MXBean test...");
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName on = new ObjectName("test:type=Explicit");
    Explicit explicit = new Explicit();
    mbs.registerMBean(explicit, on);
    testMXBean(mbs, on);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:MXBeanTest.java

示例11: testSubclassMXBean

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
private static void testSubclassMXBean() throws Exception {
    System.out.println("Subclass MXBean test...");
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName on = new ObjectName("test:type=Subclass");
    Subclass subclass = new Subclass();
    mbs.registerMBean(subclass, on);
    testMXBean(mbs, on);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:MXBeanTest.java

示例12: createServerSide

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
private JMXServiceURL createServerSide(Map<String, Object> serverMap)
throws Exception {
    final int NINETY_SECONDS = 90;

    System.out.println("AuthorizationTest::createServerSide: Start") ;

    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);

    // Creates connection environment from server side params
    HashMap<String, Object> env = new HashMap<>();
    String value = null;

    if ((value = (String)serverMap.get("-mapType")) != null) {
        if (value.contains("x.access.file")) {
            String accessFileStr = System.getProperty("test.src") +
                File.separator + "access.properties";
            env.put("jmx.remote.x.access.file", accessFileStr);
            System.out.println("Added " + accessFileStr + " file as jmx.remote.x.access.file");
        }
        if (value.contains("x.password.file")) {
            String passwordFileStr = System.getProperty("test.src") +
                File.separator + "password.properties";
            env.put("jmx.remote.x.password.file", passwordFileStr);
            System.out.println("Added " + passwordFileStr + " file as jmx.remote.x.password.file");
        }
    }

    if (serverMap.containsKey("-populate")) {
        String populateClassName = "Simple";
        ObjectName on =
            new ObjectName("defaultDomain:class=Simple");

        Utils.debug(Utils.DEBUG_STANDARD, "create and register Simple MBean") ;
        mbs.createMBean(populateClassName, on);
    }

    cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
    cs.start();

    Utils.waitReady(cs, NINETY_SECONDS);

    JMXServiceURL addr = cs.getAddress();

    System.out.println("AuthorizationTest::createServerSide: Done.") ;

    return addr;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:AuthorizationTest.java

示例13: main

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:60,代码来源:RelationNotificationSeqNoTest.java

示例14: runTest

import javax.management.MBeanServerFactory; //导入方法依赖的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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:67,代码来源:ThreadPoolTest.java

示例15: main

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName pointName = new ObjectName("a:type=Point");
    PointMXBean pointmx = new PointImpl();
    mbs.registerMBean(pointmx, pointName);
    Point point = new Point(1, 2);
    PointMXBean pointproxy =
        JMX.newMXBeanProxy(mbs, pointName, PointMXBean.class);
    Point point1 = pointproxy.identity(point);
    if (point1.getX() != point.getX() || point1.getY() != point.getY())
        throw new Exception("Point doesn't match");
    System.out.println("Point test passed");

    ObjectName evolveName = new ObjectName("a:type=Evolve");
    EvolveMXBean evolvemx = new EvolveImpl();
    mbs.registerMBean(evolvemx, evolveName);
    Evolve evolve =
        new Evolve(59, "tralala", Collections.singletonList("tiddly"));
    EvolveMXBean evolveProxy =
        JMX.newMXBeanProxy(mbs, evolveName, EvolveMXBean.class);
    Evolve evolve1 = evolveProxy.identity(evolve);
    if (evolve1.getOldInt() != evolve.getOldInt()
            || !evolve1.getNewString().equals(evolve.getNewString())
            || !evolve1.getNewerList().equals(evolve.getNewerList()))
        throw new Exception("Evolve doesn't match");
    System.out.println("Evolve test passed");

    ObjectName evolvedName = new ObjectName("a:type=Evolved");
    EvolveMXBean evolvedmx = new EvolveImpl();
    mbs.registerMBean(evolvedmx, evolvedName);
    CompositeType evolvedType =
        new CompositeType("Evolved", "descr", new String[] {"oldInt"},
                          new String[] {"oldInt descr"},
                          new OpenType[] {SimpleType.INTEGER});
    CompositeData evolvedData =
        new CompositeDataSupport(evolvedType, new String[] {"oldInt"},
                                 new Object[] {5});
    CompositeData evolved1 = (CompositeData)
        mbs.invoke(evolvedName, "identity", new Object[] {evolvedData},
                   new String[] {CompositeData.class.getName()});
    if ((Integer) evolved1.get("oldInt") != 5
            || !evolved1.get("newString").equals("defaultString")
            || ((String[]) evolved1.get("newerList")).length != 0)
        throw new Exception("Evolved doesn't match: " + evolved1);
    System.out.println("Evolved test passed");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:47,代码来源:PropertyNamesTest.java


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