private void connect() throws IOException {
  JMXServiceURL jmxUrl=new JMXServiceURL(String.format(fmtUrl,host,port));
  Map<String,Object> env=new HashMap<String,Object>();
  if (username != null) {
    String[] creds={username,password};
    env.put(JMXConnector.CREDENTIALS,creds);
  }
  env.put("com.sun.jndi.rmi.factory.socket",getRMIClientSocketFactory());
  jmxc=JMXConnectorFactory.connect(jmxUrl,env);
  mbeanServerConn=jmxc.getMBeanServerConnection();
  try {
    ObjectName name=new ObjectName(ssObjName);
    ssProxy=JMX.newMBeanProxy(mbeanServerConn,name,StorageServiceMBean.class);
    name=new ObjectName(MessagingService.MBEAN_NAME);
    msProxy=JMX.newMBeanProxy(mbeanServerConn,name,MessagingServiceMBean.class);
    name=new ObjectName(StreamManagerMBean.OBJECT_NAME);
    streamProxy=JMX.newMBeanProxy(mbeanServerConn,name,StreamManagerMBean.class);
    name=new ObjectName(CompactionManager.MBEAN_OBJECT_NAME);
    compactionProxy=JMX.newMBeanProxy(mbeanServerConn,name,CompactionManagerMBean.class);
    name=new ObjectName(FailureDetector.MBEAN_NAME);
    fdProxy=JMX.newMBeanProxy(mbeanServerConn,name,FailureDetectorMBean.class);
    name=new ObjectName(CacheService.MBEAN_NAME);
    cacheService=JMX.newMBeanProxy(mbeanServerConn,name,CacheServiceMBean.class);
    name=new ObjectName(StorageProxy.MBEAN_NAME);
    spProxy=JMX.newMBeanProxy(mbeanServerConn,name,StorageProxyMBean.class);
    name=new ObjectName(HintedHandOffManager.MBEAN_NAME);
    hhProxy=JMX.newMBeanProxy(mbeanServerConn,name,HintedHandOffManagerMBean.class);
    name=new ObjectName(GCInspector.MBEAN_NAME);
    gcProxy=JMX.newMBeanProxy(mbeanServerConn,name,GCInspectorMXBean.class);
    name=new ObjectName(Gossiper.MBEAN_NAME);
    gossProxy=JMX.newMBeanProxy(mbeanServerConn,name,GossiperMBean.class);
  }
 catch (  MalformedObjectNameException e) {
    throw new RuntimeException("Invalid ObjectName? Please report this as a bug.",e);
  }
  memProxy=ManagementFactory.newPlatformMXBeanProxy(mbeanServerConn,ManagementFactory.MEMORY_MXBEAN_NAME,MemoryMXBean.class);
  runtimeProxy=ManagementFactory.newPlatformMXBeanProxy(mbeanServerConn,ManagementFactory.RUNTIME_MXBEAN_NAME,RuntimeMXBean.class);
}

private void connect ( ) throws IOException { JMXServiceURL jmxUrl = new JMXServiceURL ( String . format ( fmtUrl , host , port ) ) ; Map < String , Object > env = new HashMap < String , Object > ( ) ; if ( username != null ) { String [ ] creds = { username , password } ; env . put ( JMXConnector . CREDENTIALS , creds ) ; } env . put ( "com.sun.jndi.rmi.factory.socket" , getRMIClientSocketFactory ( ) ) ; jmxc = JMXConnectorFactory . connect ( jmxUrl , env ) ; mbeanServerConn = jmxc . getMBeanServerConnection ( ) ; try { ObjectName name = new ObjectName ( ssObjName ) ; ssProxy = JMX . newMBeanProxy ( mbeanServerConn , name , StorageServiceMBean . class ) ; name = new ObjectName ( MessagingService . MBEAN_NAME ) ; msProxy = JMX . newMBeanProxy ( mbeanServerConn , name , MessagingServiceMBean . class ) ; name = new ObjectName ( StreamManagerMBean . OBJECT_NAME ) ; streamProxy = JMX . newMBeanProxy ( mbeanServerConn , name , StreamManagerMBean . class ) ; name = new ObjectName ( CompactionManager . MBEAN_OBJECT_NAME ) ; compactionProxy = JMX . newMBeanProxy ( mbeanServerConn , name , CompactionManagerMBean . class ) ; name = new ObjectName ( FailureDetector . MBEAN_NAME ) ; fdProxy = JMX . newMBeanProxy ( mbeanServerConn , name , FailureDetectorMBean . class ) ; name = new ObjectName ( CacheService . MBEAN_NAME ) ; cacheService = JMX . newMBeanProxy ( mbeanServerConn , name , CacheServiceMBean . class ) ; name = new ObjectName ( StorageProxy . MBEAN_NAME ) ; spProxy = JMX . newMBeanProxy ( mbeanServerConn , name , StorageProxyMBean . class ) ; name = new ObjectName ( HintedHandOffManager . MBEAN_NAME ) ; hhProxy = JMX . newMBeanProxy ( mbeanServerConn , name , HintedHandOffManagerMBean . class ) ; name = new ObjectName ( GCInspector . MBEAN_NAME ) ; gcProxy = JMX . newMBeanProxy ( mbeanServerConn , name , GCInspectorMXBean . class ) ; name = new ObjectName ( Gossiper . MBEAN_NAME ) ; gossProxy = JMX . newMBeanProxy ( mbeanServerConn , name , GossiperMBean . class ) ; } catch ( MalformedObjectNameException e ) { throw new RuntimeException ( "Invalid ObjectName? Please report this as a bug." , e ) ; } memProxy = ManagementFactory . newPlatformMXBeanProxy ( mbeanServerConn , ManagementFactory . MEMORY_MXBEAN_NAME , MemoryMXBean . class ) ; runtimeProxy = ManagementFactory . newPlatformMXBeanProxy ( mbeanServerConn , ManagementFactory . RUNTIME_MXBEAN_NAME , RuntimeMXBean . class ) ; }
create a connection to the jmx agent and setup the m [ x ] bean proxies .
