Class: IRuby::SessionAdapter::TestAdapter
- Inherits:
-
BaseAdapter
- Object
- BaseAdapter
- IRuby::SessionAdapter::TestAdapter
- Includes:
- IRuby::SessionSerialize
- Defined in:
- lib/iruby/session_adapter/test_adapter.rb
Defined Under Namespace
Classes: DummySocket
Constant Summary
Constants included from IRuby::SessionSerialize
IRuby::SessionSerialize::DELIM
Instance Attribute Summary collapse
-
#closed ⇒ Object
readonly
Returns the value of attribute closed.
-
#closed_sockets ⇒ Object
readonly
Returns the value of attribute closed_sockets.
-
#heartbeat_finished ⇒ Object
readonly
Returns the value of attribute heartbeat_finished.
-
#heartbeat_started ⇒ Object
readonly
Returns the value of attribute heartbeat_started.
-
#recv_callback ⇒ Object
Returns the value of attribute recv_callback.
-
#send_callback ⇒ Object
Returns the value of attribute send_callback.
Instance Method Summary collapse
- #close ⇒ Object
- #close_socket(sock) ⇒ Object
- #heartbeat_loop(sock) ⇒ Object
-
#initialize(config) ⇒ TestAdapter
constructor
A new instance of TestAdapter.
- #recv(sock) ⇒ Object
- #send(sock, data) ⇒ Object
- #shutdown_heartbeat(sock) ⇒ Object
Methods inherited from BaseAdapter
available?, load_requirements, #make_pub_socket, #make_rep_socket, #make_router_socket, #name
Constructor Details
#initialize(config) ⇒ TestAdapter
Returns a new instance of TestAdapter.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 10 def initialize(config) super unless config['key'].empty? || config['signature_scheme'].empty? unless config['signature_scheme'] =~ /\Ahmac-/ raise "Unknown signature_scheme: #{config['signature_scheme']}" end digest_algorithm = config['signature_scheme'][/\Ahmac-(.*)\Z/, 1] @hmac = OpenSSL::HMAC.new(config['key'], OpenSSL::Digest.new(digest_algorithm)) end @send_callback = nil @recv_callback = nil @closed_sockets = [] @closed = false @heartbeat_started = false @heartbeat_finished = false end |
Instance Attribute Details
#closed ⇒ Object (readonly)
Returns the value of attribute closed.
30 31 32 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 30 def closed @closed end |
#closed_sockets ⇒ Object (readonly)
Returns the value of attribute closed_sockets.
30 31 32 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 30 def closed_sockets @closed_sockets end |
#heartbeat_finished ⇒ Object (readonly)
Returns the value of attribute heartbeat_finished.
30 31 32 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 30 def heartbeat_finished @heartbeat_finished end |
#heartbeat_started ⇒ Object (readonly)
Returns the value of attribute heartbeat_started.
30 31 32 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 30 def heartbeat_started @heartbeat_started end |
#recv_callback ⇒ Object
Returns the value of attribute recv_callback.
29 30 31 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 29 def recv_callback @recv_callback end |
#send_callback ⇒ Object
Returns the value of attribute send_callback.
29 30 31 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 29 def send_callback @send_callback end |
Instance Method Details
#close ⇒ Object
59 60 61 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 59 def close @closed = true end |
#close_socket(sock) ⇒ Object
50 51 52 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 50 def close_socket(sock) @closed_sockets << sock end |
#heartbeat_loop(sock) ⇒ Object
44 45 46 47 48 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 44 def heartbeat_loop(sock) @heartbeat_started = true sleep 0.01 until @closed @heartbeat_finished = true end |
#recv(sock) ⇒ Object
38 39 40 41 42 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 38 def recv(sock) unless @recv_callback.nil? serialize(@recv_callback.call(sock)) end end |
#send(sock, data) ⇒ Object
32 33 34 35 36 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 32 def send(sock, data) unless @send_callback.nil? @send_callback.call(sock, unserialize(data)) end end |
#shutdown_heartbeat(sock) ⇒ Object
54 55 56 57 |
# File 'lib/iruby/session_adapter/test_adapter.rb', line 54 def shutdown_heartbeat(sock) @closed = true close_socket(sock) end |