Example usage for javax.management.remote JMXServiceURL JMXServiceURL

List of usage examples for javax.management.remote JMXServiceURL JMXServiceURL

Introduction

In this page you can find the example usage for javax.management.remote JMXServiceURL JMXServiceURL.

Prototype

public JMXServiceURL(String serviceURL) throws MalformedURLException 

Source Link

Document

Constructs a JMXServiceURL by parsing a Service URL string.

Usage

From source file:de.iew.spring.integration.SpringIntegrationJmxTest.java

@Test
public void testJmxClientClassic() throws Exception {
    JMXServiceURL clientURL = new JMXServiceURL(this.serviceUrl);
    Map clientEnv = new HashMap();

    JMXConnector connector = JMXConnectorFactory.connect(clientURL, clientEnv);
    MBeanServerConnection connection = connector.getMBeanServerConnection();

    ObjectName mbeanName = new ObjectName(this.jmxTestServiceObjectName);
    JmxTestService mbeanProxy = JMX.newMBeanProxy(connection, mbeanName, JmxTestService.class, true);

    mbeanProxy.setName("Foo Bar");
    mbeanProxy.sayHello();//from  w w  w  .j a v  a 2 s  . c  o m

    String[] hellos = mbeanProxy.getStoredHellos();
    Assert.assertEquals(1, hellos.length);

    mbeanProxy.clearHelloStore();

    hellos = mbeanProxy.getStoredHellos();
    Assert.assertEquals(0, hellos.length);
}

From source file:org.hyperic.hq.product.jmx.MBeanDumper.java

protected boolean isValidURL(String url) {
    if (url.startsWith(MxUtil.PTQL_PREFIX)) {
        return true;
    }/*from w ww  .ja  va2  s. com*/
    try {
        new JMXServiceURL(url);
        return true;
    } catch (MalformedURLException e) {
        return false;
    }
}

From source file:org.wso2.carbon.automation.test.utils.jmxclient.generic.JMXClient.java

/**
 * connect to org.wso2.carbon for JMX monitoring
 *
 * @return return MBeanServerConnection//w  w  w  .j  a  v  a2 s.c  o  m
 * @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:com.xoriant.jmx.pool.JmxPoolFactory.java

/**
 * The create method will create the actual JMX connection.
 *//*from   w  w  w  .j  ava 2s.c o  m*/
@SuppressWarnings("unchecked")
@Override
public Q create() throws Exception {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("In create method");
    }
    JMXServiceURL url = null;
    JMXConnector jmxConnector = null;
    StringBuilder vUrlString = new StringBuilder(ApplicationProperty.JMX_URL_FRONT);
    vUrlString.append(host);
    vUrlString.append(ApplicationProperty.COLON);
    vUrlString.append(port);
    vUrlString.append(ApplicationProperty.JMX_URL_BACK);
    try {
        url = new JMXServiceURL(vUrlString.toString());
        jmxConnector = JMXConnectorFactory.connect(url, null);
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
        throw new ConnectionNotFoundException(host, port);
    }
    return (Q) jmxConnector;
}

From source file:com.espertech.esper.example.servershellclient.ServerShellClientMain.java

public ServerShellClientMain() throws Exception {
    log.info("Loading properties");
    Properties properties = new Properties();
    InputStream propertiesIS = ServerShellClientMain.class.getClassLoader()
            .getResourceAsStream(ServerShellConstants.CONFIG_FILENAME);
    if (propertiesIS == null) {
        throw new RuntimeException(
                "Properties file '" + ServerShellConstants.CONFIG_FILENAME + "' not found in classpath");
    }//from   ww  w.j a  v  a2  s.  c  o m
    properties.load(propertiesIS);

    // Attached via JMX to running server
    log.info("Attach to server via JMX");
    JMXServiceURL url = new JMXServiceURL(properties.getProperty(ServerShellConstants.MGMT_SERVICE_URL));
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    ObjectName mBeanName = new ObjectName(ServerShellConstants.MGMT_MBEAN_NAME);
    EPServiceProviderJMXMBean proxy = (EPServiceProviderJMXMBean) MBeanServerInvocationHandler
            .newProxyInstance(mbsc, mBeanName, EPServiceProviderJMXMBean.class, true);

    // Connect to JMS
    log.info("Connecting to JMS server");
    String factory = properties.getProperty(ServerShellConstants.JMS_CONTEXT_FACTORY);
    String jmsurl = properties.getProperty(ServerShellConstants.JMS_PROVIDER_URL);
    String connFactoryName = properties.getProperty(ServerShellConstants.JMS_CONNECTION_FACTORY_NAME);
    String user = properties.getProperty(ServerShellConstants.JMS_USERNAME);
    String password = properties.getProperty(ServerShellConstants.JMS_PASSWORD);
    String destination = properties.getProperty(ServerShellConstants.JMS_INCOMING_DESTINATION);
    boolean isTopic = Boolean.parseBoolean(properties.getProperty(ServerShellConstants.JMS_IS_TOPIC));
    JMSContext jmsCtx = JMSContextFactory.createContext(factory, jmsurl, connFactoryName, user, password,
            destination, isTopic);

    // Create statement via JMX
    log.info("Creating a statement via Java Management Extensions (JMX) MBean Proxy");
    proxy.createEPL("select * from SampleEvent where duration > 9.9", "filterStatement",
            new ClientSideUpdateListener());

    // Get producer
    jmsCtx.getConnection().start();
    MessageProducer producer = jmsCtx.getSession().createProducer(jmsCtx.getDestination());

    Random random = new Random();
    String[] ipAddresses = { "127.0.1.0", "127.0.2.0", "127.0.3.0", "127.0.4.0" };
    NumberFormat format = NumberFormat.getInstance();

    // Send messages
    for (int i = 0; i < 1000; i++) {
        String ipAddress = ipAddresses[random.nextInt(ipAddresses.length)];
        double duration = 10 * random.nextDouble();
        String durationStr = format.format(duration);
        String payload = ipAddress + "," + durationStr;

        BytesMessage bytesMessage = jmsCtx.getSession().createBytesMessage();
        bytesMessage.writeBytes(payload.getBytes());
        bytesMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
        producer.send(bytesMessage);

        if (i % 100 == 0) {
            log.info("Sent " + i + " messages");
        }
    }

    // Create statement via JMX
    log.info("Destroing statement via Java Management Extensions (JMX) MBean Proxy");
    proxy.destroy("filterStatement");

    log.info("Shutting down JMS client connection");
    jmsCtx.destroy();

    log.info("Exiting");
    System.exit(-1);
}

From source file:io.mapzone.controller.um.launcher.ArenaLauncher.java

protected void configureInstance(ProjectInstanceRecord instance) throws MalformedURLException {
    // config via JMX
    String url = "service:jmx:rmi:///jndi/rmi://" + instance.host.get().inetAddress.get() + ":"
            + instance.process.get().jmxPort.get() + "/jmxrmi";
    JMXServiceURL serviceUrl = new JMXServiceURL(url);
    try (JMXConnector connector = JMXConnectorFactory.connect(serviceUrl, null);) {
        MBeanServerConnection conn = connector.getMBeanServerConnection();

        log.info(url);// ww  w .  ja  v  a  2 s  . c om
        while (conn.queryNames(ArenaConfigMBean.NAME.get(), null).isEmpty()) {
            log.info("No such MBean: " + ArenaConfigMBean.NAME.get());
            Thread.sleep(100);
        }

        String localHttpPort = ControllerPlugin.instance().httpPort();

        ArenaConfigMBean arenaConfig = JMX.newMBeanProxy(conn, ArenaConfigMBean.NAME.get(),
                ArenaConfigMBean.class);
        checked(() -> arenaConfig.setAppTitle(instance.project.get()));
        checked(() -> arenaConfig.setServiceAuthToken(project().serviceAuthToken.get())); // send before URLs!!!
        checked(() -> arenaConfig.setCatalogServerUrl("http://localhost:" + localHttpPort + "/csw"));
        checked(() -> arenaConfig.setProxyUrl(ProxyServlet.projectUrlBase(project())));
        checked(() -> arenaConfig.setProjectCatalogId(project().catalogId.get()));

        log.info("Instance process configured.");
    } catch (Throwable e) {
        log.warn("Error while configuring instance.", e);
    }
}

From source file:org.pssframework.jmx.MBeanServerConnectionInterceptor.java

private void reconnect() throws IOException, MalformedURLException {
    JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(serviceUrl), null);
    this.connection = connector.getMBeanServerConnection();
}

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
 *//* w  w w . j a  va2 s  . c om*/
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.eclipse.virgo.ide.runtime.internal.core.command.AbstractJmxServerCommand.java

private JMXConnector getJmxConnector() throws IOException {
    Hashtable<String, Object> h = new Hashtable<String, Object>();
    //      String username = behaviour.getDmServer().getDeployerUsername();
    //      String password = behaviour.getDmServer().getDeployerPassword();
    //      if (StringUtils.hasText(username)) {
    //         String[] credentials = new String[] { username, password };
    //         h.put(JMX_REMOTE_CREDENTIALS, credentials);
    //      }/*from   w w  w  .j a v a 2 s. com*/
    Server server = ServerUtils.getServer(serverBehaviour);

    if (serverBehaviour.getMBeanServerIp() == null) {
        throw new IOException("MBean server not open for connection");
    }
    String connectorUrl = String.format(JMX_CONNECTOR_URL, serverBehaviour.getMBeanServerIp(),
            server.getMBeanServerPort());
    return JMXConnectorFactory.connect(new JMXServiceURL(connectorUrl), h);
}

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 w w w .  j a  v a 2  s  .  c  o  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;
}