List of usage examples for javax.management.remote JMXConnectorFactory connect
public static JMXConnector connect(JMXServiceURL serviceURL, Map<String, ?> environment) throws IOException
Creates a connection to the connector server at the given address.
This method is equivalent to:
JMXConnector conn = JMXConnectorFactory.newJMXConnector(serviceURL, environment); conn.connect(environment);
From source file:org.wso2.carbon.automation.test.utils.jmxclient.generic.JMXClient.java
/** * connect to org.wso2.carbon for JMX monitoring * * @return return MBeanServerConnection//from w w w .j a v a 2 s .com * @throws java.io.IOException error in making connection * @throws javax.management.MalformedObjectNameException error in making connection */ public MBeanServerConnection connect(String jmxServerURL) throws IOException, MalformedObjectNameException { //need to read rmi ports from environment config JMXServiceURL url = new JMXServiceURL(jmxServerURL); 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(); if (mbsc != null) { return mbsc; } return null; }
From source file:org.wso2.carbon.dss.jmx.statistics.test.utils.JMXClient.java
/** * connect to org.wso2.carbon for JMX monitoring * * @return - return MBeanServerConnection * @throws java.io.IOException - error in making connection * @throws javax.management.MalformedObjectNameException * - error in making connection *//* ww w. j a va2s . co m*/ public MBeanServerConnection connect() throws IOException, MalformedObjectNameException { try { //need to read rmi ports from environment config JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi://localhost:11111/jndi/rmi://" + hostName + ":9999/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(); if (mbsc != null) { return mbsc; } } catch (MalformedURLException e) { log.error("Error while creating Jmx connection ", e); throw new MalformedURLException(); } catch (IOException e) { log.error("Error while creating Jmx connection ", e); throw new IOException("Error while creating Jmx connection " + e); } return null; }
From source file:org.pssframework.jmx.MBeanServerConnectionInterceptor.java
public Object getObject() throws Exception { JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(serviceUrl), null); this.connection = connector.getMBeanServerConnection(); ProxyFactory connectionProxy = new ProxyFactory(this.connection); connectionProxy.addAdvice(this); return connectionProxy.getProxy(); }
From source file:fr.openfarm.jmx.service.JMXQuery.java
@Override public void connect(String username, String password, String url) throws IOException { Map<String, Object> environment = null; if ("".equals(username)) { username = null;/* w w w. j a v a2s . c om*/ } if ("".equals(password)) { username = null; } if (username != null && password != null) { environment = new HashMap<String, Object>(); environment.put(JMXConnector.CREDENTIALS, new String[] { username, password }); environment.put(USERNAME_KEY, username); environment.put(PASSWORD_KEY, password); } JMXServiceURL jmxUrl = new JMXServiceURL(url); if (environment != null) { log.info("connect with user/pass"); connector = JMXConnectorFactory.connect(jmxUrl, environment); } else { log.info("connect without user/pass"); connector = JMXConnectorFactory.connect(jmxUrl); } connection = connector.getMBeanServerConnection(); }
From source file:org.wso2.esb.integration.common.utils.clients.JMXClient.java
/** * connect to org.wso2.carbon for JMX monitoring * * @return return MBeanServerConnection * @throws java.io.IOException - error in making connection * @throws javax.management.MalformedObjectNameException - error in making connection *//*from ww w . j av a2s. co m*/ public MBeanServerConnection connect() throws IOException, MalformedObjectNameException { try { JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost:" + rmiServerPort + "/jndi/rmi://" + hostName + ":" + 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(); if (mbsc != null) { return mbsc; } } catch (MalformedURLException e) { log.error("Error while creating Jmx connection ", e); throw new MalformedURLException(); } catch (IOException e) { log.error("Error while creating Jmx connection ", e); throw new IOException("Error while creating Jmx connection " + e); } return null; }
From source file:org.wso2.dss.integration.test.jira.issues.CARBON15928JMXDisablingTest.java
private MBeanInfo testMBeanForDatasource() throws Exception { Map<String, String[]> env = new HashMap<>(); String[] credentials = { "admin", "admin" }; env.put(JMXConnector.CREDENTIALS, credentials); try {/*from ww w .j a v a2s . com*/ String url = "service:jmx:rmi://localhost:12311/jndi/rmi://localhost:11199/jmxrmi"; JMXServiceURL jmxUrl = new JMXServiceURL(url); JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl, env); MBeanServerConnection mBeanServer = jmxConnector.getMBeanServerConnection(); ObjectName mbeanObject = new ObjectName(dataSourceName + ",-1234:type=DataSource"); MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(mbeanObject); return mBeanInfo; } catch (MalformedURLException | MalformedObjectNameException | IntrospectionException | ReflectionException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } }
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 w w. j a va 2 s . 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: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: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 www .ja v a 2 s. c om 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: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 {/*from www . j a v a 2 s . co 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); } }