From user-return-11795-archive-asf-public=cust-asf.ponee.io@zookeeper.apache.org Wed Jan 2 10:42:42 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id A1BCA180662 for ; Wed, 2 Jan 2019 10:42:41 +0100 (CET) Received: (qmail 19869 invoked by uid 500); 2 Jan 2019 09:42:40 -0000 Mailing-List: contact user-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@zookeeper.apache.org Delivered-To: mailing list user@zookeeper.apache.org Received: (qmail 19858 invoked by uid 99); 2 Jan 2019 09:42:39 -0000 Received: from mail-relay.apache.org (HELO mailrelay2-lw-us.apache.org) (207.244.88.137) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Jan 2019 09:42:39 +0000 Received: from [172.30.65.74] (unknown [185.63.45.212]) by mailrelay2-lw-us.apache.org (ASF Mail Server at mailrelay2-lw-us.apache.org) with ESMTPSA id 12A87218D for ; Wed, 2 Jan 2019 09:42:38 +0000 (UTC) From: Andor Molnar Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: Re: zookeeper watcher infinite calling process() since zookkeeper is down. Date: Wed, 2 Jan 2019 10:42:26 +0100 References: To: user@zookeeper.apache.org In-Reply-To: Message-Id: <7EFF989E-F26B-43F8-9AA6-E76C6933AAC5@apache.org> X-Mailer: Apple Mail (2.3445.102.3) Hi Devendra, You need to explicitly call the close() method of ZooKeeper client = object to stop it trying to connect and properly shut down before = creating a new client. Regards, Andor > On 2018. Dec 20., at 17:19, Devendra Jain wrote: >=20 > Hi, >=20 > I am facing one issue in my project when I am creating zookepper = client and > if its not created due to zookepper server url is down. It's keep on = trying > to connect and further sending the "Watcher" object mentioning the = state is > "disconnected". I am not sure how to kill this endless callback if I = want > to pass new zookeeper URL with is up. > Here is the code which I have written. >=20 > Class ZookeeperConnection { >=20 > final String zkConnectionStr; >=20 > public void ZookeeperConnection(String zkConnectionStr ){ > Zookeeper zkConnectionStr =3DzkConnectionStr; > } >=20 > private ZooKeeper newZkConnection() { > CountDownLatch zkConnectionLatch =3D new CountDownLatch(1); > try { >=20 > ZooKeeper zkClient =3D new ZooKeeper(zkConnectionStr, = 40000, new > Watcher() { > int i =3D 0; > @Override > public void process(WatchedEvent watchedEvent) { > // > String zkSessionID =3D getZkSessionID(); > // > switch (watchedEvent.getState()) { > case ConnectedReadOnly: > break; > case SyncConnected: > // Wait for connection to ZooKeeper > zkConnectionLatch.countDown(); > break; > case Disconnected: > break; > case Expired: > restartZkServices(); //calling the same new > connection method again > break; > case AuthFailed: >=20 > break; > } > } > }); > // > long zkConnectionTimeout =3D 30; > zkConnectionLatch.await(zkConnectionTimeout, = TimeUnit.SECONDS); > // Wait 30 seconds > // > if (zkClient.getState().isConnected()) { > return zkClient; > } > // > } catch (Exception ex) { > LOG.error("An exception happened during connecting to = ZooKeeper > [{}].", zkConnectionStr, ex); > } > // > return null; > } > In this code I tried to create object of ZookeeperConnection class by > passing the zookeeper server URL and latter if user want to change the > zookepper server URL we again create a new method of = ZookeeperConnection > class so if Zookeeeper is up I am able to connect through new object. = But > old object which uses old zookepper url is still active and gets = callback > and continuously show disconnected. >=20 > Please help me on this. > Thanks. > Devendra Jain