zk-eventmachine 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
@@ -6,8 +6,6 @@ module ZK
|
|
6
6
|
|
7
7
|
DEFAULT_TIMEOUT = 10
|
8
8
|
|
9
|
-
attr_reader :client
|
10
|
-
|
11
9
|
# Takes same options as ZK::Client::Base
|
12
10
|
def initialize(host, opts={})
|
13
11
|
@host = host
|
@@ -26,7 +24,10 @@ module ZK
|
|
26
24
|
# ready for use
|
27
25
|
def connect(&blk)
|
28
26
|
# XXX: maybe move this into initialize, need to figure out how to schedule it properly
|
29
|
-
@cnx ||=
|
27
|
+
@cnx ||= (
|
28
|
+
event_handler.register_state_handler(Zookeeper::ZOO_EXPIRED_SESSION_STATE, &method(:handle_expired_session_state_event!))
|
29
|
+
ZookeeperEM::Client.new(@host, DEFAULT_TIMEOUT, event_handler.get_default_watcher_block)
|
30
|
+
)
|
30
31
|
@cnx.on_attached(&blk)
|
31
32
|
end
|
32
33
|
|
@@ -137,6 +138,12 @@ module ZK
|
|
137
138
|
end
|
138
139
|
|
139
140
|
protected
|
141
|
+
def handle_expired_session_state_event!(event)
|
142
|
+
exc = ZK::Exceptions::ConnectionLoss.new("Received EXPIRED_SESSION_STATE event: #{event.inspect}")
|
143
|
+
exc.set_backtrace(caller)
|
144
|
+
connection_lost_hook(exc)
|
145
|
+
end
|
146
|
+
|
140
147
|
def connection_lost_hook(exc)
|
141
148
|
if exc and exc.kind_of?(ZK::Exceptions::ConnectionLoss)
|
142
149
|
dfr, @connection_lost_deferred = @connection_lost_deferred, Deferred::Default.new
|
@@ -81,6 +81,27 @@ module ZK::ZKEventMachine
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
+
|
85
|
+
it %[should be called if we get a session expired event] do
|
86
|
+
@zkem.on_connection_lost do |exc|
|
87
|
+
logger.debug { "WIN!" }
|
88
|
+
exc.should be_kind_of(ZK::Exceptions::ConnectionLoss)
|
89
|
+
@zkem.close! { done }
|
90
|
+
end
|
91
|
+
|
92
|
+
em do
|
93
|
+
@zkem.connect do
|
94
|
+
event = flexmock(:event).tap do |ev|
|
95
|
+
ev.should_receive(:node_event?).and_return(false)
|
96
|
+
ev.should_receive(:state_event?).and_return(true)
|
97
|
+
ev.should_receive(:zk=).with_any_args
|
98
|
+
ev.should_receive(:state).and_return(Zookeeper::ZOO_EXPIRED_SESSION_STATE)
|
99
|
+
end
|
100
|
+
|
101
|
+
EM.next_tick { @zkem.event_handler.process(event) }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
84
105
|
end
|
85
106
|
|
86
107
|
describe 'get' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zk-eventmachine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 9
|
10
|
+
version: 0.1.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonathan D. Simms
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-01-25 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: zk
|
@@ -213,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
213
|
requirements: []
|
214
214
|
|
215
215
|
rubyforge_project:
|
216
|
-
rubygems_version: 1.8.
|
216
|
+
rubygems_version: 1.8.10
|
217
217
|
signing_key:
|
218
218
|
specification_version: 3
|
219
219
|
summary: ZK client for EventMachine-based (async) applications
|