List of usage examples for javax.management.remote JMXServiceURL JMXServiceURL
public JMXServiceURL(String serviceURL) throws MalformedURLException
Constructs a JMXServiceURL
by parsing a Service URL string.
From source file:flens.query.JMXQuery.java
private synchronized void connect() throws IOException { if (!running) throw new IllegalStateException("connecting while shutting down"); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"); con = JMXConnectorFactory.connect(url, null); connection = con.getMBeanServerConnection(); }
From source file:net.nicoll.boot.daemon.SpringApplicationAdminClient.java
/** * Create a connector for an {@link javax.management.MBeanServer} exposed on the * current machine and the current port. Security should be disabled. * @param port the port on which the mbean server is exposed * @return a connection//w ww. j av a 2s . c o m * @throws IOException if the connection to that server failed */ public static JMXConnector connect(int port) throws IOException { String url = "service:jmx:rmi:///jndi/rmi://127.0.0.1:" + port + "/jmxrmi"; JMXServiceURL serviceUrl = new JMXServiceURL(url); return JMXConnectorFactory.connect(serviceUrl, null); }
From source file:com.lmig.cf.metrics.opsmetrics.OpsMetrics.java
private <T> T execute(JmxTemplate<T> template) throws OpsMetricsException { LOG.debug("Connecting to {}:{}", host, port); JMXConnector connector = null; try {//ww w . j ava2s . c o m JMXServiceURL address = new JMXServiceURL( "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"); HashMap<String, String[]> env = getCredentials(); connector = JMXConnectorFactory.connect(address, env); MBeanServerConnection mbs = connector.getMBeanServerConnection(); return template.execute(mbs); } catch (Exception e) { LOG.error("Unabled to execute JMX command", e); throw new OpsMetricsException(e); } finally { close(connector); } }
From source file:eu.itesla_project.online.tools.RunTDSimulationsMpiTool.java
@Override public void run(CommandLine line) throws Exception { OnlineWorkflowStartParameters startconfig = OnlineWorkflowStartParameters.loadDefault(); String host = line.getOptionValue(OnlineWorkflowCommand.HOST); String port = line.getOptionValue(OnlineWorkflowCommand.PORT); String threads = line.getOptionValue(OnlineWorkflowCommand.THREADS); if (host != null) startconfig.setJmxHost(host);//from w ww . j a v a2 s. com if (port != null) startconfig.setJmxPort(Integer.valueOf(port)); if (threads != null) startconfig.setThreads(Integer.valueOf(threads)); String urlString = "service:jmx:rmi:///jndi/rmi://" + startconfig.getJmxHost() + ":" + startconfig.getJmxPort() + "/jmxrmi"; JMXServiceURL serviceURL = new JMXServiceURL(urlString); Map<String, String> jmxEnv = new HashMap<>(); JMXConnector connector = JMXConnectorFactory.connect(serviceURL, jmxEnv); MBeanServerConnection mbsc = connector.getMBeanServerConnection(); ObjectName name = new ObjectName(LocalOnlineApplicationMBean.BEAN_NAME); LocalOnlineApplicationMBean application = MBeanServerInvocationHandler.newProxyInstance(mbsc, name, LocalOnlineApplicationMBean.class, false); boolean emptyContingency = line.hasOption("empty-contingency"); Path caseFile = Paths.get(line.getOptionValue("case-file")); application.runTDSimulations(startconfig, caseFile.toString(), line.getOptionValue("contingencies"), Boolean.toString(emptyContingency), line.getOptionValue("output-folder")); }
From source file:org.fabrician.enabler.KarafContainer.java
public synchronized MBeanServerConnection getMBeanServerConnection() throws Exception { if (this.mBeanServer == null) { Map<String, String[]> environment = new HashMap<String, String[]>(); String user = getAdminName(); String pwd = getAdminPassword(); String jmxurl = getJmxClientUrl(); String[] credentials = new String[] { user, pwd }; environment.put(JMXConnector.CREDENTIALS, credentials); JMXServiceURL url = null; try {/* w w w . j a v a 2 s . co m*/ url = new JMXServiceURL(jmxurl); getEngineLogger().info("Establishing JMX connection to URL : [" + jmxurl + "]..."); this.jmxc = JMXConnectorFactory.connect(url, environment); this.mBeanServer = jmxc.getMBeanServerConnection(); getEngineLogger().info("JMX connection established."); } catch (Exception ex) { getEngineLogger().warning("[" + jmxurl + "] : " + ex.getMessage()); throw ex; } } return this.mBeanServer; }
From source file:org.wso2.carbon.registry.subscription.test.util.JMXClient.java
/** * connect to org.wso2.carbon to invoke different operations * * @param userName user name to connect to org.wso2.carbon * @param password password to connect to org.wso2.carbon * @param connectionType/* w ww. j av a 2 s . c o m*/ * @param operation * @throws Exception */ public void connect(String userName, String password, String connectionType, String operation) throws Exception { try { JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi://" + NetworkUtils.getLocalHostname() + ":" + RMIServerPort + "/jndi/rmi://" + NetworkUtils.getLocalHostname() + ":" + RMIRegistryPort + "/jmxrmi"); Hashtable<String, String[]> hashT = new Hashtable<String, String[]>(); String[] credentials = new String[] { userName, password }; hashT.put("jmx.remote.credentials", credentials); jmxc = JMXConnectorFactory.connect(url, hashT); mbsc = jmxc.getMBeanServerConnection(); nodeAgent = new ObjectName(connectionType); mbsc.invoke(nodeAgent, operation, null, null); } catch (Exception ex) { log.error("infoAdminServiceStub Initialization fail "); throw new Exception("infoAdminServiceStub Initialization fail " + ex.getMessage()); } }
From source file:cc.kune.kunecli.JMXUtils.java
private static JMXServiceURL getURLForPid(final String pid) throws AttachNotSupportedException, IOException, AgentLoadException, AgentInitializationException { // attach to the target application final VirtualMachine vm = VirtualMachine.attach(pid); // get the connector address String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); // no connector address, so we start the JMX agent if (connectorAddress == null) { final String agent = vm.getSystemProperties().getProperty("java.home") + File.separator + "lib" + File.separator + "management-agent.jar"; vm.loadAgent(agent);// w w w. j a v a 2 s . c o m // agent is started, get the connector address connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); assert connectorAddress != null; } return new JMXServiceURL(connectorAddress); }
From source file:com.exxatools.monitoring.jmx.JmxStats.java
public void setServiceUrl(String serviceUrl) throws MalformedURLException { this.serviceUrl = new JMXServiceURL(serviceUrl); }
From source file:uk.co.gidley.jmxmonitor.services.InternalJmxTest.java
@Test public void testStartupShutdown() throws MalformedObjectNameException, InitialisationException, ConfigurationException { MainConfiguration mainConfiguration = mock(MainConfiguration.class); RegistryShutdownHub registryShutdownHub = mock(RegistryShutdownHub.class); Configuration configuration = new PropertiesConfiguration( "src/test/resources/jmxLocalMonitoringTestConfiguration.properties"); when(mainConfiguration.getConfiguration()).thenReturn(configuration); InternalJmx internalJmx = new InternalJmx(mainConfiguration, registryShutdownHub); verify(registryShutdownHub).addRegistryShutdownListener(internalJmx); // Internal JMX should now be not running try {//from w w w . java 2 s .c o m ManagementFactory.getPlatformMBeanServer().getObjectInstance(internalJmx.getConnectorServerName()); } catch (InstanceNotFoundException e) { assertThat("Exception should not have thrown", false); } try { JMXServiceURL serviceUrl = new JMXServiceURL(configuration.getString("jmxmonitor.localJmx")); JMXConnector jmxc = JMXConnectorFactory.connect(serviceUrl, null); MBeanServerConnection mBeanServerConnection = jmxc.getMBeanServerConnection(); assertThat(mBeanServerConnection, notNullValue()); } catch (IOException e) { assertThat("Exception should not have thrown", false); } // Fire shutdown anyhow internalJmx.registryDidShutdown(); // Check JMX actually closed try { ManagementFactory.getPlatformMBeanServer().getObjectInstance(internalJmx.getConnectorServerName()); assertThat("Exception should have thrown", false); } catch (InstanceNotFoundException e) { } try { JMXServiceURL serviceUrl = new JMXServiceURL(configuration.getString("jmxmonitor.localJmx")); JMXConnector jmxc = JMXConnectorFactory.connect(serviceUrl, null); MBeanServerConnection mBeanServerConnection = jmxc.getMBeanServerConnection(); assertThat("Exception should have thrown", false); } catch (IOException e) { } }
From source file:org.apache.james.modules.server.JMXServer.java
private void doStart() { try {// w w w . ja v a 2 s. co m PropertiesConfiguration configuration = new PropertiesConfiguration( fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + "jmx.properties")); String address = configuration.getString("jmx.address"); int port = configuration.getInt("jmx.port"); String serviceURL = "service:jmx:rmi://" + address + "/jndi/rmi://" + address + ":" + port + "/jmxrmi"; RestrictingRMISocketFactory restrictingRMISocketFactory = new RestrictingRMISocketFactory(address); LocateRegistry.createRegistry(port, restrictingRMISocketFactory, restrictingRMISocketFactory); Map<String, ?> environment = ImmutableMap.of(); jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL(serviceURL), environment, ManagementFactory.getPlatformMBeanServer()); jmxConnectorServer.start(); } catch (Exception e) { throw Throwables.propagate(e); } }