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


Java JMX类代码示例

本文整理汇总了Java中javax.management.JMX的典型用法代码示例。如果您正苦于以下问题:Java JMX类的具体用法?Java JMX怎么用?Java JMX使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getSimonProxyBean

import javax.management.JMX; //导入依赖的package包/类
private SimonManagerMXBean getSimonProxyBean (
												MBeanServerConnection mbeanConn,
												ServiceCollectionResults collectionResults ) {

	SimonManagerMXBean simonMgrMxBean = null;

	ServiceInstance service = collectionResults.getServiceInstance();
	if ( service.getSimonMbean().length() > 0 ) {

		try {
			simonMgrMxBean = JMX.newMXBeanProxy(
				mbeanConn, new ObjectName(
					collectionResults.getServiceInstance().getSimonMbean() ),
				SimonManagerMXBean.class );
		} catch (Exception e) {
			logger.warn( "Failed to get simon proxy", CSAP.getCsapFilteredStackTrace( e ) );
		}

	}

	logger.debug( "{} type: {} Simon mbean name: {} ",
		service.getServiceName(), service.getServerType(), service.getSimonMbean() );

	return simonMgrMxBean;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:26,代码来源:ServiceCollector.java

示例2: getMemberMXBean

import javax.management.JMX; //导入依赖的package包/类
/**
 * Gets the MemberMXBean from the JVM Platform MBeanServer for the specified member, identified by
 * name or ID in the GemFire cluster.
 * 
 * @param memberNameId a String indicating the name or ID of the GemFire member.
 * @return a proxy to the GemFire member's MemberMXBean.
 * @throws IllegalStateException if no MemberMXBean could be found for GemFire member with ID or
 *         name.
 * @throws RuntimeException wrapping the MalformedObjectNameException if the ObjectName pattern is
 *         malformed.
 * @see #getMBeanServer()
 * @see #isMemberMXBeanFound(java.util.Collection)
 * @see javax.management.ObjectName
 * @see javax.management.QueryExp
 * @see javax.management.MBeanServer#queryNames(javax.management.ObjectName,
 *      javax.management.QueryExp)
 * @see javax.management.JMX#newMXBeanProxy(javax.management.MBeanServerConnection,
 *      javax.management.ObjectName, Class)
 * @see org.apache.geode.management.MemberMXBean
 */
protected MemberMXBean getMemberMXBean(final String memberNameId) {
  try {
    final MBeanServer connection = getMBeanServer();

    final String objectNamePattern =
        ManagementConstants.OBJECTNAME__PREFIX.concat("type=Member,*");

    // NOTE throws a MalformedObjectNameException, but this should not happen since we constructed
    // the ObjectName above
    final ObjectName objectName = ObjectName.getInstance(objectNamePattern);

    final QueryExp query = Query.or(Query.eq(Query.attr("Name"), Query.value(memberNameId)),
        Query.eq(Query.attr("Id"), Query.value(memberNameId)));

    final Set<ObjectName> objectNames = connection.queryNames(objectName, query);

    assertState(isMemberMXBeanFound(objectNames),
        "No MemberMXBean with ObjectName (%1$s) based on Query (%2$s) was found in the Platform MBeanServer for member (%3$s)!",
        objectName, query, memberNameId);

    return JMX.newMXBeanProxy(connection, objectNames.iterator().next(), MemberMXBean.class);
  } catch (MalformedObjectNameException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:46,代码来源:AbstractCommandsController.java

示例3: getManagingMemberMXBean

import javax.management.JMX; //导入依赖的package包/类
/**
 * Lookup operation for the MemberMXBean representing the Manager in the GemFire cluster. This
 * method gets an instance fo the Platform MBeanServer for this JVM process and uses it to lookup
 * the MemberMXBean for the GemFire Manager based on the ObjectName declared in the
 * DistributedSystemMXBean.getManagerObjectName() operation.
 * 
 * @return a proxy instance to the MemberMXBean of the GemFire Manager.
 * @see #getMBeanServer()
 * @see #createMemberMXBeanForManagerUsingProxy(javax.management.MBeanServer,
 *      javax.management.ObjectName)
 * @see org.apache.geode.management.DistributedSystemMXBean
 * @see org.apache.geode.management.MemberMXBean
 */
protected synchronized MemberMXBean getManagingMemberMXBean() {
  if (managingMemberMXBeanProxy == null) {
    SystemManagementService service = (SystemManagementService) ManagementService
        .getExistingManagementService(GemFireCacheImpl.getInstance());
    MBeanServer mbs = getMBeanServer();

    final DistributedSystemMXBean distributedSystemMXBean = JMX.newMXBeanProxy(mbs,
        MBeanJMXAdapter.getDistributedSystemName(), DistributedSystemMXBean.class);

    managingMemberMXBeanProxy = createMemberMXBeanForManagerUsingProxy(mbs,
        distributedSystemMXBean.getMemberObjectName());
  }

  return managingMemberMXBeanProxy;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:29,代码来源:AbstractCommandsController.java

示例4: newProxyInstance

import javax.management.JMX; //导入依赖的package包/类
/**
 * 
 * @param member member to which this MBean belongs
 * @param monitoringRegion corresponding MonitoringRegion
 * @param objectName ObjectName of the MBean
 * @param interfaceClass on which interface the proxy to be exposed
 * @return Object
 * @throws ClassNotFoundException
 * @throws IntrospectionException
 */
public static Object newProxyInstance(DistributedMember member,
    Region<String, Object> monitoringRegion, ObjectName objectName, Class interfaceClass)
    throws ClassNotFoundException, IntrospectionException {
  boolean isMXBean = JMX.isMXBeanInterface(interfaceClass);
  boolean notificationBroadcaster =
      ((FederationComponent) monitoringRegion.get(objectName.toString())).isNotificationEmitter();

  InvocationHandler handler =
      new MBeanProxyInvocationHandler(member, objectName, monitoringRegion, isMXBean);

  Class[] interfaces;

  if (notificationBroadcaster) {
    interfaces =
        new Class[] {interfaceClass, ProxyInterface.class, NotificationBroadCasterProxy.class};
  } else {
    interfaces = new Class[] {interfaceClass, ProxyInterface.class};
  }

  Object proxy = Proxy.newProxyInstance(MBeanProxyInvocationHandler.class.getClassLoader(),
      interfaces, handler);

  return interfaceClass.cast(proxy);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:35,代码来源:MBeanProxyInvocationHandler.java

示例5: getProxyMBean

import javax.management.JMX; //导入依赖的package包/类
/**
 * Retrieve a new proxy MBean
 *
 * @return A new proxy MBean of the same type with which the class was constructed
 */
public <T> T getProxyMBean(Class<T> proxyClass, String beanQueryName)
    throws MalformedObjectNameException, IOException {
  ObjectName name = null;
  QueryExp query = null;

  if (proxyClass != null) {
    query = Query.isInstanceOf(Query.value(proxyClass.getName()));
  }

  if (beanQueryName != null) {
    name = ObjectName.getInstance(beanQueryName);
  }

  Set<ObjectInstance> beans = con.queryMBeans(name, query);
  assertEquals("failed to find only one instance of type " + proxyClass.getName() + " with name "
      + beanQueryName, 1, beans.size());

  return JMX.newMXBeanProxy(con, ((ObjectInstance) beans.toArray()[0]).getObjectName(),
      proxyClass);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:26,代码来源:MBeanServerConnectionRule.java

示例6: makeNotificationEmitter

import javax.management.JMX; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:TestUtils.java

示例7: testPrivate

import javax.management.JMX; //导入依赖的package包/类
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;
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:JMXProxyFallbackTest.java

示例8: testCaseProb

import javax.management.JMX; //导入依赖的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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:ExceptionDiagnosisTest.java

示例9: test

import javax.management.JMX; //导入依赖的package包/类
private static <T> void test(MBeanServer mbs, Class<T> c) throws Exception {
    System.out.println("Testing " + c.getName());
    T merlin = c.cast(
        Proxy.newProxyInstance(c.getClassLoader(),
            new Class<?>[] {c},
            new DullInvocationHandler()));
    ObjectName merlinName = new ObjectName("a:type=" + c.getName());
    mbs.registerMBean(merlin, merlinName);
    System.out.println(mbs.getMBeanInfo(merlinName));
    T merlinProxy = JMX.newMXBeanProxy(mbs, merlinName, c);
    Method[] merlinMethods = c.getMethods();
    for (Method m : merlinMethods) {
        Class<?>[] types = m.getParameterTypes();
        Object[] params = new Object[types.length];
        for (int i = 0; i < types.length; i++)
            params[i] = DullInvocationHandler.zeroFor(types[i]);
        System.out.println("Invoking " + m.getName());
        m.invoke(merlinProxy, (Object[]) params);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:RandomMXBeanTest.java

示例10: testReadAttributes

import javax.management.JMX; //导入依赖的package包/类
@Test
public void testReadAttributes() throws Exception {
    DynamicMBean proxy = JMX.newMBeanProxy(platformMBeanServer, threadPoolDynamicWrapperON, DynamicMBean.class);

    assertEquals(threadCount, proxy.getAttribute(THREAD_COUNT));

    assertEquals(threadPoolConfigBean.isTriggerNewInstanceCreation(),
            proxy.getAttribute(TRIGGER_NEW_INSTANCE_CREATION));

    AttributeList attributes = proxy.getAttributes(new String[] { THREAD_COUNT, TRIGGER_NEW_INSTANCE_CREATION });
    assertEquals(2, attributes.size());
    Attribute threadCountAttr = (Attribute) attributes.get(0);
    assertEquals(THREAD_COUNT, threadCountAttr.getName());
    assertEquals(threadCount, threadCountAttr.getValue());
    Attribute boolTestAttr = (Attribute) attributes.get(1);
    assertEquals(TRIGGER_NEW_INSTANCE_CREATION, boolTestAttr.getName());
    assertEquals(threadPoolConfigBean.isTriggerNewInstanceCreation(), boolTestAttr.getValue());

    MBeanInfo beanInfo = proxy.getMBeanInfo();
    assertEquals(2, beanInfo.getAttributes().length);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:AbstractDynamicWrapperTest.java

示例11: testSetAttribute

import javax.management.JMX; //导入依赖的package包/类
@Test
public void testSetAttribute() throws Exception {
    DynamicMBean proxy = JMX.newMBeanProxy(platformMBeanServer, threadPoolDynamicWrapperON, DynamicMBean.class);

    proxy.setAttribute(new Attribute(THREAD_COUNT, newThreadCount));

    assertEquals(newThreadCount, proxy.getAttribute(THREAD_COUNT));
    assertEquals(newThreadCount, threadPoolConfigBean.getThreadCount());

    AttributeList attributeList = new AttributeList();
    attributeList.add(new Attribute(THREAD_COUNT, threadCount));
    boolean bool = true;
    attributeList.add(new Attribute(TRIGGER_NEW_INSTANCE_CREATION, bool));
    proxy.setAttributes(attributeList);

    assertEquals(threadCount, threadPoolConfigBean.getThreadCount());
    assertEquals(bool, threadPoolConfigBean.isTriggerNewInstanceCreation());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:19,代码来源:DynamicWritableWrapperTest.java

示例12: testObjectNameSetterWithONContainingTransaction_shouldBeTranslatedToReadOnlyON

import javax.management.JMX; //导入依赖的package包/类
@Test
public void testObjectNameSetterWithONContainingTransaction_shouldBeTranslatedToReadOnlyON() throws Exception {
    TestingParallelAPSPModuleFactory testingParallelAPSPConfigBeanFactory = new TestingParallelAPSPModuleFactory();
    TestingParallelAPSPModule apspConfigBean = testingParallelAPSPConfigBeanFactory.createModule("", null, null);
    ModuleIdentifier moduleIdentifier2 = new ModuleIdentifier("apsp", "parallel");
    ObjectName dynON2 = ObjectNameUtil.createReadOnlyModuleON(moduleIdentifier2);
    AbstractDynamicWrapper dyn = getDynamicWrapper(apspConfigBean, moduleIdentifier2);
    platformMBeanServer.registerMBean(dyn, dynON2);
    try {
        TestingParallelAPSPConfigMXBean proxy = JMX.newMBeanProxy(platformMBeanServer, dynON2,
                TestingParallelAPSPConfigMXBean.class);
        ObjectName withTransactionName = ObjectNameUtil.createTransactionModuleON("transaction1", "moduleName",
                "instanceName");
        proxy.setThreadPool(withTransactionName);
        ObjectName withoutTransactionName = ObjectNameUtil.withoutTransactionName(withTransactionName);
        assertEquals(withoutTransactionName, proxy.getThreadPool());
    } finally {
        platformMBeanServer.unregisterMBean(dynON2);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:21,代码来源:DynamicWritableWrapperTest.java

示例13: getJmxMetric

import javax.management.JMX; //导入依赖的package包/类
public static Object getJmxMetric(MBeanServerConnection mbeanServerConn, String jmxPath, String poolName, String metricName)
{
    String name = String.format("org.apache.cassandra.metrics:type=ThreadPools,path=%s,scope=%s,name=%s", jmxPath, poolName, metricName);

    try
    {
        ObjectName oName = new ObjectName(name);
        if (!mbeanServerConn.isRegistered(oName))
        {
            return "N/A";
        }

        switch (metricName)
        {
            case "ActiveTasks":
            case "PendingTasks":
            case "CompletedTasks":
                return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.JmxGaugeMBean.class).getValue();
            case "TotalBlockedTasks":
            case "CurrentlyBlockedTasks":
                return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.JmxCounterMBean.class).getCount();
            default:
                throw new AssertionError("Unknown metric name " + metricName);
        }
    }
    catch (Exception e)
    {
        throw new RuntimeException("Error reading: " + name, e);
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:31,代码来源:ThreadPoolMetrics.java

示例14: registerOrGetJmxBean

import javax.management.JMX; //导入依赖的package包/类
private RedisThrottlerJmxBean registerOrGetJmxBean() {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        synchronized (jmxBeanReferenceCountByName) {

            // Get the reference count for the JMX bean.
            Integer jmxBeanReferenceCount = jmxBeanReferenceCountByName.get(jmxBeanName);
            if (jmxBeanReferenceCount == null) {
                jmxBeanReferenceCount = 0;
            }

            // Create or get the JMX bean.
            RedisThrottlerJmxBean jmxBean;
            try {
                jmxBean = new RedisThrottlerInternalJmxBean();
                StandardMBean jmxBeanWrapper = new StandardMBean(jmxBean, RedisThrottlerJmxBean.class);
                mbs.registerMBean(jmxBeanWrapper, jmxBeanName);
            } catch (InstanceAlreadyExistsException ignored) {
                jmxBean = JMX.newMBeanProxy(mbs, jmxBeanName, RedisThrottlerJmxBean.class);
            }

            // Increment the reference count and return the JMX bean.
            jmxBeanReferenceCountByName.put(jmxBeanName, jmxBeanReferenceCount + 1);
            return jmxBean;

        }
    } catch (Throwable error) {
        String message = String.format("failed accessing the JMX bean (jmxBeanName=%s)", jmxBeanName);
        throw new RuntimeException(message, error);
    }
}
 
开发者ID:vy,项目名称:log4j2-redis-appender,代码行数:32,代码来源:RedisThrottler.java

示例15: addJMXAgentFromAdress

import javax.management.JMX; //导入依赖的package包/类
/**
 * Creates JMX wrapper for agent on specified adress and adds it to the list
 * of all connected agents.
 * @param serviceUrl URL of the JMX service where remote agent resides eg. service:jmx:rmi:///jndi/rmi://localhost:9999/server
 * @param objectName name of the MBean representing agent eg. myDomain:name=MyAgent1
 */
protected void addJMXAgentFromAdress(String serviceUrl, ObjectName objectName) throws IOException {
    JMXServiceURL url = new JMXServiceURL(serviceUrl);
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    
    IAgent agent = JMX.newMXBeanProxy(mbsc, objectName, IAgent.class);
    
    agents.add(agent);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:16,代码来源:AbstractJMXAgentObserver.java


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