@Test public void loadJmxTest() throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { JamService jamService = new JamService("http: int port = jamService.loadJMXAgent(-1); assert(port != -1); }
public int loadJMXAgent(int port) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { String name = ManagementFactory.getRuntimeMXBean().getName(); VirtualMachine vm = VirtualMachine.attach(name.substring(0, name.indexOf('@'))); String remoteConnectorPort = vm.getSystemProperties().getProperty("com.sun.management.jmxremote.port"); if (remoteConnectorPort != null) { final String remoteConnectorAddress = "service:jmx:rmi: LOGGER.info("JMX Available at " + remoteConnectorAddress); return new Integer(remoteConnectorPort); } int localPort = port; if (localPort == -1) { ServerSocket s = new ServerSocket(0); localPort = s.getLocalPort(); s.close(); } final String home = vm.getSystemProperties().getProperty("java.home"); final String agent = home + File.separator + "lib" + File.separator + "management-agent.jar"; vm.loadAgent(agent, "com.sun.management.jmxremote.port=" + localPort + "," + "com.sun.management.jmxremote.authenticate=false,com.sun.management.jmxremote.ssl=false"); final String remoteConnectorAddress = "service:jmx:rmi: LOGGER.info("JMX Available at " + remoteConnectorAddress); vm.detach(); return localPort; }
JamService { public int loadJMXAgent(int port) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { String name = ManagementFactory.getRuntimeMXBean().getName(); VirtualMachine vm = VirtualMachine.attach(name.substring(0, name.indexOf('@'))); String remoteConnectorPort = vm.getSystemProperties().getProperty("com.sun.management.jmxremote.port"); if (remoteConnectorPort != null) { final String remoteConnectorAddress = "service:jmx:rmi: LOGGER.info("JMX Available at " + remoteConnectorAddress); return new Integer(remoteConnectorPort); } int localPort = port; if (localPort == -1) { ServerSocket s = new ServerSocket(0); localPort = s.getLocalPort(); s.close(); } final String home = vm.getSystemProperties().getProperty("java.home"); final String agent = home + File.separator + "lib" + File.separator + "management-agent.jar"; vm.loadAgent(agent, "com.sun.management.jmxremote.port=" + localPort + "," + "com.sun.management.jmxremote.authenticate=false,com.sun.management.jmxremote.ssl=false"); final String remoteConnectorAddress = "service:jmx:rmi: LOGGER.info("JMX Available at " + remoteConnectorAddress); vm.detach(); return localPort; } }
JamService { public int loadJMXAgent(int port) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { String name = ManagementFactory.getRuntimeMXBean().getName(); VirtualMachine vm = VirtualMachine.attach(name.substring(0, name.indexOf('@'))); String remoteConnectorPort = vm.getSystemProperties().getProperty("com.sun.management.jmxremote.port"); if (remoteConnectorPort != null) { final String remoteConnectorAddress = "service:jmx:rmi: LOGGER.info("JMX Available at " + remoteConnectorAddress); return new Integer(remoteConnectorPort); } int localPort = port; if (localPort == -1) { ServerSocket s = new ServerSocket(0); localPort = s.getLocalPort(); s.close(); } final String home = vm.getSystemProperties().getProperty("java.home"); final String agent = home + File.separator + "lib" + File.separator + "management-agent.jar"; vm.loadAgent(agent, "com.sun.management.jmxremote.port=" + localPort + "," + "com.sun.management.jmxremote.authenticate=false,com.sun.management.jmxremote.ssl=false"); final String remoteConnectorAddress = "service:jmx:rmi: LOGGER.info("JMX Available at " + remoteConnectorAddress); vm.detach(); return localPort; } JamService(String jamServerBaseUrl); }
JamService { public int loadJMXAgent(int port) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { String name = ManagementFactory.getRuntimeMXBean().getName(); VirtualMachine vm = VirtualMachine.attach(name.substring(0, name.indexOf('@'))); String remoteConnectorPort = vm.getSystemProperties().getProperty("com.sun.management.jmxremote.port"); if (remoteConnectorPort != null) { final String remoteConnectorAddress = "service:jmx:rmi: LOGGER.info("JMX Available at " + remoteConnectorAddress); return new Integer(remoteConnectorPort); } int localPort = port; if (localPort == -1) { ServerSocket s = new ServerSocket(0); localPort = s.getLocalPort(); s.close(); } final String home = vm.getSystemProperties().getProperty("java.home"); final String agent = home + File.separator + "lib" + File.separator + "management-agent.jar"; vm.loadAgent(agent, "com.sun.management.jmxremote.port=" + localPort + "," + "com.sun.management.jmxremote.authenticate=false,com.sun.management.jmxremote.ssl=false"); final String remoteConnectorAddress = "service:jmx:rmi: LOGGER.info("JMX Available at " + remoteConnectorAddress); vm.detach(); return localPort; } JamService(String jamServerBaseUrl); HttpClient getClient(); void setClient(HttpClient client); String getJamServerBaseUrl(); void setJamServerBaseUrl(String jamServerBaseUrl); void addServerToServiceQueue(final String queueName, final String brokerUrl,
                                        final String host, final int port); void disableServiceQueue(final String queueName); boolean doesServiceQueueExist(final String queueName, final String brokerUrl); void enableServiceQueue(final String queueName); void registerServiceQueue(final String queueName, final String brokerUrl,
                                     final int queryIntervalInSeconds, final boolean resetStatisticsAfterQuery,
                                     final boolean profileEnabled); void removeServerFromServiceQueue(final String queueName, final String brokerUrl,
                                             final String host, final int port); void removeServiceQueue(final String queueName); void runGather(final String queueName, final String brokerUrl); int loadJMXAgent(int port); }
JamService { public int loadJMXAgent(int port) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { String name = ManagementFactory.getRuntimeMXBean().getName(); VirtualMachine vm = VirtualMachine.attach(name.substring(0, name.indexOf('@'))); String remoteConnectorPort = vm.getSystemProperties().getProperty("com.sun.management.jmxremote.port"); if (remoteConnectorPort != null) { final String remoteConnectorAddress = "service:jmx:rmi: LOGGER.info("JMX Available at " + remoteConnectorAddress); return new Integer(remoteConnectorPort); } int localPort = port; if (localPort == -1) { ServerSocket s = new ServerSocket(0); localPort = s.getLocalPort(); s.close(); } final String home = vm.getSystemProperties().getProperty("java.home"); final String agent = home + File.separator + "lib" + File.separator + "management-agent.jar"; vm.loadAgent(agent, "com.sun.management.jmxremote.port=" + localPort + "," + "com.sun.management.jmxremote.authenticate=false,com.sun.management.jmxremote.ssl=false"); final String remoteConnectorAddress = "service:jmx:rmi: LOGGER.info("JMX Available at " + remoteConnectorAddress); vm.detach(); return localPort; } JamService(String jamServerBaseUrl); HttpClient getClient(); void setClient(HttpClient client); String getJamServerBaseUrl(); void setJamServerBaseUrl(String jamServerBaseUrl); void addServerToServiceQueue(final String queueName, final String brokerUrl,
                                        final String host, final int port); void disableServiceQueue(final String queueName); boolean doesServiceQueueExist(final String queueName, final String brokerUrl); void enableServiceQueue(final String queueName); void registerServiceQueue(final String queueName, final String brokerUrl,
                                     final int queryIntervalInSeconds, final boolean resetStatisticsAfterQuery,
                                     final boolean profileEnabled); void removeServerFromServiceQueue(final String queueName, final String brokerUrl,
                                             final String host, final int port); void removeServiceQueue(final String queueName); void runGather(final String queueName, final String brokerUrl); int loadJMXAgent(int port); static final Logger LOGGER; }