kandi background
Explore Kits

simplejmx | Simple JMX Java Library to help with the publishing | Performance Testing library

 by   j256 Java Version: simplejmx-1.19 License: ISC

 by   j256 Java Version: simplejmx-1.19 License: ISC

Download this library from

kandi X-RAY | simplejmx Summary

simplejmx is a Java library typically used in Testing, Performance Testing, Spring applications. simplejmx has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can download it from GitHub, Maven.
This package provides some Java classes to help with the publishing of objects using JMX.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • simplejmx has a highly active ecosystem.
  • It has 89 star(s) with 23 fork(s). There are 12 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 0 open issues and 4 have been closed. On average issues are closed in 338 days. There are 3 open pull requests and 0 closed requests.
  • It has a positive sentiment in the developer community.
  • The latest version of simplejmx is simplejmx-1.19
simplejmx Support
Best in #Performance Testing
Average in #Performance Testing
simplejmx Support
Best in #Performance Testing
Average in #Performance Testing

quality kandi Quality

  • simplejmx has 0 bugs and 0 code smells.
simplejmx Quality
Best in #Performance Testing
Average in #Performance Testing
simplejmx Quality
Best in #Performance Testing
Average in #Performance Testing

securitySecurity

  • simplejmx has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • simplejmx code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
simplejmx Security
Best in #Performance Testing
Average in #Performance Testing
simplejmx Security
Best in #Performance Testing
Average in #Performance Testing

license License

  • simplejmx is licensed under the ISC License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
simplejmx License
Best in #Performance Testing
Average in #Performance Testing
simplejmx License
Best in #Performance Testing
Average in #Performance Testing

buildReuse

  • simplejmx releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
simplejmx Reuse
Best in #Performance Testing
Average in #Performance Testing
simplejmx Reuse
Best in #Performance Testing
Average in #Performance Testing
Top functions reviewed by kandi - BETA

kandi has reviewed simplejmx and discovered the below as its top functions. This is intended to give you an instant insight into simplejmx implemented functionality, and help decide if they suit your requirements.

  • Print the operations
    • Traverse lines .
      • Starts the JMX service .
        • Discover an attribute method .
          • Look up parameter types and signature .
            • Display type string .
              • The main entry point .
                • Registers bean annotations .
                  • Authenticate against the credentials .
                    • Returns a list of JmxAttributeFieldInfo for this class .

                      Get all kandi verified functions for this library.

                      Get all kandi verified functions for this library.

                      simplejmx Key Features

                      For more information, visit the [SimpleJMX home page](http://256stuff.com/sources/simplejmx/).

                      Online documentation can be found on the home page. Here are the [SimpleJMX Javadocs](http://256stuff.com/sources/simplejmx/javadoc/simplejmx/).

                      Code available from the [git repository](https://github.com/j256/simplejmx). [![CircleCI](https://circleci.com/gh/j256/simplejmx.svg?style=svg)](https://circleci.com/gh/j256/simplejmx) [![CodeCov](https://img.shields.io/codecov/c/github/j256/simplejmx.svg)](https://codecov.io/github/j256/simplejmx/)

                      Maven packages are published via [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.j256.simplejmx/simplejmx/badge.svg?style=flat-square)](https://maven-badges.herokuapp.com/maven-central/com.j256.simplejmx/simplejmx/) [![javadoc](https://javadoc.io/badge2/com.j256.simplejmx/simplejmx/javadoc.svg)](https://javadoc.io/doc/com.j256.simplejmx/simplejmx)

                      Publishing JMX Beans over HTTP for Web Browser

                      copy iconCopydownload iconDownload
                      // start a web server for exposing jmx beans listing on port 8080
                      JmxWebServer jmxWebServer = new JmxWebServer(8080);
                      jmxWebServer.start();

                      Sample Jmx Code

                      copy iconCopydownload iconDownload
                      // create a new JMX server listening on a specific port
                      JmxServer jmxServer = new JmxServer(JMX_PORT);
                      // NOTE: you could also use the platform mbean server:
                      // JmxServer jmxServer = new JmxServer(ManagementFactory.getPlatformMBeanServer());

                      Maven Configuration

                      copy iconCopydownload iconDownload
                      <dependency>
                      	<groupId>com.j256.simplejmx</groupId>
                      	<artifactId>simplejmx</artifactId>
                      	<version>1.19</version>
                      </dependency>

                      How to programmatically invoke MBeans operation of target process

                      copy iconCopydownload iconDownload
                      class Example {
                          public static void main(String[] args) {
                              while (true) {
                              }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          Example
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class GetMBeans {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             Set<ObjectInstance> instances = connection.queryMBeans(null, null);
                             Iterator<ObjectInstance> iterator = instances.iterator();
                             while (iterator.hasNext()) {
                                 ObjectInstance instance = iterator.next();
                                 System.out.println(instance.getClassName() + " " + instance.getObjectName());
                             }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          -javaagent:jacoco-0.8.4/lib/jacocoagent.jar=jmx=true \
                          Example
                      
                      org.jacoco.agent.rt.internal_035b120.Agent org.jacoco:type=Runtime
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class MBeanClient {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             final IProxy proxy = (IProxy) MBeanServerInvocationHandler.newProxyInstance(connection, new ObjectName("org.jacoco:type=Runtime"), IProxy.class, false);
                      
                             final byte[] data = proxy.getExecutionData(false);
                             System.out.println("Got " + data.length + " bytes");
                          }
                      
                          public interface IProxy {
                              String getVersion();
                              String getSessionId();
                              void setSessionId(String id);
                              byte[] getExecutionData(boolean reset);
                              void dump(boolean reset);
                              void reset();
                          }
                      }
                      
                      Got 84 bytes
                      
                      class Example {
                          public static void main(String[] args) {
                              while (true) {
                              }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          Example
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class GetMBeans {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             Set<ObjectInstance> instances = connection.queryMBeans(null, null);
                             Iterator<ObjectInstance> iterator = instances.iterator();
                             while (iterator.hasNext()) {
                                 ObjectInstance instance = iterator.next();
                                 System.out.println(instance.getClassName() + " " + instance.getObjectName());
                             }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          -javaagent:jacoco-0.8.4/lib/jacocoagent.jar=jmx=true \
                          Example
                      
                      org.jacoco.agent.rt.internal_035b120.Agent org.jacoco:type=Runtime
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class MBeanClient {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             final IProxy proxy = (IProxy) MBeanServerInvocationHandler.newProxyInstance(connection, new ObjectName("org.jacoco:type=Runtime"), IProxy.class, false);
                      
                             final byte[] data = proxy.getExecutionData(false);
                             System.out.println("Got " + data.length + " bytes");
                          }
                      
                          public interface IProxy {
                              String getVersion();
                              String getSessionId();
                              void setSessionId(String id);
                              byte[] getExecutionData(boolean reset);
                              void dump(boolean reset);
                              void reset();
                          }
                      }
                      
                      Got 84 bytes
                      
                      class Example {
                          public static void main(String[] args) {
                              while (true) {
                              }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          Example
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class GetMBeans {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             Set<ObjectInstance> instances = connection.queryMBeans(null, null);
                             Iterator<ObjectInstance> iterator = instances.iterator();
                             while (iterator.hasNext()) {
                                 ObjectInstance instance = iterator.next();
                                 System.out.println(instance.getClassName() + " " + instance.getObjectName());
                             }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          -javaagent:jacoco-0.8.4/lib/jacocoagent.jar=jmx=true \
                          Example
                      
                      org.jacoco.agent.rt.internal_035b120.Agent org.jacoco:type=Runtime
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class MBeanClient {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             final IProxy proxy = (IProxy) MBeanServerInvocationHandler.newProxyInstance(connection, new ObjectName("org.jacoco:type=Runtime"), IProxy.class, false);
                      
                             final byte[] data = proxy.getExecutionData(false);
                             System.out.println("Got " + data.length + " bytes");
                          }
                      
                          public interface IProxy {
                              String getVersion();
                              String getSessionId();
                              void setSessionId(String id);
                              byte[] getExecutionData(boolean reset);
                              void dump(boolean reset);
                              void reset();
                          }
                      }
                      
                      Got 84 bytes
                      
                      class Example {
                          public static void main(String[] args) {
                              while (true) {
                              }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          Example
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class GetMBeans {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             Set<ObjectInstance> instances = connection.queryMBeans(null, null);
                             Iterator<ObjectInstance> iterator = instances.iterator();
                             while (iterator.hasNext()) {
                                 ObjectInstance instance = iterator.next();
                                 System.out.println(instance.getClassName() + " " + instance.getObjectName());
                             }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          -javaagent:jacoco-0.8.4/lib/jacocoagent.jar=jmx=true \
                          Example
                      
                      org.jacoco.agent.rt.internal_035b120.Agent org.jacoco:type=Runtime
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class MBeanClient {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             final IProxy proxy = (IProxy) MBeanServerInvocationHandler.newProxyInstance(connection, new ObjectName("org.jacoco:type=Runtime"), IProxy.class, false);
                      
                             final byte[] data = proxy.getExecutionData(false);
                             System.out.println("Got " + data.length + " bytes");
                          }
                      
                          public interface IProxy {
                              String getVersion();
                              String getSessionId();
                              void setSessionId(String id);
                              byte[] getExecutionData(boolean reset);
                              void dump(boolean reset);
                              void reset();
                          }
                      }
                      
                      Got 84 bytes
                      
                      class Example {
                          public static void main(String[] args) {
                              while (true) {
                              }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          Example
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class GetMBeans {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             Set<ObjectInstance> instances = connection.queryMBeans(null, null);
                             Iterator<ObjectInstance> iterator = instances.iterator();
                             while (iterator.hasNext()) {
                                 ObjectInstance instance = iterator.next();
                                 System.out.println(instance.getClassName() + " " + instance.getObjectName());
                             }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          -javaagent:jacoco-0.8.4/lib/jacocoagent.jar=jmx=true \
                          Example
                      
                      org.jacoco.agent.rt.internal_035b120.Agent org.jacoco:type=Runtime
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class MBeanClient {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             final IProxy proxy = (IProxy) MBeanServerInvocationHandler.newProxyInstance(connection, new ObjectName("org.jacoco:type=Runtime"), IProxy.class, false);
                      
                             final byte[] data = proxy.getExecutionData(false);
                             System.out.println("Got " + data.length + " bytes");
                          }
                      
                          public interface IProxy {
                              String getVersion();
                              String getSessionId();
                              void setSessionId(String id);
                              byte[] getExecutionData(boolean reset);
                              void dump(boolean reset);
                              void reset();
                          }
                      }
                      
                      Got 84 bytes
                      
                      class Example {
                          public static void main(String[] args) {
                              while (true) {
                              }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          Example
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class GetMBeans {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             Set<ObjectInstance> instances = connection.queryMBeans(null, null);
                             Iterator<ObjectInstance> iterator = instances.iterator();
                             while (iterator.hasNext()) {
                                 ObjectInstance instance = iterator.next();
                                 System.out.println(instance.getClassName() + " " + instance.getObjectName());
                             }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          -javaagent:jacoco-0.8.4/lib/jacocoagent.jar=jmx=true \
                          Example
                      
                      org.jacoco.agent.rt.internal_035b120.Agent org.jacoco:type=Runtime
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class MBeanClient {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             final IProxy proxy = (IProxy) MBeanServerInvocationHandler.newProxyInstance(connection, new ObjectName("org.jacoco:type=Runtime"), IProxy.class, false);
                      
                             final byte[] data = proxy.getExecutionData(false);
                             System.out.println("Got " + data.length + " bytes");
                          }
                      
                          public interface IProxy {
                              String getVersion();
                              String getSessionId();
                              void setSessionId(String id);
                              byte[] getExecutionData(boolean reset);
                              void dump(boolean reset);
                              void reset();
                          }
                      }
                      
                      Got 84 bytes
                      
                      class Example {
                          public static void main(String[] args) {
                              while (true) {
                              }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          Example
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class GetMBeans {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             Set<ObjectInstance> instances = connection.queryMBeans(null, null);
                             Iterator<ObjectInstance> iterator = instances.iterator();
                             while (iterator.hasNext()) {
                                 ObjectInstance instance = iterator.next();
                                 System.out.println(instance.getClassName() + " " + instance.getObjectName());
                             }
                          }
                      }
                      
                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          -javaagent:jacoco-0.8.4/lib/jacocoagent.jar=jmx=true \
                          Example
                      
                      org.jacoco.agent.rt.internal_035b120.Agent org.jacoco:type=Runtime
                      
                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class MBeanClient {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             final IProxy proxy = (IProxy) MBeanServerInvocationHandler.newProxyInstance(connection, new ObjectName("org.jacoco:type=Runtime"), IProxy.class, false);
                      
                             final byte[] data = proxy.getExecutionData(false);
                             System.out.println("Got " + data.length + " bytes");
                          }
                      
                          public interface IProxy {
                              String getVersion();
                              String getSessionId();
                              void setSessionId(String id);
                              byte[] getExecutionData(boolean reset);
                              void dump(boolean reset);
                              void reset();
                          }
                      }
                      
                      Got 84 bytes
                      
                      -Dcom.sun.management.jmxremote.port=1240
                      -Dcom.sun.management.jmxremote.local.only=false
                      -Dcom.sun.management.jmxremote.authenticate=false
                      -Dcom.sun.management.jmxremote.ssl=false
                      
                      public static void main(String[] args) throws Exception {
                          JmxClient client = new JmxClient("localhost", 1240);
                          client.invokeOperation(new ObjectName("org.jacoco:type=Runtime"), "dump", new Object[] {true});
                          client.close();
                      }
                      
                      -Dcom.sun.management.jmxremote.port=1240
                      -Dcom.sun.management.jmxremote.local.only=false
                      -Dcom.sun.management.jmxremote.authenticate=false
                      -Dcom.sun.management.jmxremote.ssl=false
                      
                      public static void main(String[] args) throws Exception {
                          JmxClient client = new JmxClient("localhost", 1240);
                          client.invokeOperation(new ObjectName("org.jacoco:type=Runtime"), "dump", new Object[] {true});
                          client.close();
                      }
                      

                      Community Discussions

                      Trending Discussions on simplejmx
                      • How to programmatically invoke MBeans operation of target process
                      Trending Discussions on simplejmx

                      QUESTION

                      How to programmatically invoke MBeans operation of target process

                      Asked 2019-May-28 at 12:20

                      I want to simulate what jconsole does by:

                      1. Identifying a running process that exposes jmx functionality (e.g: pid: 14796 FreshProject.jar)

                      2. Listing the available MBeans libraries (e.g: org.jacoco)

                      3. Invoking an operation (e.g: clicking dump)

                      MBeans Operation example

                      I've tried using the simplejmx library as mentioned here but I am confused as to what hostName and port I should use. I tried passing localhost and 1099 as I've read these are the default values but it errors java.net.ConnectException: Connection refused: connect.

                      Please don't point me to a different sof post and close this as I most probably already read and tried it several times.

                      ANSWER

                      Answered 2019-May-28 at 10:37

                      I want to simulate what jconsole does

                      Have a look at the implementation of jconsole - see http://openjdk.java.net/tools/svc/jconsole/ and https://github.com/openjdk/jdk/tree/master/src/jdk.jconsole/share/classes

                      I am confused as to what hostName and port I should use. I tried passing localhost and 1099 as I've read these are the default values but it errors java.net.ConnectException: Connection refused: connect.

                      As per https://docs.oracle.com/en/java/javase/11/management/monitoring-and-management-using-jmx-technology.html by default there is no port. And JConsole uses Attach API - see https://github.com/openjdk/jdk/blob/master/src/jdk.jconsole/share/classes/sun/tools/jconsole/LocalVirtualMachine.java In this code you'll also find answer on

                      Identifying a running process that exposes jmx functionality

                      To connect via port you need to specify appropriate parameters. For example following Example.java

                      class Example {
                          public static void main(String[] args) {
                              while (true) {
                              }
                          }
                      }
                      

                      can be started as

                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          Example
                      

                      Then

                      Listing the available MBeans

                      can be done as

                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class GetMBeans {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             Set<ObjectInstance> instances = connection.queryMBeans(null, null);
                             Iterator<ObjectInstance> iterator = instances.iterator();
                             while (iterator.hasNext()) {
                                 ObjectInstance instance = iterator.next();
                                 System.out.println(instance.getClassName() + " " + instance.getObjectName());
                             }
                          }
                      }
                      

                      After start of the above Example also with JaCoCo

                      java \
                          -Dcom.sun.management.jmxremote.port=1099 \
                          -Dcom.sun.management.jmxremote.authenticate=false \
                          -Dcom.sun.management.jmxremote.ssl=false \
                          -javaagent:jacoco-0.8.4/lib/jacocoagent.jar=jmx=true \
                          Example
                      

                      execution of javac GetMBeans.java && java GetMBeans | grep jacoco produces

                      org.jacoco.agent.rt.internal_035b120.Agent org.jacoco:type=Runtime
                      

                      Invoking an operation

                      is shown in JaCoCo documentation - see MBeanClient.java at https://www.jacoco.org/jacoco/trunk/doc/api.html

                      import javax.management.MBeanServer;
                      import javax.management.MBeanServerConnection;
                      import javax.management.MBeanServerInvocationHandler;
                      import javax.management.ObjectInstance;
                      import javax.management.ObjectName;
                      import javax.management.remote.JMXConnector;
                      import javax.management.remote.JMXConnectorFactory;
                      import javax.management.remote.JMXServiceURL;
                      
                      import java.lang.management.ManagementFactory;
                      import java.util.Iterator;
                      import java.util.Set;
                      
                      class MBeanClient {
                          public static void main(final String[] args) throws Exception {
                             final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
                             final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                             final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
                      
                             final IProxy proxy = (IProxy) MBeanServerInvocationHandler.newProxyInstance(connection, new ObjectName("org.jacoco:type=Runtime"), IProxy.class, false);
                      
                             final byte[] data = proxy.getExecutionData(false);
                             System.out.println("Got " + data.length + " bytes");
                          }
                      
                          public interface IProxy {
                              String getVersion();
                              String getSessionId();
                              void setSessionId(String id);
                              byte[] getExecutionData(boolean reset);
                              void dump(boolean reset);
                              void reset();
                          }
                      }
                      

                      execution of javac MBeanClient.java && java MBeanClient produces

                      Got 84 bytes
                      

                      Source https://stackoverflow.com/questions/56337983

                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                      Vulnerabilities

                      No vulnerabilities reported

                      Install simplejmx

                      You can download it from GitHub, Maven.
                      You can use simplejmx like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the simplejmx component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

                      Support

                      For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

                      DOWNLOAD this Library from

                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      Share this Page

                      share link
                      Consider Popular Performance Testing Libraries
                      Try Top Libraries by j256
                      Compare Performance Testing Libraries with Highest Support
                      Compare Performance Testing Libraries with Highest Quality
                      Compare Performance Testing Libraries with Highest Security
                      Compare Performance Testing Libraries with Permissive License
                      Compare Performance Testing Libraries with Highest Reuse
                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      • © 2022 Open Weaver Inc.