List of usage examples for javax.management.remote JMXConnector connect
public void connect() throws IOException;
Establishes the connection to the connector server.
From source file:com.linkedin.d2.balancer.util.LoadBalancerClientCli.java
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 {/*from w w w . j ava 2 s . c om*/ // 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); } } }
From source file:org.apache.hadoop.hbase.TestJMXListener.java
@Test public void testStop() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); LOG.info("shutdown hbase cluster..."); cluster.shutdown();// w w w . jav a2 s .co m LOG.info("wait for the hbase cluster shutdown..."); cluster.waitUntilShutDown(); JMXConnector connector = JMXConnectorFactory .newJMXConnector(JMXListener.buildJMXServiceURL(connectorPort, connectorPort), null); expectedEx.expect(IOException.class); connector.connect(); }
From source file:org.lilyproject.lilyservertestfw.LilyProxy.java
public void start(SolrDefinition solrDef) throws Exception { if (started) { throw new IllegalStateException("LilyProxy is already started."); } else {/* w ww.j a v a 2 s . c o m*/ started = true; } cleanOldTmpDirs(); if (hasBeenStarted && this.mode == Mode.EMBED) { // In embed mode, we can't support multiple start-stop sequences since // HBase/Hadoop does not shut down all processes synchronously. throw new IllegalStateException("LilyProxy can only be started once in a JVM when using embed mode."); } else { hasBeenStarted = true; } System.out.println("LilyProxy mode: " + mode); if (mode == Mode.CONNECT) { // First reset the state System.out.println("Calling reset state flag on externally launched Lily..."); try { String hostport = "localhost:10102"; JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi://" + hostport + "/jndi/rmi://" + hostport + "/jmxrmi"); JMXConnector connector = JMXConnectorFactory.connect(url); connector.connect(); ObjectName lilyLauncher = new ObjectName("LilyLauncher:name=Launcher"); connector.getMBeanServerConnection().invoke(lilyLauncher, "resetLilyState", new Object[0], new String[0]); connector.close(); } catch (Exception e) { throw new Exception("Resetting Lily state failed.", e); } System.out.println("State reset done."); } if (mode == Mode.EMBED || mode == Mode.HADOOP_CONNECT) { if (testHome == null) { testHome = TestHomeUtil.createTestHome(TEMP_DIR_PREFIX); } if (mode == Mode.EMBED) { hbaseProxy.setTestHome(new File(testHome, TemplateDir.HADOOP_DIR)); } solrProxy.setTestHome(new File(testHome, TemplateDir.SOLR_DIR)); lilyServerProxy.setTestHome(new File(testHome, TemplateDir.LILYSERVER_DIR)); } if (mode == Mode.EMBED && Boolean.parseBoolean(System.getProperty(RESTORE_TEMPLATE_DIR_PROP_NAME, "true"))) { TemplateDir.restoreTemplateDir(testHome); } hbaseProxy.start(); solrProxy.start(solrDef); lilyServerProxy.start(); hbaseIndexerLauncherService.start(Collections.<String>emptyList()); }
From source file:org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java
/** * This method gets the JmxConnector to connect with the given * jmxServiceURL./*from w ww . j a v a2s. c om*/ * * @param username * may be null * @param password * may be null * @param jmxServiceURL * should not be null! * @return a jmxConnector * @throws IOException * if the connection to the given jmxServiceURL fails (e.g. * authentication failure or not reachable) */ public JMXConnector getJmxConnector(String username, String password, JMXServiceURL jmxServiceURL) throws IOException { JMXConnector jmxConnector; HashMap<String, String[]> env = new HashMap<String, String[]>(); if (username != null && password != null) { String[] credentials = new String[] { username, password }; env.put("jmx.remote.credentials", credentials); } jmxConnector = JMXConnectorFactory.connect(jmxServiceURL, env); jmxConnector.connect(); return jmxConnector; }