public boolean connect(){
  try {
    JMXServiceURL jmxUrl=new JMXServiceURL(String.format(JXM_URL_FORMAT,config.jmxHost(),config.jmxPort()));
    Map<String,Object> env=new HashMap<String,Object>();
    if (config.jmxSslEnabled()) {
      String[] creds=new String[2];
      creds[0]=config.jmxSslUsername();
      creds[1]=config.jmxSslPassword();
      env.put(JMXConnector.CREDENTIALS,creds);
    }
    env.put(DEFAULT_SOCKET_FACTORY,getRMIClientSocketFactory());
    jmxc=JMXConnectorFactory.connect(jmxUrl,env);
    mbeanServerConn=jmxc.getMBeanServerConnection();
    String queryName=String.format("%s:*",config.metricsPackageName());
    mbeans=filterMBeans(mbeanServerConn.queryMBeans(new ObjectName(queryName),null));
    return true;
  }
 catch (  IOException e) {
    logger.error("Cannot connect to jmx on {}:{}",config.jmxHost(),config.jmxPort(),e);
  }
catch (  MalformedObjectNameException e) {
    logger.error("Failed to query by object name",e);
  }
catch (  ReflectionException|IntrospectionException|InstanceNotFoundException e) {
    logger.error("Failed to get mbean attributes",e);
  }
  return false;
}

public boolean connect ( ) { try { JMXServiceURL jmxUrl = new JMXServiceURL ( String . format ( JXM_URL_FORMAT , config . jmxHost ( ) , config . jmxPort ( ) ) ) ; Map < String , Object > env = new HashMap < String , Object > ( ) ; if ( config . jmxSslEnabled ( ) ) { String [ ] creds = new String [ 2 ] ; creds [ 0 ] = config . jmxSslUsername ( ) ; creds [ 1 ] = config . jmxSslPassword ( ) ; env . put ( JMXConnector . CREDENTIALS , creds ) ; } env . put ( DEFAULT_SOCKET_FACTORY , getRMIClientSocketFactory ( ) ) ; jmxc = JMXConnectorFactory . connect ( jmxUrl , env ) ; mbeanServerConn = jmxc . getMBeanServerConnection ( ) ; String queryName = String . format ( "%s:*" , config . metricsPackageName ( ) ) ; mbeans = filterMBeans ( mbeanServerConn . queryMBeans ( new ObjectName ( queryName ) , null ) ) ; return true ; } catch ( IOException e ) { logger . error ( "Cannot connect to jmx on {}:{}" , config . jmxHost ( ) , config . jmxPort ( ) , e ) ; } catch ( MalformedObjectNameException e ) { logger . error ( "Failed to query by object name" , e ) ; } catch ( ReflectionException | IntrospectionException | InstanceNotFoundException e ) { logger . error ( "Failed to get mbean attributes" , e ) ; } return false ; }
open jmx connection and collect mbeans matching configuration defined patterns .
