java类javax.management.MBeanServerInvocationHandler的实例源码

JBossWorkManagerUtils.java 文件源码 项目:lams 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
TestUtils.java 文件源码 项目:jdk8u-jdk 阅读 36 收藏 0 点赞 0 评论 0
/**
 * 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;
}
TestUtils.java 文件源码 项目:openjdk9 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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;
}
MBeanClientInterceptor.java 文件源码 项目:spring4-understanding 阅读 36 收藏 0 点赞 0 评论 0
/**
 * 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();
        }
    }
}
JBossWorkManagerUtils.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
TestUtils.java 文件源码 项目:jdk8u_jdk 阅读 37 收藏 0 点赞 0 评论 0
/**
 * 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;
}
ManagedScript.java 文件源码 项目:HeliosStreams 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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 */}

}
TestUtils.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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;
}
MBeanClientInterceptor.java 文件源码 项目:spring 阅读 37 收藏 0 点赞 0 评论 0
/**
 * 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();
        }
    }
}
Client.java 文件源码 项目:cacheonix-core 阅读 31 收藏 0 点赞 0 评论 0
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 !");
}
TestUtils.java 文件源码 项目:Advanced-Trigoplex 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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;
}
DstatCommand.java 文件源码 项目:daq-eclipse 阅读 16 收藏 0 点赞 0 评论 0
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()));
        }
    }
DstatCommand.java 文件源码 项目:daq-eclipse 阅读 18 收藏 0 点赞 0 评论 0
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()));
        }
    }
DstatCommand.java 文件源码 项目:daq-eclipse 阅读 21 收藏 0 点赞 0 评论 0
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()));
        }
    }
TestUtils.java 文件源码 项目:infobip-open-jdk-8 阅读 29 收藏 0 点赞 0 评论 0
/**
 * 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;
}
TestUtils.java 文件源码 项目:jdk8u-dev-jdk 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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;
}
SecurityJMXTest.java 文件源码 项目:activemq-artemis 阅读 27 收藏 0 点赞 0 评论 0
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());
}
PurgeCommandTest.java 文件源码 项目:activemq-artemis 阅读 30 收藏 0 点赞 0 评论 0
/**
 * 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();
   }
}
CarbonMetricsTestCase.java 文件源码 项目:product-cep 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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();
}
TestUtils.java 文件源码 项目:jdk7-jdk 阅读 31 收藏 0 点赞 0 评论 0
/**
 * 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;
}
TestUtils.java 文件源码 项目:openjdk-source-code-learn 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
JmxExporter.java 文件源码 项目:ajp-client 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
JBossWorkManagerUtils.java 文件源码 项目:class-guard 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
TestUtils.java 文件源码 项目:OLD-OpenJDK8 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
SessionExpireTestRun.java 文件源码 项目:incubator-twill 阅读 20 收藏 0 点赞 0 评论 0
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;
}
TestUtils.java 文件源码 项目:openjdk-jdk7u-jdk 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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;
}
JmxServerProbe.java 文件源码 项目:James 阅读 19 收藏 0 点赞 0 评论 0
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);
    }
}
TestUtils.java 文件源码 项目:openjdk-icedtea7 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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;
}
TestUtils.java 文件源码 项目:WBSAirback 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
MBeanClientInterceptor.java 文件源码 项目:lams 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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 on Java 6.
            if (JmxUtils.isMXBeanSupportAvailable()) {
                this.invocationHandler =
                        new MBeanServerInvocationHandler(this.serverToUse, this.objectName,
                                (this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
            }
            else {
                this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName);
            }
        }
        else {
            // Non-strict casing can only be achieved through custom
            // invocation handling. Only partial MXBean support available!
            retrieveMBeanInfo();
        }
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号