Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add client_id support

  • Loading branch information...
commit 75473fdc10b4c573e6c4610668d68df5dff5d51d 1 parent 0df608e
David LaBissoniere labisso authored

Showing 2 changed files with 18 additions and 2 deletions. Show diff stats Hide diff stats

  1. +4 0 kazoo/client.py
  2. +14 2 kazoo/zkclient.py
4 kazoo/client.py
@@ -94,6 +94,10 @@ def remove_listener(self, listener):
94 94 """
95 95 self.state_listeners.discard(listener)
96 96
  97 + @property
  98 + def client_id(self):
  99 + return self.zk.client_id
  100 +
97 101 def connect(self, timeout=None):
98 102 """Initiate connection to ZK
99 103
16 kazoo/zkclient.py
@@ -53,9 +53,10 @@ class ZooKeeperClient(object):
53 53
54 54 DEFAULT_TIMEOUT = 10000
55 55
56   - def __init__(self, hosts, watcher=None, timeout=10000):
  56 + def __init__(self, hosts, watcher=None, timeout=10000, client_id=None):
57 57 self._hosts = hosts
58 58 self._watcher = watcher
  59 + self._provided_client_id = client_id
59 60 if timeout is None:
60 61 timeout = self.DEFAULT_TIMEOUT
61 62 self._timeout = timeout
@@ -71,6 +72,12 @@ def __init__(self, hosts, watcher=None, timeout=10000):
71 72 def connected(self):
72 73 return self._connected
73 74
  75 + @property
  76 + def client_id(self):
  77 + if self._handle is not None:
  78 + return zookeeper.client_id(self._handle)
  79 + return None
  80 +
74 81 def get_sync_strategy(self):
75 82 return self._sync
76 83
@@ -114,7 +121,12 @@ def connect_async(self):
114 121 """
115 122
116 123 cb = self._wrap_session_callback(self._session_callback)
117   - self._handle = zookeeper.init(self._hosts, cb, self._timeout)
  124 + if self._provided_client_id:
  125 + self._handle = zookeeper.init(self._hosts, cb, self._timeout,
  126 + self._provided_client_id)
  127 + else:
  128 + self._handle = zookeeper.init(self._hosts, cb, self._timeout)
  129 +
118 130 return self._connected_async_result
119 131
120 132 def connect(self, timeout=None):

0 comments on commit 75473fd

Please sign in to comment.
Something went wrong with that request. Please try again.