public static RecoverableZooKeeper connect(Configuration conf, String ensemble, Watcher watcher) throws IOException { return connect(conf, ensemble, watcher, ""); }
/** * Creates a new connection to ZooKeeper, pulling settings and ensemble config * from the specified configuration object using methods from {@link org.apache.hadoop.hbase.zookeeper.ZKConfig} * . * * Sets the connection status monitoring watcher to the specified watcher. * * @param conf * configuration to pull ensemble and other settings from * @param watcher * watcher to monitor connection changes * @return connection to zookeeper * @throws java.io.IOException * if unable to connect to zk or config problem */ public static RecoverableZooKeeper connect(Configuration conf, Watcher watcher) throws IOException { Properties properties = ZKConfig.makeZKProps(conf); String ensemble = ZKConfig.getZKQuorumServersString(properties); return connect(conf, ensemble, watcher); }
/** * Instantiate a ZooKeeper connection and watcher. * @param descriptor Descriptive string that is added to zookeeper sessionid * and used as identifier for this instance. * @throws java.io.IOException * @throws com.alibaba.wasp.ZooKeeperConnectionException */ public ZooKeeperWatcher(Configuration conf, String descriptor, Abortable abortable, boolean canCreateBaseZNode) throws IOException, ZooKeeperConnectionException { this.conf = conf; // Capture a stack trace now. Will print it out later if problem so we can // distingush amongst the myriad ZKWs. try { throw new Exception("ZKW CONSTRUCTOR STACK TRACE FOR DEBUGGING"); } catch (Exception e) { this.constructorCaller = e; } this.quorum = ZKConfig.getZKQuorumServersString(conf); // Identifier will get the session id appended later below down when we // handle the sync connect event. this.identifier = descriptor; this.abortable = abortable; setNodeNames(conf); this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, this, descriptor); if (canCreateBaseZNode) { createBaseZNodes(); } }