Java Code Examples for javax.management.remote.JMXConnector

Following code examples demonstrate how to use javax.management.remote.JMXConnectorfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use javax.management.remote.JMXConnectorand various code implementation of this class.

    public static void main(String[] args) {
        try {
            HashMap<String, Object> prop = new HashMap<String, Object>();
            prop.put(JMXConnector.CREDENTIALS, "hello");
            final JMXConnector conn = JMXConnectorFactory.connect(new JMXServiceURL(
                                                                  prop);

            HelloMBean hello = JMX.newMBeanProxy(conn.getMBeanServerConnection(), new ObjectName("hello:name=hello"),
                                                 HelloMBean.class);
            hello.setName("bearice");
            hello.printHello();
            hello.printHello("AAAAAA");
            conn.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    } 


	public static void main(String[] args) {
		try {
			log("Local JMXServiceURL Test");
			log("URL:[" + jurl.getURLPath() + "]");
			JMXConnector connector = JMXConnectorFactory.connect(jurl, Collections.singletonMap("jmx.remote.protocol.provider.class.loader", LocalJMXConnector.class.getClassLoader()));
			log("Connected to [" + connector.getMBeanServerConnection().getDefaultDomain() + "]");
		} catch (Exception ex) {
			ex.printStackTrace(System.err);
		}		
	} 

	public void updateConnector(final JMXConnector connector) {
		final JMXConnector prior = this.connector.getAndSet(connector);
		try { prior.close(); } catch (Exception x) {}
		for(Notif n: notifs) {
			connector.addConnectionNotificationListener(n.listener, n.filter, n.handback);
		}
	} 

	public static JMXConnector addressable(final JMXConnector jmxConnector, final JMXServiceURL jmxServiceURL) {
		if(jmxConnector==null) throw new IllegalArgumentException("The passed JMXConnector was null");
		if(jmxConnector instanceof JMXAddressable) return jmxConnector;
		if(jmxServiceURL==null) throw new IllegalArgumentException("The passed JMXConnector does not implement JMXAddressable, but the passed JMXServiceURL was null");
		return new WrappedJMXConnector(jmxConnector, jmxServiceURL);
	} 

	public static void main(String args[]) {
		final String objectNameStr = "dustin:type=status,name=remoteJMX";    
		 try    
		   {    
			    LocateRegistry.createRegistry(9999);
		        final ObjectName objectName = new ObjectName(objectNameStr);    
		        final JMXServiceURL jmxUrl = new JMXServiceURL(jmxRmiStr);    
		        final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl);    
		        final MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();  
		        System.out.println("b");
		   } catch (Exception e) {
			   e.printStackTrace();
		   }
	} 

Advertisement
Javadoc


The client end of a JMX API connector. An object of this type can be used to establish a c

onnection to a connector server.

A newly-created object of this type is unconnected. Its #connect connect method must be called before it can be used. However, objects created by JMXConnectorFactory#connect(JMXServiceURL, Map) JMXConnectorFactory.connect are already connected. @since 1.5

Read More
Advertisement