summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichiel Johan Baird <michiel@asana.com>2016-04-20 17:07:44 -0700
committerMichiel Johan Baird <michiel@asana.com>2016-04-20 17:07:44 -0700
commit92b4dba7bfff675a65ae63ab3706d91eb93cf806 (patch)
tree12d864a22aa45725c37007a9e3121da25dbde669
parentf055dc08d1c24e0c95610852ce99ad38e0ab2688 (diff)
downloadkazoo-92b4dba7bfff675a65ae63ab3706d91eb93cf806.tar.gz
Ensure watches are notified when connection state is lost
- This behaviour matches the reference implementation in Zookeeper - New EventType added: NONE - Path defaults to None as in reference implementation
-rw-r--r--kazoo/client.py14
-rw-r--r--kazoo/protocol/states.py6
2 files changed, 20 insertions, 0 deletions
diff --git a/kazoo/client.py b/kazoo/client.py
index 27fbe00..c052d55 100644
--- a/kazoo/client.py
+++ b/kazoo/client.py
@@ -44,8 +44,11 @@ from kazoo.protocol.serialization import (
Sync,
Transaction
)
+from kazoo.protocol.states import Callback
+from kazoo.protocol.states import EventType
from kazoo.protocol.states import KazooState
from kazoo.protocol.states import KeeperState
+from kazoo.protocol.states import WatchedEvent
from kazoo.retry import KazooRetry
from kazoo.security import ACL
from kazoo.security import OPEN_ACL_UNSAFE
@@ -305,9 +308,20 @@ class KazooClient(object):
self._protocol_version = None
def _reset_watchers(self):
+ watchers = []
+ for child_watchers in six.itervalues(self._child_watchers):
+ watchers.extend(child_watchers)
+
+ for data_watchers in six.itervalues(self._data_watchers):
+ watchers.extend(data_watchers)
+
self._child_watchers = defaultdict(set)
self._data_watchers = defaultdict(set)
+ ev = WatchedEvent(EventType.NONE, self._state, None)
+ for watch in watchers:
+ self.handler.dispatch_callback(Callback("watch", watch, (ev,)))
+
def _reset_session(self):
self._session_id = None
self._session_passwd = b'\x00' * 16
diff --git a/kazoo/protocol/states.py b/kazoo/protocol/states.py
index 395c013..7eb09d7 100644
--- a/kazoo/protocol/states.py
+++ b/kazoo/protocol/states.py
@@ -93,13 +93,19 @@ class EventType(object):
removed). This event does not indicate the data for a child
node has changed, which must have its own watch established.
+ .. attribute:: NONE
+
+ The connection state has been altered.
+
"""
CREATED = 'CREATED'
DELETED = 'DELETED'
CHANGED = 'CHANGED'
CHILD = 'CHILD'
+ NONE = 'NONE'
EVENT_TYPE_MAP = {
+ -1:EventType.NONE,
1: EventType.CREATED,
2: EventType.DELETED,
3: EventType.CHANGED,