當前位置: 首頁>>代碼示例>>Java>>正文


Java MBeanServerInvocationHandler類代碼示例

本文整理匯總了Java中javax.management.MBeanServerInvocationHandler的典型用法代碼示例。如果您正苦於以下問題:Java MBeanServerInvocationHandler類的具體用法?Java MBeanServerInvocationHandler怎麽用?Java MBeanServerInvocationHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MBeanServerInvocationHandler類屬於javax.management包,在下文中一共展示了MBeanServerInvocationHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getWorkManager

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
/**
 * Obtain the default JBoss JCA WorkManager through a JMX lookup
 * for the JBossWorkManagerMBean.
 * @param mbeanName the JMX object name to use
 * @see org.jboss.resource.work.JBossWorkManagerMBean
 */
public static WorkManager getWorkManager(String mbeanName) {
	Assert.hasLength(mbeanName, "JBossWorkManagerMBean name must not be empty");
	try {
		Class<?> mbeanClass = JBossWorkManagerUtils.class.getClassLoader().loadClass(JBOSS_WORK_MANAGER_MBEAN_CLASS_NAME);
		InitialContext jndiContext = new InitialContext();
		MBeanServerConnection mconn = (MBeanServerConnection) jndiContext.lookup(MBEAN_SERVER_CONNECTION_JNDI_NAME);
		ObjectName objectName = ObjectName.getInstance(mbeanName);
		Object workManagerMBean = MBeanServerInvocationHandler.newProxyInstance(mconn, objectName, mbeanClass, false);
		Method getInstanceMethod = workManagerMBean.getClass().getMethod("getInstance");
		return (WorkManager) getInstanceMethod.invoke(workManagerMBean);
	}
	catch (Exception ex) {
		throw new IllegalStateException(
				"Could not initialize JBossWorkManagerTaskExecutor because JBoss API is not available", ex);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:JBossWorkManagerUtils.java

示例2: makeNotificationEmitter

import javax.management.MBeanServerInvocationHandler; //導入依賴的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

示例3: prepare

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
/**
 * 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) {
			// 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();
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:MBeanClientInterceptor.java

示例4: carryOverAndClose

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
/**
 * Reads the counters from the prior instance of this class, increments this instances counters and closes the prior.
 */
protected void carryOverAndClose() {
	final ManagedScriptMBean oldScript = MBeanServerInvocationHandler.newProxyInstance(JMXHelper.getHeliosMBeanServer(), objectName, ManagedScriptMBean.class, false);
	deploymentId = oldScript.getDeploymentId()+1;
	totalErrors.add(oldScript.getTotalCollectionErrors());
	Date dt = oldScript.getLastCollectionErrorDate();
	if(dt!=null) {
		lastError.set(dt.getTime());
	}
	dt = oldScript.getLastCollectionDate();
	if(dt!=null) {
		lastCompleteCollection.set(dt.getTime());
	}
	final Long lastElapsed = oldScript.getLastCollectionElapsed();
	if(lastElapsed!=null) {
		lastCollectionElapsed.set(lastElapsed);
	}
	try { oldScript.close(); } catch (Exception x) {/* No Op */}
	
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:23,代碼來源:ManagedScript.java

示例5: main

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
public static void main(String[] args) throws Exception
{
   // The RMI server's host: this is actually ignored by JSR 160
   // since this information is stored in the RMI stub.
   String serverHost = "localhost";

   // The host where the rmiregistry runs.
   String namingHost = "localhost";

   String jndiPath = "/ssljmxconnector";
   JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + serverHost + "/jndi/rmi://" + namingHost + jndiPath);
   JMXConnector connector = JMXConnectorFactory.connect(url);
   MBeanServerConnection connection = connector.getMBeanServerConnection();

   // Call the server side
   ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
   Object proxy = MBeanServerInvocationHandler.newProxyInstance(connection, delegateName, MBeanServerDelegateMBean.class, true);
   MBeanServerDelegateMBean delegate = (MBeanServerDelegateMBean)proxy;

   System.out.println(delegate.getImplementationVendor() + " is cool !");
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:22,代碼來源:Client.java

示例6: mxBean

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
/**
 * Gets CacheGroupMetricsMXBean for given node and group name.
 *
 * @param nodeIdx Node index.
 * @param cacheOrGrpName Cache group name.
 * @return MBean instance.
 */
private CacheGroupMetricsMXBean mxBean(int nodeIdx, String cacheOrGrpName) throws MalformedObjectNameException {
    ObjectName mbeanName = U.makeMBeanName(getTestIgniteInstanceName(nodeIdx), "Cache groups", cacheOrGrpName);

    MBeanServer mbeanSrv = ManagementFactory.getPlatformMBeanServer();

    if (!mbeanSrv.isRegistered(mbeanName))
        fail("MBean is not registered: " + mbeanName.getCanonicalName());

    return MBeanServerInvocationHandler.newProxyInstance(mbeanSrv, mbeanName, CacheGroupMetricsMXBean.class,
        true);
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:19,代碼來源:CacheGroupMetricsMBeanTest.java

示例7: displayAllDestinations

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
private void displayAllDestinations() throws Exception {

        String query = JmxMBeansUtil.createQueryString(queryString, "*");
        List<?> queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query);

        final String header = "%-50s  %10s  %10s  %10s  %10s  %10s  %10s";
        final String tableRow = "%-50s  %10d  %10d  %10d  %10d  %10d  %10d";

        context.print(String.format(Locale.US, header, "Name", "Queue Size", "Producer #", "Consumer #", "Enqueue #", "Dequeue #", "Memory %"));

        // Iterate through the queue result
        for (Object view : queueList) {
            ObjectName queueName = ((ObjectInstance)view).getObjectName();
            QueueViewMBean queueView = MBeanServerInvocationHandler.
                newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true);

            context.print(String.format(Locale.US, tableRow,
                    queueView.getName(),
                    queueView.getQueueSize(),
                    queueView.getProducerCount(),
                    queueView.getConsumerCount(),
                    queueView.getEnqueueCount(),
                    queueView.getDequeueCount(),
                    queueView.getMemoryPercentUsage()));
        }
    }
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:27,代碼來源:DstatCommand.java

示例8: displayQueueStats

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
private void displayQueueStats() throws Exception {

        String query = JmxMBeansUtil.createQueryString(queryString, "Queue");
        List<?> queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query);

        final String header = "%-50s  %10s  %10s  %10s  %10s  %10s  %10s";
        final String tableRow = "%-50s  %10d  %10d  %10d  %10d  %10d  %10d";

        context.print(String.format(Locale.US, header, "Name", "Queue Size", "Producer #", "Consumer #", "Enqueue #", "Dequeue #", "Memory %"));

        // Iterate through the queue result
        for (Object view : queueList) {
            ObjectName queueName = ((ObjectInstance)view).getObjectName();
            QueueViewMBean queueView = MBeanServerInvocationHandler.
                newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true);

            context.print(String.format(Locale.US, tableRow,
                    queueView.getName(),
                    queueView.getQueueSize(),
                    queueView.getProducerCount(),
                    queueView.getConsumerCount(),
                    queueView.getEnqueueCount(),
                    queueView.getDequeueCount(),
                    queueView.getMemoryPercentUsage()));
        }
    }
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:27,代碼來源:DstatCommand.java

示例9: displayTopicStats

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
private void displayTopicStats() throws Exception {

        String query = JmxMBeansUtil.createQueryString(queryString, "Topic");
        List<?> topicsList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query);

        final String header = "%-50s  %10s  %10s  %10s  %10s  %10s  %10s";
        final String tableRow = "%-50s  %10d  %10d  %10d  %10d  %10d  %10d";

        context.print(String.format(Locale.US, header, "Name", "Queue Size", "Producer #", "Consumer #", "Enqueue #", "Dequeue #", "Memory %"));

        // Iterate through the topics result
        for (Object view : topicsList) {
            ObjectName topicName = ((ObjectInstance)view).getObjectName();
            TopicViewMBean topicView = MBeanServerInvocationHandler.
                newProxyInstance(createJmxConnection(), topicName, TopicViewMBean.class, true);

            context.print(String.format(Locale.US, tableRow,
                    topicView.getName(),
                    topicView.getQueueSize(),
                    topicView.getProducerCount(),
                    topicView.getConsumerCount(),
                    topicView.getEnqueueCount(),
                    topicView.getDequeueCount(),
                    topicView.getMemoryPercentUsage()));
        }
    }
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:27,代碼來源:DstatCommand.java

示例10: testBrowseExpiredMessages

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
public void testBrowseExpiredMessages() throws Exception {
   JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi");
   JMXConnector connector = JMXConnectorFactory.connect(url, null);
   connector.connect();
   MBeanServerConnection connection = connector.getMBeanServerConnection();
   ObjectName name = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost," + "destinationType=Queue,destinationName=TEST.Q");
   QueueViewMBean queueMbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, QueueViewMBean.class, true);
   HashMap<String, String> headers = new HashMap<>();
   headers.put("timeToLive", Long.toString(2000));
   headers.put("JMSDeliveryMode", Integer.toString(DeliveryMode.PERSISTENT));
   queueMbean.sendTextMessage(headers, "test", "system", "manager");
   // allow message to expire on the queue
   TimeUnit.SECONDS.sleep(4);

   Connection c = new ActiveMQConnectionFactory("vm://localhost").createConnection("system", "manager");
   c.start();

   // browser consumer will force expiration check on addConsumer
   QueueBrowser browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("TEST.Q"));
   assertTrue("no message in the q", !browser.getEnumeration().hasMoreElements());

   // verify dlq got the message, no security exception as brokers context is now used
   browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("ActiveMQ.DLQ"));
   assertTrue("one message in the dlq", browser.getEnumeration().hasMoreElements());
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:26,代碼來源:SecurityJMXTest.java

示例11: testQueueViewMbean

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
/**
 * This test ensures that the queueViewMbean will work.
 *
 * @throws Exception
 */
public void testQueueViewMbean() throws Exception {

   try {
      addMessages();

      validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);

      List<String> tokens = Arrays.asList(new String[]{"*"});
      for (String token : tokens) {
         List<ObjectInstance> queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), "type=Broker,brokerName=localbroker,destinationType=Queue,destinationName=" + token);

         for (ObjectInstance queue : queueList) {
            ObjectName queueName = queue.getObjectName();
            QueueViewMBean proxy = MBeanServerInvocationHandler.newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true);
            int removed = proxy.removeMatchingMessages(MSG_SEL_WITH_PROPERTY);
            LOG.info("Removed: " + removed);
         }
      }

      validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT);

   } finally {
      purgeAllMessages();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:31,代碼來源:PurgeCommandTest.java

示例12: invokeJMXReportOperation

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
/**
 * This method will force metric manager to collect metrics by invoking report() method
 * using remote jmx
 * @throws IOException
 * @throws MalformedObjectNameException
 */
private void invokeJMXReportOperation() throws IOException, MalformedObjectNameException, XPathExpressionException {
    int JMXServicePort = Integer.parseInt(cepServer.getInstance().getPorts().get("jmxserver"));
    int RMIRegistryPort = Integer.parseInt(cepServer.getInstance().getPorts().get("rmiregistry"));
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost:" + JMXServicePort +
            "/jndi/rmi://localhost:" + RMIRegistryPort + "/jmxrmi");
    Map<String, String[]> env = new HashMap<>();
    String[] credentials = {"admin", "admin"};
    env.put(JMXConnector.CREDENTIALS, credentials);
    JMXConnector jmxConnector = JMXConnectorFactory.connect(url, env);
    MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection();
    ObjectName mbeanName = new ObjectName("org.wso2.carbon:type=MetricManager");
    MetricManagerMXBean mbeanProxy =
            MBeanServerInvocationHandler.newProxyInstance(
                    mbeanServerConnection, mbeanName, MetricManagerMXBean.class, true);
    mbeanProxy.report();
    jmxConnector.close();
}
 
開發者ID:wso2,項目名稱:product-cep,代碼行數:24,代碼來源:CarbonMetricsTestCase.java

示例13: getMonitor

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
/**
 * get an mbean instance for a remote jmx-enabled jvm.
 * 
 * @param jmxServerUrl
 *            jmx service url, for example
 *            <code>service:jmx:rmi:///jndi/rmi://:9999/jmxrmi</code>
 * @param host
 *            channel pool's tcp host
 * @param port
 *            channel pool's tcp port
 * @return a proxy for the monitor associated with the pool
 */
public static ChannelPoolMonitorMBean getMonitor(String jmxServerUrl, String host, int port) throws IOException {
	ObjectName objectName = null;
	try {
		objectName = makeObjectName(host, port);
	} catch (MalformedObjectNameException e) {
		throw new IllegalArgumentException(e);
	}

	JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:9999/jmxrmi");
	JMXConnector jmxc = JMXConnectorFactory.connect(url, null);

	MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

	Set<ObjectInstance> set = mbsc.queryMBeans(objectName, null);
	if (set == null || set.isEmpty()) {
		return null;
	} else {
		return MBeanServerInvocationHandler.newProxyInstance(mbsc, objectName, ChannelPoolMonitorMBean.class, true);
	}
}
 
開發者ID:jrialland,項目名稱:ajp-client,代碼行數:33,代碼來源:JmxExporter.java

示例14: expireAppMasterZKSession

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
private boolean expireAppMasterZKSession(TwillController controller, long timeout, TimeUnit timeoutUnit) {
  MBeanServer mbeanServer = MBeanRegistry.getInstance().getPlatformMBeanServer();
  QueryExp query = Query.isInstanceOf(new StringValueExp(ConnectionMXBean.class.getName()));

  Stopwatch stopwatch = new Stopwatch();

  do {
    // Find the AM session and expire it
    Set<ObjectName> connectionBeans = mbeanServer.queryNames(ObjectName.WILDCARD, query);
    for (ObjectName objectName : connectionBeans) {

      ConnectionMXBean connectionBean = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, objectName,
                                                                                      ConnectionMXBean.class, false);
      for (String node : connectionBean.getEphemeralNodes()) {
        if (node.endsWith("/instances/" + controller.getRunId().getId())) {
          // This is the AM, expire the session.
          LOG.info("Kill AM session {}", connectionBean.getSessionId());
          connectionBean.terminateSession();
          return true;
        }
      }
    }
  } while (stopwatch.elapsedTime(timeoutUnit) < timeout);

  return false;
}
 
開發者ID:chtyim,項目名稱:incubator-twill,代碼行數:27,代碼來源:SessionExpireTestRun.java

示例15: connect

import javax.management.MBeanServerInvocationHandler; //導入依賴的package包/類
private void connect() throws IOException {
    JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port));
    JMXConnector jmxc = JMXConnectorFactory.connect(jmxUrl, null);
    mbeanServerConn = jmxc.getMBeanServerConnection();

    try {
        ObjectName name = new ObjectName(DOMAINLIST_OBJECT_NAME);
        domainListProcxy = (DomainListManagementMBean) MBeanServerInvocationHandler.newProxyInstance(mbeanServerConn, name, DomainListManagementMBean.class, true);
        name = new ObjectName(VIRTUALUSERTABLE_OBJECT_NAME);
        virtualUserTableProxy = (RecipientRewriteTableManagementMBean) MBeanServerInvocationHandler.newProxyInstance(mbeanServerConn, name, RecipientRewriteTableManagementMBean.class, true);
        name = new ObjectName(USERSREPOSITORY_OBJECT_NAME);
        usersRepositoryProxy = (UsersRepositoryManagementMBean) MBeanServerInvocationHandler.newProxyInstance(mbeanServerConn, name, UsersRepositoryManagementMBean.class, true);
    } catch (MalformedObjectNameException e) {
        throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e);
    }
}
 
開發者ID:twachan,項目名稱:James,代碼行數:17,代碼來源:JmxServerProbe.java


注:本文中的javax.management.MBeanServerInvocationHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。