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


Java MBeanServerInvocationHandler.newProxyInstance方法代碼示例

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


在下文中一共展示了MBeanServerInvocationHandler.newProxyInstance方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: Ex4Service

import javax.management.MBeanServerInvocationHandler; //導入方法依賴的package包/類
public Ex4Service() throws URISyntaxException {
  CachingProvider cachingProvider = Caching.getCachingProvider("org.ehcache.jsr107.EhcacheCachingProvider");

  CacheManager cacheManager = cachingProvider.getCacheManager(
      getClass().getResource("/ehcache-ex4.xml").toURI(),
      getClass().getClassLoader());
  cache = cacheManager.getCache("someCache4", Long.class, Person.class);

  try {
    MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName("javax.cache:type=CacheStatistics,CacheManager="
        + getClass().getResource("/ehcache-ex4.xml")
        .toURI()
        .toString()
        .replace(":", ".") + ",Cache=someCache4");
    cacheStatisticsMXBean = MBeanServerInvocationHandler.newProxyInstance(beanServer, objectName, CacheStatisticsMXBean.class, false);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:aurbroszniowski,項目名稱:DevoxxFr2017,代碼行數:21,代碼來源:Ex4Service.java

示例11: main

import javax.management.MBeanServerInvocationHandler; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception
{
	// InternalLoggerFactory.setDefaultFactory(new SimpleLoggerFactory());

	AHessianJmxClient _ahessianClient = new AHessianJmxClient("test",
			15009, false, null);
	_ahessianClient.start();
	MBeanServerConnection jmxc = _ahessianClient.getMBeanServer();
	MBeanServerDelegateMBean proxy = (MBeanServerDelegateMBean) MBeanServerInvocationHandler
			.newProxyInstance(jmxc, new ObjectName(
					"JMImplementation:type=MBeanServerDelegate"),
					MBeanServerDelegateMBean.class, false);
	System.out.println(proxy.getMBeanServerId());
	boolean ok = false;
	while (true)
		try
		{
			System.out.println(proxy.getMBeanServerId());
			ok = true;
			Thread.sleep(1000);
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			Thread.sleep(1000);
		}

}
 
開發者ID:yajsw,項目名稱:yajsw,代碼行數:29,代碼來源:AHessianJmxClient.java

示例12: run

import javax.management.MBeanServerInvocationHandler; //導入方法依賴的package包/類
@Override
public void run(CommandLine line, ToolRunningContext context) throws Exception {

    OnlineWorkflowStartParameters startconfig = OnlineWorkflowStartParameters.loadDefault();

    String host = line.getOptionValue(OnlineWorkflowCommand.HOST);
    String port = line.getOptionValue(OnlineWorkflowCommand.PORT);
    String threads = line.getOptionValue(OnlineWorkflowCommand.THREADS);
    if (host != null) {
        startconfig.setJmxHost(host);
    }
    if (port != null) {
        startconfig.setJmxPort(Integer.valueOf(port));
    }
    if (threads != null) {
        startconfig.setThreads(Integer.valueOf(threads));
    }


    String urlString = "service:jmx:rmi:///jndi/rmi://" + startconfig.getJmxHost() + ":" + startconfig.getJmxPort() + "/jmxrmi";

    JMXServiceURL serviceURL = new JMXServiceURL(urlString);
    Map<String, String> jmxEnv = new HashMap<>();
    JMXConnector connector = JMXConnectorFactory.connect(serviceURL, jmxEnv);
    MBeanServerConnection mbsc = connector.getMBeanServerConnection();

    ObjectName name = new ObjectName(LocalOnlineApplicationMBean.BEAN_NAME);
    LocalOnlineApplicationMBean application = MBeanServerInvocationHandler.newProxyInstance(mbsc, name, LocalOnlineApplicationMBean.class, false);


    boolean emptyContingency = line.hasOption("empty-contingency");
    Path caseFile = Paths.get(line.getOptionValue("case-file"));
    application.runTDSimulations(startconfig, caseFile.toString(), line.getOptionValue("contingencies"), Boolean.toString(emptyContingency), line.getOptionValue("output-folder"));
}
 
開發者ID:itesla,項目名稱:ipst,代碼行數:35,代碼來源:RunTDSimulationsMpiTool.java

示例13: 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();
  stopwatch.start();
  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;
        }
      }
    }
    Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
  } while (stopwatch.elapsedTime(timeoutUnit) < timeout);

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

示例14: Jmx

import javax.management.MBeanServerInvocationHandler; //導入方法依賴的package包/類
public Jmx() throws IOException, MalformedObjectNameException {
    // I got this from the log messages when I was starting ActiveMQ
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
    JMXConnector connector = JMXConnectorFactory.connect(url);
    connector.connect();

    MBeanServerConnection connection = connector.getMBeanServerConnection();

    // This is jmxDomain:ObjectName...see ActiveMQ MBeans Reference in http://activemq.apache.org/jmx.html
    ObjectName name = new ObjectName("org.apache.activemq:brokerName=localhost,type=Broker");
    BrokerViewMBean mbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true);

    System.out.println(mbean.getTotalMessageCount());
}
 
開發者ID:aquaplanet,項目名稱:activemq-demo,代碼行數:15,代碼來源:Jmx.java

示例15: newProxyClient

import javax.management.MBeanServerInvocationHandler; //導入方法依賴的package包/類
public <T> T newProxyClient(ObjectName name, Class<T> mbean) {
    if (isRegistered(name)) {
        ObjectName on = mbeansRegistered.get(name);
        return MBeanServerInvocationHandler.newProxyInstance(server, on != null ? on : name, mbean, false);
    } else {
        return null;
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:9,代碼來源:DefaultManagementAgent.java


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