Class: ZooKeeper::EventMachine::ClientConn
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- ZooKeeper::EventMachine::ClientConn
show all
- Includes:
- Slf4r::Logger, Protocol
- Defined in:
- lib/zkruby/eventmachine.rb
Constant Summary
Constants included
from Protocol
Protocol::MIN_PACKET
Instance Method Summary
collapse
Methods included from Protocol
#receive_data, #send_records
Constructor Details
#initialize(session, connect_timeout) ⇒ ClientConn
Returns a new instance of ClientConn.
22
23
24
25
26
27
28
|
# File 'lib/zkruby/eventmachine.rb', line 22
def initialize(session,connect_timeout)
@session = session
@connect_timeout = connect_timeout
set_pending_connect_timeout(connect_timeout)
rescue Exception => ex
logger.warn("Exception in initialize",ex)
end
|
Instance Method Details
#connection_completed ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/zkruby/eventmachine.rb', line 35
def connection_completed()
@session.prime_connection(self)
@timer = EM.add_timer(@connect_timeout) do
if @session.connected?
ping = @session.ping_interval
@timer = EM.add_periodic_timer ( ping ) do
case @ping
when 1 then @session.ping()
when 2 then close_connection()
end
@ping += 1
end
else
close_connection()
end
end
rescue Exception => ex
logger.warn("Exception in connection_completed",ex)
end
|
#disconnect ⇒ Object
65
66
67
|
# File 'lib/zkruby/eventmachine.rb', line 65
def disconnect()
close_connection()
end
|
#post_init ⇒ Object
30
31
32
33
|
# File 'lib/zkruby/eventmachine.rb', line 30
def post_init()
rescue Exception => ex
logger.warn("Exception in post_init",ex)
end
|
#receive_records(packet_io) ⇒ Object
60
61
62
63
|
# File 'lib/zkruby/eventmachine.rb', line 60
def receive_records(packet_io)
@ping = 0
@session.receive_records(packet_io)
end
|
#set_pending_connect_timeout(timeout) ⇒ Object
17
18
19
|
# File 'lib/zkruby/eventmachine.rb', line 17
def set_pending_connect_timeout(timeout)
end
|
#unbind ⇒ Object
69
70
71
72
73
74
|
# File 'lib/zkruby/eventmachine.rb', line 69
def unbind
EM.cancel_timer(@timer) if @timer
@session.disconnected()
rescue Exception => ex
logger.warn("Exception in unbind",ex)
end
|