當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。