Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Add client_id support
Browse files Browse the repository at this point in the history
  • Loading branch information
labisso committed Mar 2, 2012
1 parent 0df608e commit 75473fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions kazoo/client.py
Expand Up @@ -94,6 +94,10 @@ def remove_listener(self, listener):
"""
self.state_listeners.discard(listener)

@property
def client_id(self):
return self.zk.client_id

def connect(self, timeout=None):
"""Initiate connection to ZK
Expand Down
16 changes: 14 additions & 2 deletions kazoo/zkclient.py
Expand Up @@ -53,9 +53,10 @@ class ZooKeeperClient(object):

DEFAULT_TIMEOUT = 10000

def __init__(self, hosts, watcher=None, timeout=10000):
def __init__(self, hosts, watcher=None, timeout=10000, client_id=None):
self._hosts = hosts
self._watcher = watcher
self._provided_client_id = client_id
if timeout is None:
timeout = self.DEFAULT_TIMEOUT
self._timeout = timeout
Expand All @@ -71,6 +72,12 @@ def __init__(self, hosts, watcher=None, timeout=10000):
def connected(self):
return self._connected

@property
def client_id(self):
if self._handle is not None:
return zookeeper.client_id(self._handle)
return None

def get_sync_strategy(self):
return self._sync

Expand Down Expand Up @@ -114,7 +121,12 @@ def connect_async(self):
"""

cb = self._wrap_session_callback(self._session_callback)
self._handle = zookeeper.init(self._hosts, cb, self._timeout)
if self._provided_client_id:
self._handle = zookeeper.init(self._hosts, cb, self._timeout,
self._provided_client_id)
else:
self._handle = zookeeper.init(self._hosts, cb, self._timeout)

return self._connected_async_result

def connect(self, timeout=None):
Expand Down

0 comments on commit 75473fd

Please sign in to comment.