Search in sources :

Example 16 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project rest.li by linkedin.

the class LoadBalancerClientCli method resetTogglingStores.

public static void resetTogglingStores(String host, boolean enabled) throws Exception {
    MonitoredHost _host = MonitoredHost.getMonitoredHost(new HostIdentifier(host));
    for (Object pidObj : _host.activeVms()) {
        int pid = (Integer) pidObj;
        System.out.println("checking pid: " + pid);
        JMXServiceURL jmxUrl = null;
        com.sun.tools.attach.VirtualMachine vm = com.sun.tools.attach.VirtualMachine.attach(pid + "");
        try {
            // get the connector address
            String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS);
            // establish connection to connector server
            if (connectorAddress != null) {
                jmxUrl = new JMXServiceURL(connectorAddress);
            }
        } finally {
            vm.detach();
        }
        if (jmxUrl != null) {
            System.out.println("got jmx url: " + jmxUrl);
            // connect to jmx
            JMXConnector connector = JMXConnectorFactory.connect(jmxUrl);
            connector.connect();
            MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
            // look for all beans in the d2 name space
            Set<ObjectInstance> objectInstances = mbeanServer.queryMBeans(new ObjectName("com.linkedin.d2:*"), null);
            for (ObjectInstance objectInstance : objectInstances) {
                System.err.println("checking object: " + objectInstance.getObjectName());
                // if we've found a toggling store, then toggle it
                if (objectInstance.getObjectName().toString().endsWith("TogglingStore")) {
                    System.out.println("found toggling zk store, so toggling to: " + enabled);
                    mbeanServer.invoke(objectInstance.getObjectName(), "setEnabled", new Object[] { enabled }, new String[] { "boolean" });
                }
            }
        } else {
            System.out.println("pid is not a jmx process: " + pid);
        }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HostIdentifier(sun.jvmstat.monitor.HostIdentifier) ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName) JMXConnector(javax.management.remote.JMXConnector) MonitoredHost(sun.jvmstat.monitor.MonitoredHost) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 17 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project spring-boot by spring-projects.

the class StartMojo method waitForForkedSpringApplication.

private void waitForForkedSpringApplication() throws IOException, MojoFailureException, MojoExecutionException {
    try {
        getLog().debug("Connecting to local MBeanServer at port " + this.jmxPort);
        JMXConnector connector = execute(this.wait, this.maxAttempts, new CreateJmxConnector(this.jmxPort));
        if (connector == null) {
            throw new MojoExecutionException("JMX MBean server was not reachable before the configured " + "timeout (" + (this.wait * this.maxAttempts) + "ms");
        }
        getLog().debug("Connected to local MBeanServer at port " + this.jmxPort);
        try {
            MBeanServerConnection connection = connector.getMBeanServerConnection();
            doWaitForSpringApplication(connection);
        } finally {
            connector.close();
        }
    } catch (IOException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MojoExecutionException("Failed to connect to MBean server at port " + this.jmxPort, ex);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ConnectException(java.net.ConnectException) ReflectionException(javax.management.ReflectionException)

Example 18 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project spring-boot by spring-projects.

the class StopMojo method stopForkedProcess.

private void stopForkedProcess() throws IOException, MojoFailureException, MojoExecutionException {
    JMXConnector connector = SpringApplicationAdminClient.connect(this.jmxPort);
    try {
        MBeanServerConnection connection = connector.getMBeanServerConnection();
        doStop(connection);
    } finally {
        connector.close();
    }
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 19 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project spring-framework by spring-projects.

the class MBeanServerConnectionFactoryBean method createLazyConnection.

/**
	 * Creates lazy proxies for the {@code JMXConnector} and {@code MBeanServerConnection}
	 */
private void createLazyConnection() {
    this.connectorTargetSource = new JMXConnectorLazyInitTargetSource();
    TargetSource connectionTargetSource = new MBeanServerConnectionLazyInitTargetSource();
    this.connector = (JMXConnector) new ProxyFactory(JMXConnector.class, this.connectorTargetSource).getProxy(this.beanClassLoader);
    this.connection = (MBeanServerConnection) new ProxyFactory(MBeanServerConnection.class, connectionTargetSource).getProxy(this.beanClassLoader);
}
Also used : TargetSource(org.springframework.aop.TargetSource) AbstractLazyCreationTargetSource(org.springframework.aop.target.AbstractLazyCreationTargetSource) ProxyFactory(org.springframework.aop.framework.ProxyFactory) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 20 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project spring-framework by spring-projects.

the class MBeanServerConnectionFactoryBeanTests method testTestValidConnection.

@Test
public void testTestValidConnection() throws Exception {
    Assume.group(TestGroup.JMXMP);
    JMXConnectorServer connectorServer = getConnectorServer();
    connectorServer.start();
    try {
        MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean();
        bean.setServiceUrl(serviceUrl);
        bean.afterPropertiesSet();
        try {
            MBeanServerConnection connection = bean.getObject();
            assertNotNull("Connection should not be null", connection);
            // perform simple MBean count test
            assertEquals("MBean count should be the same", getServer().getMBeanCount(), connection.getMBeanCount());
        } finally {
            bean.destroy();
        }
    } finally {
        connectorServer.stop();
    }
}
Also used : MBeanServerConnection(javax.management.MBeanServerConnection) JMXConnectorServer(javax.management.remote.JMXConnectorServer) Test(org.junit.Test)

Aggregations

MBeanServerConnection (javax.management.MBeanServerConnection)125 JMXConnector (javax.management.remote.JMXConnector)84 ObjectName (javax.management.ObjectName)73 JMXServiceURL (javax.management.remote.JMXServiceURL)59 JMXConnectorServer (javax.management.remote.JMXConnectorServer)38 Test (org.junit.Test)35 IOException (java.io.IOException)31 MBeanServer (javax.management.MBeanServer)28 HashMap (java.util.HashMap)23 Attribute (javax.management.Attribute)15 NotificationListener (javax.management.NotificationListener)13 MalformedURLException (java.net.MalformedURLException)12 ArrayList (java.util.ArrayList)12 Notification (javax.management.Notification)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 Map (java.util.Map)10 List (java.util.List)8 RemoteException (java.rmi.RemoteException)7 LocateRegistry (java.rmi.registry.LocateRegistry)7 Registry (java.rmi.registry.Registry)7