类javax.management.JMX源码实例Demo

下面列出了怎么用javax.management.JMX的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openjdk-jdk8u-backup   文件: TestUtils.java
/**
 * Transfroms a proxy implementing T in a proxy implementing T plus
 * NotificationEmitter
 *
 **/
public static <T> T makeNotificationEmitter(T proxy,
                    Class<T> mbeanInterface) {
    if (proxy instanceof NotificationEmitter)
        return proxy;
    if (proxy == null) return null;
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a "+Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler =
            Proxy.getInvocationHandler(proxy);
    if (!(handler instanceof MBeanServerInvocationHandler))
        throw new IllegalArgumentException("not a JMX Proxy");
    final MBeanServerInvocationHandler h =
            (MBeanServerInvocationHandler)handler;
    final ObjectName name = h.getObjectName();
    final MBeanServerConnection mbs = h.getMBeanServerConnection();
    final boolean isMXBean = h.isMXBean();
    final T newProxy;
    if (isMXBean)
        newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true);
    else
        newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true);
    return newProxy;
}
 
源代码2 项目: openjdk-8   文件: ExceptionDiagnosisTest.java
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);
        }
    }
}
 
源代码3 项目: dragonwell8_jdk   文件: ExceptionDiagnosisTest.java
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);
        }
    }
}
 
源代码4 项目: jdk8u_jdk   文件: JMXProxyFallbackTest.java
private static void testPrivate(Class<?> iface) throws Exception {
    try {
        System.out.println("Creating a proxy for private M(X)Bean " +
                            iface.getName() + " ...");

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

        JMX.newMBeanProxy(mbs, on, iface);
        success("Created a proxy for private M(X)Bean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("Proxy not created");
        } else {
            throw e;
        }
    }
}
 
源代码5 项目: TencentKona-8   文件: JMXProxyFallbackTest.java
private static void testPrivate(Class<?> iface) throws Exception {
    try {
        System.out.println("Creating a proxy for private M(X)Bean " +
                            iface.getName() + " ...");

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

        JMX.newMBeanProxy(mbs, on, iface);
        success("Created a proxy for private M(X)Bean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("Proxy not created");
        } else {
            throw e;
        }
    }
}
 
源代码6 项目: openjdk-8-source   文件: JMXProxyFallbackTest.java
private static void testPrivate(Class<?> iface) throws Exception {
    try {
        System.out.println("Creating a proxy for private M(X)Bean " +
                            iface.getName() + " ...");

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

        JMX.newMBeanProxy(mbs, on, iface);
        success("Created a proxy for private M(X)Bean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("Proxy not created");
        } else {
            throw e;
        }
    }
}
 
private void testAsUser() throws Exception {
    final SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
    final HashMap<String, Object> env = new HashMap<>(1);
    env.put(JMXConnector.CREDENTIALS, new Object[] { TestUsers.USER.username, TestUsers.USER.password });
    JMXConnector userJmxConnector = JMXConnectorFactory.connect(new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI)),
                                                                env);

    try {
        MBeanServerConnection connection = userJmxConnector.getMBeanServerConnection();
        final ObjectName beanName = new ObjectName(SchedulerJMXHelper.RUNTIMEDATA_MBEAN_NAME);
        RuntimeDataMBean bean = JMX.newMXBeanProxy(connection, beanName, RuntimeDataMBean.class);
        checkDataConsistent(bean);
    } finally {
        userJmxConnector.close();
    }
}
 
/**
 * Ensures that an {@code MBeanServerConnection} is configured and attempts
 * to detect a local connection if one is not supplied.
 */
public void prepare() {
	synchronized (this.preparationMonitor) {
		if (this.server != null) {
			this.serverToUse = this.server;
		}
		else {
			this.serverToUse = null;
			this.serverToUse = this.connector.connect(this.serviceUrl, this.environment, this.agentId);
		}
		this.invocationHandler = null;
		if (this.useStrictCasing) {
			Assert.state(this.objectName != null, "No ObjectName set");
			// Use the JDK's own MBeanServerInvocationHandler, in particular for native MXBean support.
			this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName,
					(this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
		}
		else {
			// Non-strict casing can only be achieved through custom invocation handling.
			// Only partial MXBean support available!
			retrieveMBeanInfo(this.serverToUse);
		}
	}
}
 
源代码9 项目: jdk8u60   文件: TestUtils.java
/**
 * Transfroms a proxy implementing T in a proxy implementing T plus
 * NotificationEmitter
 *
 **/
public static <T> T makeNotificationEmitter(T proxy,
                    Class<T> mbeanInterface) {
    if (proxy instanceof NotificationEmitter)
        return proxy;
    if (proxy == null) return null;
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a "+Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler =
            Proxy.getInvocationHandler(proxy);
    if (!(handler instanceof MBeanServerInvocationHandler))
        throw new IllegalArgumentException("not a JMX Proxy");
    final MBeanServerInvocationHandler h =
            (MBeanServerInvocationHandler)handler;
    final ObjectName name = h.getObjectName();
    final MBeanServerConnection mbs = h.getMBeanServerConnection();
    final boolean isMXBean = h.isMXBean();
    final T newProxy;
    if (isMXBean)
        newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true);
    else
        newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true);
    return newProxy;
}
 
源代码10 项目: jdk8u-jdk   文件: JMXProxyFallbackTest.java
private static void testPrivate(Class<?> iface) throws Exception {
    try {
        System.out.println("Creating a proxy for private M(X)Bean " +
                            iface.getName() + " ...");

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

        JMX.newMBeanProxy(mbs, on, iface);
        success("Created a proxy for private M(X)Bean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("Proxy not created");
        } else {
            throw e;
        }
    }
}
 
源代码11 项目: jdk8u60   文件: ExceptionDiagnosisTest.java
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);
        }
    }
}
 
源代码12 项目: spring-analysis-note   文件: JmxUtils.java
/**
 * Return the Java 6 MXBean interface exists for the given class, if any
 * (that is, an interface whose name ends with "MXBean" and/or
 * carries an appropriate MXBean annotation).
 * @param clazz the class to check
 * @return whether there is an MXBean interface for the given class
 */
@Nullable
public static Class<?> getMXBeanInterface(@Nullable Class<?> clazz) {
	if (clazz == null || clazz.getSuperclass() == null) {
		return null;
	}
	Class<?>[] implementedInterfaces = clazz.getInterfaces();
	for (Class<?> iface : implementedInterfaces) {
		if (JMX.isMXBeanInterface(iface)) {
			return iface;
		}
	}
	return getMXBeanInterface(clazz.getSuperclass());
}
 
源代码13 项目: stratio-cassandra   文件: NodeProbe.java
public EndpointSnitchInfoMBean getEndpointSnitchInfoProxy()
{
    try
    {
        return JMX.newMBeanProxy(mbeanServerConn, new ObjectName("org.apache.cassandra.db:type=EndpointSnitchInfo"), EndpointSnitchInfoMBean.class);
    }
    catch (MalformedObjectNameException e)
    {
        throw new RuntimeException(e);
    }
}
 
源代码14 项目: dragonwell8_jdk   文件: ScanManager.java
public ScanDirConfigMXBean createOtherConfigurationMBean(String name,
        String filename)
    throws JMException {
    final ScanDirConfig profile = new ScanDirConfig(filename);
    final ObjectName profName = makeScanDirConfigName(name);
    final ObjectInstance moi = mbeanServer.registerMBean(profile,profName);
    final ScanDirConfigMXBean proxy =
            JMX.newMXBeanProxy(mbeanServer,profName,
                ScanDirConfigMXBean.class,true);
    configmap.put(moi.getObjectName(),proxy);
    return proxy;
}
 
源代码15 项目: openjdk-jdk8u   文件: ScanManager.java
public ScanDirConfigMXBean createOtherConfigurationMBean(String name,
        String filename)
    throws JMException {
    final ScanDirConfig profile = new ScanDirConfig(filename);
    final ObjectName profName = makeScanDirConfigName(name);
    final ObjectInstance moi = mbeanServer.registerMBean(profile,profName);
    final ScanDirConfigMXBean proxy =
            JMX.newMXBeanProxy(mbeanServer,profName,
                ScanDirConfigMXBean.class,true);
    configmap.put(moi.getObjectName(),proxy);
    return proxy;
}
 
@Override
public Map.Entry<String, ColumnFamilyStoreMBean> next() {
  ObjectName objectName = resIter.next();
  String keyspaceName = objectName.getKeyProperty("keyspace");
  ColumnFamilyStoreMBean cfsProxy = JMX.newMBeanProxy(mbeanServerConn, objectName, ColumnFamilyStoreMBean.class);
  return new AbstractMap.SimpleImmutableEntry<>(keyspaceName, cfsProxy);
}
 
源代码17 项目: openjdk-jdk8u   文件: RandomMXBeanTest.java
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]);
    }
}
 
源代码18 项目: streamsx.topology   文件: Resetter.java
@Override
public void setup(MBeanServerConnection mbs, OperatorContext context) throws InstanceNotFoundException, Exception {
    seq.increment();
    
    ObjectName consistentWildcard = ObjectName.getInstance("com.ibm.streams.control:type=consistent,index=*");
    Set<ObjectName> regions = mbs.queryNames(consistentWildcard, null);
    
    if (regions.isEmpty()) {
        fail.setValue(1);
        trace.severe("No consistent regions!");
        return;
    }
        
    for (ObjectName name : regions) {            
        ConsistentRegionMXBean crbean = JMX.newMXBeanProxy(mbs, name,
                ConsistentRegionMXBean.class, true);
        
        if (trace.isLoggable(Level.FINE))               
            trace.fine("Discovered consistent region: " + crbean.getName());            
        
        String metricName = "nResets." + crbean.getName();
        Metric resetCount;
        try {
            resetCount = context.getMetrics().createCustomMetric(metricName, "Requested resets for region", Metric.Kind.COUNTER);                
        } catch (IllegalArgumentException e) {
            resetCount = context.getMetrics().getCustomMetric(metricName);
        }
        resetCounts.add(resetCount);
        
        scheduleReset(crbean, resetCount);
        seq.increment();
    }
}
 
源代码19 项目: jdk8u_jdk   文件: MXBeanInteropTest1.java
private final int doMemoryManagerMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- MemoryManagerMXBean") ;

    try {
        ObjectName filterName =
                new ObjectName(ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
                + ",*");
        Set<ObjectName> onSet = mbsc.queryNames(filterName, null);

        for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
            ObjectName memoryManagerName = iter.next() ;
            System.out.println("-------- " + memoryManagerName) ;
            MBeanInfo mbInfo = mbsc.getMBeanInfo(memoryManagerName);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            errorCount += checkNonEmpty(mbInfo);
            MemoryManagerMXBean memoryManager = null;

            memoryManager =
                    JMX.newMXBeanProxy(mbsc,
                    memoryManagerName,
                    MemoryManagerMXBean.class) ;
            System.out.println("getMemoryPoolNames\t\t"
                    + Arrays.deepToString(memoryManager.getMemoryPoolNames()));
            System.out.println("getName\t\t"
                    + memoryManager.getName());
            System.out.println("isValid\t\t"
                    + memoryManager.isValid());
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
源代码20 项目: dragonwell8_jdk   文件: RandomMXBeanTest.java
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]);
    }
}
 
源代码21 项目: openjdk-jdk8u   文件: MXBeanInteropTest1.java
private final int doGarbageCollectorMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- GarbageCollectorMXBean") ;

    try {
        ObjectName filterName =
                new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
                + ",*");
        Set<ObjectName> onSet = mbsc.queryNames(filterName, null);

        for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
            ObjectName garbageName = iter.next() ;
            System.out.println("-------- " + garbageName) ;
            MBeanInfo mbInfo = mbsc.getMBeanInfo(garbageName);
            errorCount += checkNonEmpty(mbInfo);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            GarbageCollectorMXBean garbage = null ;

            garbage =
                    JMX.newMXBeanProxy(mbsc,
                    garbageName,
                    GarbageCollectorMXBean.class) ;
            System.out.println("getCollectionCount\t\t"
                    + garbage.getCollectionCount());
            System.out.println("getCollectionTime\t\t"
                    + garbage.getCollectionTime());
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
源代码22 项目: javasimon   文件: MonitoringClient.java
/**
	 * Entry point to this monitoring client.
	 *
	 * @param args host:port part of the JMX connector server
	 * @throws java.io.IOException thrown in case of some I/O exception
	 * @throws javax.management.MalformedObjectNameException thrown when the name of the JMX object is incorrect
	 */
	public static void main(String[] args) throws IOException, MalformedObjectNameException {
		final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + args[0] + "/jmxrmi");

//		final Map<String, String[]> env = new HashMap<String, String[]>();
//		env.put(JMXConnector.CREDENTIALS, new String[]{login, pass});

		JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
		MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
		SimonManagerMXBean simonManagerMXBean = JMX.newMXBeanProxy(mbsc, new ObjectName("org.javasimon.jmx.example:type=Simon"), SimonManagerMXBean.class);

		System.out.println("List of retrieved Simons:");
		for (String n : simonManagerMXBean.getSimonNames()) {
			System.out.println("  " + n);
		}

		System.out.println("List of stopwatch Simons:");
		for (SimonInfo si : simonManagerMXBean.getSimonInfos()) {
			if (si.getType().equals(SimonInfo.STOPWATCH)) {
				System.out.println("  " + si.getName());
			}
		}

		simonManagerMXBean.printSimonTree();

		jmxc.close();
	}
 
源代码23 项目: dragonwell8_jdk   文件: MXBeanInteropTest1.java
private final int doMemoryMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- MemoryMXBean") ;

    try {
        ObjectName memoryName =
                new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(memoryName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t"
                + mbInfo);
        MemoryMXBean memory = null ;

        memory =
                JMX.newMXBeanProxy(mbsc,
                memoryName,
                MemoryMXBean.class,
                true) ;
        System.out.println("getMemoryHeapUsage\t\t"
                + memory.getHeapMemoryUsage());
        System.out.println("getNonHeapMemoryHeapUsage\t\t"
                + memory.getNonHeapMemoryUsage());
        System.out.println("getObjectPendingFinalizationCount\t\t"
                + memory.getObjectPendingFinalizationCount());
        System.out.println("isVerbose\t\t"
                + memory.isVerbose());

        System.out.println("---- OK\n") ;

    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
源代码24 项目: openjdk-8-source   文件: ScanManager.java
public ScanDirConfigMXBean createOtherConfigurationMBean(String name,
        String filename)
    throws JMException {
    final ScanDirConfig profile = new ScanDirConfig(filename);
    final ObjectName profName = makeScanDirConfigName(name);
    final ObjectInstance moi = mbeanServer.registerMBean(profile,profName);
    final ScanDirConfigMXBean proxy =
            JMX.newMXBeanProxy(mbeanServer,profName,
                ScanDirConfigMXBean.class,true);
    configmap.put(moi.getObjectName(),proxy);
    return proxy;
}
 
源代码25 项目: hottub   文件: ScanManager.java
public ScanDirConfigMXBean createOtherConfigurationMBean(String name,
        String filename)
    throws JMException {
    final ScanDirConfig profile = new ScanDirConfig(filename);
    final ObjectName profName = makeScanDirConfigName(name);
    final ObjectInstance moi = mbeanServer.registerMBean(profile,profName);
    final ScanDirConfigMXBean proxy =
            JMX.newMXBeanProxy(mbeanServer,profName,
                ScanDirConfigMXBean.class,true);
    configmap.put(moi.getObjectName(),proxy);
    return proxy;
}
 
源代码26 项目: jdk8u-jdk   文件: MXBeanInteropTest1.java
private final int doMemoryManagerMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- MemoryManagerMXBean") ;

    try {
        ObjectName filterName =
                new ObjectName(ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
                + ",*");
        Set<ObjectName> onSet = mbsc.queryNames(filterName, null);

        for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
            ObjectName memoryManagerName = iter.next() ;
            System.out.println("-------- " + memoryManagerName) ;
            MBeanInfo mbInfo = mbsc.getMBeanInfo(memoryManagerName);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            errorCount += checkNonEmpty(mbInfo);
            MemoryManagerMXBean memoryManager = null;

            memoryManager =
                    JMX.newMXBeanProxy(mbsc,
                    memoryManagerName,
                    MemoryManagerMXBean.class) ;
            System.out.println("getMemoryPoolNames\t\t"
                    + Arrays.deepToString(memoryManager.getMemoryPoolNames()));
            System.out.println("getName\t\t"
                    + memoryManager.getName());
            System.out.println("isValid\t\t"
                    + memoryManager.isValid());
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
源代码27 项目: stratio-cassandra   文件: NodeProbe.java
private List<Entry<String, ColumnFamilyStoreMBean>> getCFSMBeans(MBeanServerConnection mbeanServerConn, String type)
        throws MalformedObjectNameException, IOException
{
    ObjectName query = new ObjectName("org.apache.cassandra.db:type=" + type +",*");
    Set<ObjectName> cfObjects = mbeanServerConn.queryNames(query, null);
    List<Entry<String, ColumnFamilyStoreMBean>> mbeans = new ArrayList<Entry<String, ColumnFamilyStoreMBean>>(cfObjects.size());
    for(ObjectName n : cfObjects)
    {
        String keyspaceName = n.getKeyProperty("keyspace");
        ColumnFamilyStoreMBean cfsProxy = JMX.newMBeanProxy(mbeanServerConn, n, ColumnFamilyStoreMBean.class);
        mbeans.add(new AbstractMap.SimpleImmutableEntry<String, ColumnFamilyStoreMBean>(keyspaceName, cfsProxy));
    }
    return mbeans;
}
 
源代码28 项目: stratio-cassandra   文件: NodeProbe.java
public Map.Entry<String, JMXEnabledThreadPoolExecutorMBean> next()
{
    ObjectName objectName = resIter.next();
    String poolName = objectName.getKeyProperty("type");
    JMXEnabledThreadPoolExecutorMBean threadPoolProxy = JMX.newMBeanProxy(mbeanServerConn, objectName, JMXEnabledThreadPoolExecutorMBean.class);
    return new AbstractMap.SimpleImmutableEntry<String, JMXEnabledThreadPoolExecutorMBean>(poolName, threadPoolProxy);
}
 
@NotNull
private <T> T newProxy(final String name, final Class<T> type) {
    lock.lock();
    try {
        connect();
        return JMX.newMBeanProxy(mbeanServerConn, new ObjectName(name), type);
    } catch (final Exception e) {
        throw new JmxRuntimeException("Failed to create proxy for " + name, e);
    } finally {
        lock.unlock();
    }
}
 
源代码30 项目: gemfirexd-oss   文件: JmxOperationInvoker.java
public <T> T getMBeanProxy(final ObjectName objectName, final Class<T> mbeanInterface) {
  if (DistributedSystemMXBean.class.equals(mbeanInterface)
    && ManagementConstants.OBJECTNAME__DISTRIBUTEDSYSTEM_MXBEAN.equals(objectName.toString())) {
    return mbeanInterface.cast(getDistributedSystemMXBean());
  }
  else if (JMX.isMXBeanInterface(mbeanInterface)) {
    return JMX.newMXBeanProxy(getMBeanServerConnection(), objectName, mbeanInterface);
  }
  else {
    return JMX.newMBeanProxy(getMBeanServerConnection(), objectName, mbeanInterface);
  }
}
 
 类所在包
 同包方法