This way:

class Notifiery
{
public synchronized void Notify()
{
   mNotified = true;
   notify();
}
public synchronized bool Wait(long timeout)
{
   if (mNotified) return true;
   wait(timeout);
   return mNotified;
}
bool mNotified;
}

Notifier n = new Notifier;
zk = new Zookeeper(.....); /// pass "n" to the init watch
bool connected = n.Wait(your_tolerant_timeout);
if (!connected)
{
  zk.close();
  throw something;
}
Inside the init watch, n.Notify() after you see a CONNECTED event.
2011/5/14 Jeremy Sevellec <[email protected]>

> Hi Everyone,
>
> I'm new to Zookeeper and I'm trying to use it to make some distributed
> lock. Globally, It works perfect!
>
> I've got a question about zookeeper client connection to a dead
> zookeeper server .
>
> When I'm doing this connec to to a dead zookeeper server like this (the
> code works fine when the server is up) :
> zooKeeper = new ZooKeeper(....).
>
> The zookeeper client failed to connect but loop infinitely to try to
> connect again and again. Is there any solution to know [catch] that it's
> impossible to connect to a zookeeper server to be abble to make
> something?
>
> Regards,
>
> Jérémy
>

Reply via email to