Example usage for javax.management.remote JMXConnector getMBeanServerConnection

List of usage examples for javax.management.remote JMXConnector getMBeanServerConnection

Introduction

In this page you can find the example usage for javax.management.remote JMXConnector getMBeanServerConnection.

Prototype

public MBeanServerConnection getMBeanServerConnection() throws IOException;

Source Link

Document

Returns an MBeanServerConnection object representing a remote MBean server.

Usage

From source file:com.continuent.tungsten.common.jmx.JmxManager.java

/**
 * Remove NotificationListener from this MBean.
 * /*w  w w . j ava  2 s. c  o  m*/
 * @param jmxConnector The MBean server connector.
 * @param mbeanClass The class for which an MBean exists.
 * @param notificationListener Previously added NotificationListener
 *            instance.
 * @throws Exception
 */
static public void removeNotificationListener(JMXConnector jmxConnector, Class<?> mbeanClass,
        NotificationListener notificationListener) throws Exception {
    MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
    ObjectName objectName = generateMBeanObjectName(mbeanClass);
    mbsc.removeNotificationListener(objectName, notificationListener);
}

From source file:com.continuent.tungsten.common.jmx.JmxManager.java

/**
 * Attach NotificationListener that can be used to listen notifications
 * emitted by MBean server.//w  w  w.  j  a  va2  s.c  o m
 * 
 * @param jmxConnector The MBean server connector.
 * @param mbeanClass The class for which an MBean exists.
 * @param notificationListener User provided NotificationListener instance.
 * @throws InstanceNotFoundException
 * @throws Exception
 */
static public void addNotificationListener(JMXConnector jmxConnector, Class<?> mbeanClass,
        NotificationListener notificationListener) throws InstanceNotFoundException, Exception {
    MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
    ObjectName objectName = generateMBeanObjectName(mbeanClass);
    mbsc.addNotificationListener(objectName, notificationListener, null, null);
}

From source file:com.continuent.tungsten.common.jmx.JmxManager.java

/**
 * Remove NotificationListener from this MBean.
 * //from   www .j  a  v a  2 s  . c om
 * @param jmxConnector The MBean server connector.
 * @param mbeanInterface The MBean interface this instance implements.
 * @param mbeanName A custom name for the MBean.
 * @param notificationListener Previously added NotificationListener
 *            instance.
 * @throws Exception
 */
static public void removeNotificationListener(JMXConnector jmxConnector, Class<?> mbeanInterface,
        String mbeanName, NotificationListener notificationListener, boolean ignored) throws Exception {
    MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
    ObjectName objectName = generateMBeanObjectName(mbeanInterface.getName(), mbeanName);
    mbsc.removeNotificationListener(objectName, notificationListener);
}

From source file:com.continuent.tungsten.common.jmx.JmxManager.java

/**
 * Attach NotificationListener that can be used to listen notifications
 * emitted by MBean server./*from   ww  w. j ava 2s  . c  o  m*/
 * 
 * @param jmxConnector The MBean server connector.
 * @param mbeanInterface The MBean interface this instance implements.
 * @param mbeanName A custom name for the MBean.
 * @param notificationListener User provided NotificationListener instance.
 * @throws InstanceNotFoundException
 * @throws Exception
 */
static public void addNotificationListener(JMXConnector jmxConnector, Class<?> mbeanInterface, String mbeanName,
        NotificationListener notificationListener, boolean ignored)
        throws InstanceNotFoundException, Exception {
    MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
    ObjectName objectName = generateMBeanObjectName(mbeanInterface.getName(), mbeanName);
    mbsc.addNotificationListener(objectName, notificationListener, null, null);
}

From source file:org.hyperic.hq.product.jmx.MxUtil.java

public static JMXConnector getCachedMBeanConnector(Properties config)
        throws MalformedURLException, IOException {
    String jmxUrl = config.getProperty(MxUtil.PROP_JMX_URL);
    String user = config.getProperty(PROP_JMX_USERNAME);
    String pass = config.getProperty(PROP_JMX_PASSWORD);
    JMXConnectorKey key = new JMXConnectorKey(jmxUrl, user, pass);
    JMXConnector rtn = null;
    synchronized (mbeanConns) {
        rtn = mbeanConns.get(key);/*from   ww w  .j a v a 2s.  co  m*/
        if (rtn == null) {
            rtn = getMBeanConnector(config);
            mbeanConns.put(key, rtn);
        }
        try {
            // ensure that the connection is not broken
            rtn.getMBeanServerConnection();
        } catch (IOException e) {
            close(rtn);
            rtn = getMBeanConnector(config);
            mbeanConns.put(key, rtn);
        }
    }
    final JMXConnector c = rtn;
    final InvocationHandler handler = new InvocationHandler() {
        private final JMXConnector conn = c;

        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            if (method.getName().equals("close")) {
                return null;
            }
            synchronized (conn) {
                return method.invoke(conn, args);
            }
        }
    };
    return (JMXConnector) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
            new Class<?>[] { JMXConnector.class }, handler);
}

From source file:net.tzolov.geode.jmx.JmxToGrafanaApplication.java

@Bean
public MBeanServerConnection jmxConnection(@Value("${mbeanHostName}") String mbeanHostName,
        @Value("${mbeanPort}") String mbeanPort) {

    try {//from   w  w  w  .  j  a  va2s  . co m
        String mbeanServerUrl = "service:jmx:rmi:///jndi/rmi://" + mbeanHostName.trim() + ":" + mbeanPort.trim()
                + "/jmxrmi";
        JMXServiceURL url = new JMXServiceURL(mbeanServerUrl);

        JMXConnector jmxConnector = JMXConnectorFactory.connect(url, null);
        return jmxConnector.getMBeanServerConnection();
    } catch (Exception ex) {
        throw new RuntimeException((ex));
    }
}

From source file:com.continuent.tungsten.common.jmx.JmxManager.java

/**
 * Client helper method to obtain a proxy that implements the given
 * interface by forwarding its methods through the given MBean server to the
 * named MBean.//from w  w  w  .  jav a 2  s .  c o  m
 * 
 * @param clientConnection the MBean server to forward to
 * @param mbeanClass The MBean interface this instance implements
 * @param mbeanName A custom name for this MBean
 * @param notificationBroadcaster If true make the returned proxy implement
 *            NotificationEmitter by forwarding its methods via connection
 * @return An MBean proxy
 */
public static Object getMBeanProxy(JMXConnector clientConnection, Class<?> mbeanClass, String mbeanName,
        boolean notificationBroadcaster, boolean ignored) {
    try {

        ObjectName objectName = generateMBeanObjectName(mbeanClass.getName(), mbeanName);

        return MBeanServerInvocationHandler.newProxyInstance(clientConnection.getMBeanServerConnection(),
                objectName, mbeanClass, notificationBroadcaster);
    } catch (Exception e) {
        throw new ServerRuntimeException("Unable to get proxy connection to bean", e);
    }
}

From source file:com.continuent.tungsten.common.jmx.JmxManager.java

/**
 * Client helper method to obtain a proxy that implements the given
 * interface by forwarding its methods through the given MBean server to the
 * named MBean.// w  w w.  j a  va2s  .  c  o  m
 * 
 * @param clientConnection the MBean server to forward to
 * @param mbeanClass The MBean interface this instance implements
 * @param mbeanName A custom name for this MBean
 * @param notificationBroadcaster If true make the returned proxy implement
 *            NotificationEmitter by forwarding its methods via connection
 * @return An MBean proxy
 */
public static Object getMBeanProxy(JMXConnector clientConnection, Class<?> mbeanClass, Class<?> mbeanInterface,
        String mbeanName, boolean notificationBroadcaster, boolean ignored) {
    try {

        ObjectName objectName = generateMBeanObjectName(mbeanClass.getName(), mbeanName);

        return MBeanServerInvocationHandler.newProxyInstance(clientConnection.getMBeanServerConnection(),
                objectName, mbeanInterface, notificationBroadcaster);
    } catch (Exception e) {
        throw new ServerRuntimeException("Unable to get proxy connection to bean", e);
    }
}

From source file:com.googlecode.jmxtrans.connections.MBeanServerConnectionFactory.java

@Override
@Nonnull/*from w  w  w  .  j  av a2s .  co  m*/
public JMXConnection makeObject(@Nonnull JmxConnectionProvider server) throws IOException {
    if (server.isLocal()) {
        return new JMXConnection(null, server.getLocalMBeanServer());
    } else {
        JMXConnector connection = server.getServerConnection();
        return new JMXConnection(connection, connection.getMBeanServerConnection());
    }
}

From source file:test.integ.be.fedict.hsm.MonitoringTest.java

@Test
public void testJMXConnection() throws Exception {
    JMXServiceURL jmxServiceURL = new JMXServiceURL("service:jmx:remoting-jmx://localhost:9999");
    JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceURL);
    MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
    MemoryMXBean memoryMXBean = ManagementFactory.newPlatformMXBeanProxy(connection,
            ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class);
    MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
    LOG.debug("used heap memory: " + heapMemoryUsage.getUsed());
}