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:org.camid.rulemanager.ServerShellClientMain.java

public static EPServiceProviderJMXMBean ServerShellClientMain() throws Exception {

    log.info("Loading properties");

    log.info("Attach to server via JMX");
    //        JMXServiceURL url = new JMXServiceURL(properties.getProperty(ServerShellConstants.MGMT_SERVICE_URL));
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:5554/server");

    //        String jmxServiceURL = "service:jmx:rmi:///jndi/rmi://localhost:5554/server";
    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);

    //        proxy.destroy("sensor1c");
    return proxy;

    // Create statement via JMX
    //           System.out.println("Creating a statement via Java Management Extensions (JMX) MBean Proxy");
    //           proxy.createEPL("select * from sensor(value>20)","filter", "null");
    ////from   w ww . j  a  v a 2  s .co  m
    //
    //        System.out.println("Destroing statement via Java Management Extensions (JMX) MBean Proxy");
    //        proxy.destroy("filterStatement");
    //
    //
    //        System.out.println("Exiting");
    //        System.exit(-1);
}

From source file:com.adaptris.core.services.jmx.JmxOperationInvoker.java

public Object invoke(String serviceUrl, String objectName, String username, String password, String methodName,
        Object[] params, String[] signatures) throws Exception {
    Map<String, String[]> env = new HashMap<>();
    if ((!StringUtils.isEmpty(username)) && (!StringUtils.isEmpty(password))) {
        String[] credentials = { username, Password.decode(password) };
        env.put(JMXConnector.CREDENTIALS, credentials);
    }/*from   w  ww  .jav  a 2s  . c om*/
    JMXServiceURL jmxServiceUrl = new JMXServiceURL(serviceUrl);
    JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceUrl, env);
    ObjectName objectNameInst = ObjectName.getInstance(objectName);
    MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection();
    try {
        return mbeanConn.invoke(objectNameInst, methodName, params, signatures);
    } finally {
        jmxConnector.close();

    }
}

From source file:de.unisb.cs.st.javalanche.mutation.runtime.jmx.MutationMxClient.java

public static boolean connect(int i) {
    JMXConnector jmxc = null;/*  w w  w. j a  v a 2 s. c o  m*/
    JMXServiceURL url = null;

    try {
        url = new JMXServiceURL(MXBeanRegisterer.ADDRESS + i);
        jmxc = JMXConnectorFactory.connect(url, null);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        return false;
        // System.out.println("Could not connect to address: " + url);
        // e.printStackTrace();
    }
    if (jmxc != null) {
        try {
            MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
            ObjectName objectName = new ObjectName(MXBeanRegisterer.OBJECT_NAME);
            Object numberOfMutations = mbsc.getAttribute(objectName, "NumberOfMutations");
            Object currentTest = mbsc.getAttribute(objectName, "CurrentTest");
            Object currentMutation = mbsc.getAttribute(objectName, "CurrentMutation");
            Object allMutations = mbsc.getAttribute(objectName, "Mutations");
            Object mutationsDuration = mbsc.getAttribute(objectName, "MutationDuration");
            Object testDuration = mbsc.getAttribute(objectName, "TestDuration");
            //            Object mutationSummary = mbsc.getAttribute(objectName,
            //                  "MutationSummary");

            final RuntimeMXBean remoteRuntime = ManagementFactory.newPlatformMXBeanProxy(mbsc,
                    ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);

            final MemoryMXBean remoteMemory = ManagementFactory.newPlatformMXBeanProxy(mbsc,
                    ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class);
            System.out.print("Connection: " + i + "  ");
            System.out.println("Target VM: " + remoteRuntime.getName() + " - " + remoteRuntime.getVmVendor()
                    + " - " + remoteRuntime.getSpecVersion() + " - " + remoteRuntime.getVmVersion());
            System.out.println(
                    "Running for: " + DurationFormatUtils.formatDurationHMS(remoteRuntime.getUptime()));
            System.out
                    .println("Memory usage: Heap - " + formatMemory(remoteMemory.getHeapMemoryUsage().getUsed())
                            + "  Non Heap - " + formatMemory(remoteMemory.getNonHeapMemoryUsage().getUsed()));

            String mutationDurationFormatted = DurationFormatUtils
                    .formatDurationHMS(Long.parseLong(mutationsDuration.toString()));
            String testDurationFormatted = DurationFormatUtils
                    .formatDurationHMS(Long.parseLong(testDuration.toString()));
            if (DEBUG_ADD) {
                System.out.println("Classpath: " + remoteRuntime.getClassPath());
                System.out.println("Args: " + remoteRuntime.getInputArguments());
                System.out.println("All Mutations: " + allMutations);
            }
            //            System.out.println(mutationSummary);
            System.out.println(
                    "Current mutation (Running for: " + mutationDurationFormatted + "): " + currentMutation);
            System.out.println("Mutations tested: " + numberOfMutations);
            System.out.println("Current test:   (Running for: " + testDurationFormatted + "): " + currentTest);

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (MalformedObjectNameException e) {
            e.printStackTrace();
        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (AttributeNotFoundException e) {
            e.printStackTrace();
        } catch (InstanceNotFoundException e) {
            e.printStackTrace();
        } catch (MBeanException e) {
            e.printStackTrace();
        } catch (ReflectionException e) {
            e.printStackTrace();
        } finally {
            try {
                jmxc.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return true;
}

From source file:org.opendaylight.infrautils.diagstatus.MBeanUtils.java

public static JMXServiceURL getJMXUrl(String targetHost) throws MalformedURLException {
    String jmxUrl = constructJmxUrl(targetHost, RMI_REGISTRY_PORT);
    return new JMXServiceURL(jmxUrl);
}

From source file:com.all.services.ServiceConsole.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from  w w w . j  a v  a 2s .  c om*/
        LOG.info("Connecting to JMX service...");
        if (args.length < 2) {
            LOG.error("Incorrect usage of Ultrapeer console.\n\n Args should be 'command password [host]'");
            throw new IllegalArgumentException("Not enough agrugments to run.");
        }
        HashMap env = new HashMap();
        env.put("jmx.remote.credentials", new String[] { "controlRole", args[1] });
        String hostname = args.length > 2 ? args[2] : "";
        JMXConnector jmxc = JMXConnectorFactory
                .connect(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + hostname + ":9999/jmxrmi"), env);
        ServiceMonitorMBean mbeanProxy = JMX.newMBeanProxy(jmxc.getMBeanServerConnection(),
                new ObjectName("com.all.services:type=ServiceMonitor"), ServiceMonitorMBean.class, true);
        handleCommand(mbeanProxy, args[0]);
        jmxc.close();
        LOG.info("Done.");
    } catch (Exception e) {
        LOG.error(e, e);
    }
}

From source file:gr.cslab.Metric_test.java

static boolean connectHost(String hostName) {
    try {/*  w w w . j  a v a  2s. c  o  m*/
        String url = "service:jmx:rmi:///jndi/rmi://" + hostName + ":" + port + "/jmxrmi";
        System.out.println("Using host: " + hostName + " (" + url + ")");
        JMXServiceURL serviceUrl = new JMXServiceURL(url);
        JMXConnector jmxc = JMXConnectorFactory.connect(serviceUrl, null);
        hostConnections.put(hostName, jmxc);
    } catch (MalformedURLException ex) {
        System.err.println("ERROR: malformed url");
        return false;
    } catch (IOException ex) {
        System.err.println("ERROR: could not connect to: " + hostName);
        hostConnections.remove(hostName);
        return false;
    }
    return true;
}

From source file:org.springside.modules.utils.jmx.JmxClientTemplate.java

/**
 * JMX Server./*from w w  w . j a va 2s  . c o  m*/
 */

private void initConnector(final String serviceUrl, final String userName, final String passwd)
        throws IOException {
    JMXServiceURL url = new JMXServiceURL(serviceUrl);

    boolean hasCredentlals = StringUtils.isNotBlank(userName);
    if (hasCredentlals) {
        Map environment = Collections.singletonMap(JMXConnector.CREDENTIALS, new String[] { userName, passwd });
        connector = JMXConnectorFactory.connect(url, environment);
    } else {
        connector = JMXConnectorFactory.connect(url);
    }

    connection = connector.getMBeanServerConnection();
    connected.set(true);
}

From source file:io.galeb.router.tests.client.JmxClientService.java

@PostConstruct
public void start() {
    try {/*from  w w  w  .jav a 2  s. co m*/
        String jmxUrl = ConnectorAddressLink.importFrom(Info.getPid());
        if (jmxUrl != null) {
            final JMXServiceURL url = new JMXServiceURL(jmxUrl);
            final JMXConnector jmxConn = JMXConnectorFactory.connect(url);
            client = jmxConn.getMBeanServerConnection();
            enabled.set(true);
        }
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug(ExceptionUtils.getStackTrace(e));
        }
    }
}

From source file:com.rosy.bill.utils.jmx.JmxClientTemplate.java

/**
 * JMX Server.//from w  w  w .j  a  v  a  2  s .  c om
 */
@SuppressWarnings("unchecked")
private void initConnector(final String serviceUrl, final String userName, final String passwd)
        throws IOException {
    JMXServiceURL url = new JMXServiceURL(serviceUrl);

    boolean hasCredentlals = StringUtils.isNotBlank(userName);
    if (hasCredentlals) {
        Map environment = Collections.singletonMap(JMXConnector.CREDENTIALS, new String[] { userName, passwd });
        connector = JMXConnectorFactory.connect(url, environment);
    } else {
        connector = JMXConnectorFactory.connect(url);
    }

    connection = connector.getMBeanServerConnection();
    connected.set(true);
}

From source file:com.fusesource.forge.jmstest.probe.jmx.JMXConnectionFactory.java

public JMXConnector getConnector() {

    JMXConnector connector = null;

    try {//from   ww  w . j  a  va 2s  .c om
        if (connector == null) {
            if (username != null && password != null) {
                Map<String, String[]> m = new HashMap<String, String[]>();
                m.put(JMXConnector.CREDENTIALS, new String[] { username, password });
                connector = JMXConnectorFactory.connect(new JMXServiceURL(url), m);
            } else {
                connector = JMXConnectorFactory.connect(new JMXServiceURL(url));
            }
        }
    } catch (IOException ioe) {
        // TODO: do this right
        log().error("Error connecting to JMX server ", ioe);
    }
    return connector;
}