private void connect ( ZooKeeperClient injectedClient ) throws InterruptedException { if ( ! initialized . get ( ) ) { if ( injectedClient == null ) { List < InetSocketAddress > hosts = new ArrayList < InetSocketAddress > ( ) ; for ( String host : config . hosts . split ( "," ) ) { String [ ] parts = host . split ( ":" ) ; try { hosts . add ( new InetSocketAddress ( parts [ 0 ] , Integer . parseInt ( parts [ 1 ] ) ) ) ; } catch ( Exception e ) { LOG . error ( "Invalid ZK host '" + host + "', need to skip, problem: " + e . getMessage ( ) ) ; } } // TODO: What about empty hosts at this point? LOG . info ( "Connecting to hosts: {}" , hosts . toString ( ) ) ; injectedClient = new ZooKeeperClient ( Amount . of ( ( int ) config . zkTimeout , Time . MILLISECONDS ) , hosts ) ; } zk = injectedClient ; claimer . start ( ) ; LOG . info ( "Registering connection watcher." ) ; zk . register ( connectionWatcher ) ; } // and then see that we can actually get the client without problems try { zk . get ( ) ; } catch ( ZooKeeperConnectionException e ) { throw ZKException . from ( e ) ; } }
Directs the ZooKeeperClient to connect to the ZooKeeper ensemble and wait for the connection to be established before continuing .