Check out ZKClient:

The way this client deals with sessions is pretty nice and clean and I ended up 
using a lot of this code as the basis for my Java client.


-----Original Message-----
From: Gustavo Niemeyer [] 
Sent: Thursday, November 18, 2010 1:26 PM
Subject: Session events

Hello again,

Even though we've been using ZooKeeper for some time, just now we're
stopping and thinking through to see how to best deal with session
events in the context of a whole application.

To ensure I'm not off track, my understanding of session and session
event handling is:

1) It is an error to attempt to use a zk connection before a session
is established.

2) Session events can *only* be observed by setting a watch
explicitly, so one has to do something similar to wexists("/",
observe_change_func) in their preferred client API to set a hook which
will purposefully wait on a session change.

3) *All* the existing watches receive session events.

4) Reconnections within the grace period will not cause a session event.

First, are these statements correct?

Then, how are people generally architecting reliable applications when
facing these facts?  Are you simply checking for type == SESSION_EVENT
on *all* the watching functions?  Are you using a single watching
function and perhaps redirecting the flow to a different location
after freeing the used resources?  Are you ignoring the issue entirely
and hoping for the best? :-)

Any insights into existing practices will be welcome.

Gustavo Niemeyer

Reply via email to