public static void main(String[] args) {
		try{
			//Create an RMI connector client and
			//connect it to the RMI connector server
			echo("Create an RMI connector client and " +
			" connect it to the RMI connector server");
			JMXServiceURL url = new JMXServiceURL(
					"service:jmx:rmi:///jndi/rmi://localhost:9999/server");
			JMXConnector jmxc = JMXConnectorFactory.connect(url,null);
			
			//Create listener
			ClientListener listener = new ClientListener();
			
			//Get an MBeanServerConnection
			echo("Get an MBeanServerConnection");
			MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
			waitForEnterPressed();
			
			//Get domains from MBeanServer
			echo("Domains:");
			String domains[] = mbsc.getDomains();
			for(int i = 0; i < domains.length; i++){
				echo("domain[" + i + "] = " + domains[i]);
			}
			waitForEnterPressed();
			
			//Get MBeanServer's default domain
			String domain = mbsc.getDefaultDomain();
			
			//Create SimpleStandard MBean
			ObjectName stdMBeanName = 
					new ObjectName(domain + ":type=SimpleStandard,name=2");
			echo("Create SimpleStandard MBean ...");
			mbsc.createMBean("SimpleStandard", stdMBeanName,null,null);
			waitForEnterPressed();
			
			 // Create SimpleDynamic MBean
            ObjectName dynMBeanName =
            		new ObjectName(domain +":type=SimpleDynamic,name=2");
            echo("\nCreate SimpleDynamic MBean...");
            mbsc.createMBean("SimpleDynamic", dynMBeanName, null, null);
            waitForEnterPressed();
			//Get MBean count
			echo("Mbean count = " + mbsc.getMBeanCount());
			
			//Query MBean names
			echo("Query MBeanServer MBeans:");
			Set names = mbsc.queryNames(null, null);
			for(Iterator i = names.iterator();i.hasNext();){
				echo("ObjectName = " + (ObjectName) i.next());
			}
			waitForEnterPressed();
			
			//Manage SimpleStandard MBean
			echo("\n>>>Perform operations on SimpleStandard MBean<<<");
			echo("State = " + mbsc.getAttribute(stdMBeanName, "State"));
			mbsc.setAttribute(stdMBeanName, new Attribute("State","changed state"));
			
			//Another way of interacting with a given MBean is through a
			//dedicated proxy instead of going directly through the MBean
			//server connection
			SimpleStandardMBean proxy = JMX.newMBeanProxy(mbsc, stdMBeanName,
										SimpleStandardMBean.class,true);
			echo("state = " + proxy.getState());
			
			//Add notification listener on SimpleStandard MBean
			mbsc.addNotificationListener(stdMBeanName, listener, null, null);
			
			//Invoke reset and receive notification
			echo("Invoke reset() in SimpleStandard MBean ...");
			mbsc.invoke(stdMBeanName, "reset", null, null);
			
			//Sleep for 2 seoonds in order to have time receive the
			//notification before removing the notification listener.
			sleep(2000);
			
			//Remove notification listener
			echo("Remove notification listener...");
			mbsc.removeNotificationListener(stdMBeanName, listener);
			
			//Unregister SimpleStandard MBean
			echo("Unregister SimpleStand MBean...");
			mbsc.unregisterMBean(stdMBeanName);
			waitForEnterPressed();
			
		    //Manage the SimpleDynamic MBean
	        echo("\n>>> Perform operations on SimpleDynamic MBean <<<");

	        // Get State attribute in SimpleDynamic MBean
	        
	        echo("\nState = " + mbsc.getAttribute(dynMBeanName, "State"));

	        // Set State attribute in SimpleDynamic MBean
	        mbsc.setAttribute(dynMBeanName,
	                              new Attribute("State", "changed state"));

	        // Get State attribute in SimpleDynamic MBean
	        echo("\nState = " + mbsc.getAttribute(dynMBeanName, "State"));

	        // Add notification listener on SimpleDynamic MBean
	        echo("\nAdd notification listener...");
	        mbsc.addNotificationListener(dynMBeanName, listener, null, null);

	        // Invoke "reset" in SimpleDynamic MBean
	        //
	        // Calling "reset" makes the SimpleDynamic MBean emit a
	        // notification that will be received by the registered
	        // ClientListener.
	        //        
	        echo("\nInvoke reset() in SimpleDynamic MBean...");
	        mbsc.invoke(dynMBeanName, "reset", null, null);

	        // Sleep for 2 seconds in order to have time to receive the
	        // notification before removing the notification listener.
	        //
	        echo("\nWaiting for notification...");
	        sleep(2000);

	        // Remove notification listener on SimpleDynamic MBean
	        //
	        echo("\nRemove notification listener...");
	        mbsc.removeNotificationListener(dynMBeanName, listener);

	        // Unregister SimpleDynamic MBean
	        //
	        echo("\nUnregister SimpleDynamic MBean...");
	        mbsc.unregisterMBean(dynMBeanName);
		    waitForEnterPressed();

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

	}