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);
}
}
}
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);
}
}
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();
}
}
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);
}
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();
}
}
Aggregations