protected final class HBaseClient.ZKClient extends Object implements org.apache.zookeeper.Watcher
We don't watch the file of the -ROOT- region. We just asynchronously
read it once to find -ROOT-, then we close our ZooKeeper session.
There are a few reasons for this. First of all, the -ROOT- region
doesn't move often. When it does, and when we need to use it, we'll
realize that -ROOT- is no longer where we though it was and we'll find
it again. Secondly, maintaining a session open just to watch the
-ROOT- region is a waste of resources both on our side and on ZK's side.
ZK is chatty, it will frequently send us heart beats that will keep
waking its event thread, etc. Third, if the application we're part of
already needs to maintain a session with ZooKeeper anyway, we can't
easily share it with them anyway, because of ZooKeeper's API. Indeed,
unfortunately the ZooKeeper API requires that the ZooKeeper
object be re-created when the session is invalidated (due to a
disconnection or a timeout), which means that it's impossible to
share the ZooKeeper
object. Ideally in an application there
should be only one instance, but their poor API makes it impractical,
since the instance must be re-created when the session is invalidated,
which entails that one entity should own the reconnection process and
have a way of giving everyone else the new instance. This is extremely
cumbersome so I don't expect anyone to do this, which is why we manage
our own instance.
Constructor and Description |
---|
ZKClient(String quorum_spec,
String base_path)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
disconnectZK()
Disconnects from ZooKeeper.
|
com.stumbleupon.async.Deferred<Object> |
getDeferredRoot()
Returns a deferred that will be called back once we found -ROOT-.
|
void |
process(org.apache.zookeeper.WatchedEvent event)
Processes a ZooKeeper event.
|
public com.stumbleupon.async.Deferred<Object> getDeferredRoot()
public void process(org.apache.zookeeper.WatchedEvent event)
This method is called back by ZooKeeper
from its main event
thread. So make sure you don't block.
process
in interface org.apache.zookeeper.Watcher
event
- The event to process.public void disconnectZK()
This method is blocking. Unfortunately, ZooKeeper
doesn't offer an asynchronous API to close a session at this time.
It waits until the server responds to the closeSession
RPC.
Copyright © 2010-2017, The Async HBase Authors