Class: BrB::Tunnel::Handler
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- BrB::Tunnel::Handler
- Defined in:
- lib/brb/tunnel.rb
Overview
Brb interface Handler for Tunnel over Event machine
Constant Summary
Constants included from Shared
Constants included from Request
Request::CallbackRequestCode, Request::MessageRequestCode, Request::ReturnCode
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Return true if the tunnel is currently active.
- #close_connection(after_writing = false) ⇒ Object
-
#initialize(opts = {}) ⇒ Handler
constructor
A new instance of Handler.
-
#method_missing(meth, *args, &block) ⇒ Object
When no method is found on tunnel interface, create an brb out request.
-
#post_init ⇒ Object
EventMachine Callback, called after connection has been initialized.
-
#stop_service ⇒ Object
Stop the service.
-
#unbind ⇒ Object
EventMachine unbind event The connection has been closed.
Methods included from Shared
#brb_send, #declare_callback, #get_callback, #load_request, #make_proxy, #receive_data, #recv, #treat_callback_return, #treat_request
Methods included from Request
#is_brb_request_blocking?, #new_brb_in_request, #new_brb_out_request
Constructor Details
#initialize(opts = {}) ⇒ Handler
Returns a new instance of Handler.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/brb/tunnel.rb', line 23 def initialize(opts = {}) super @object = opts[:object] @verbose = opts[:verbose] BrB.logger.level = @verbose ? Logger::INFO : Logger::WARN @timeout_rcv_value = opts[:timeout] || 30 # Currently not implemented due to the lack of performance of ruby Timeout @close_after_timeout = opts[:close_after_timeout] || false @uri = opts[:uri] @replock = Mutex.new @responses = {} @block = opts[:block] @queue = Queue.new @buffer = '' # Callbacks handling : @callbacks = {} @callbacks_mutex = Mutex.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
When no method is found on tunnel interface, create an brb out request
86 87 88 89 |
# File 'lib/brb/tunnel.rb', line 86 def method_missing(meth, *args, &block) return nil if !@active new_brb_out_request(meth, *args, &block) end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
18 19 20 |
# File 'lib/brb/tunnel.rb', line 18 def uri @uri end |
Instance Method Details
#active? ⇒ Boolean
Return true if the tunnel is currently active
81 82 83 |
# File 'lib/brb/tunnel.rb', line 81 def active? @active end |
#close_connection(after_writing = false) ⇒ Object
54 55 56 57 |
# File 'lib/brb/tunnel.rb', line 54 def close_connection(after_writing = false) @active = false super end |
#post_init ⇒ Object
EventMachine Callback, called after connection has been initialized
44 45 46 47 48 49 50 51 52 |
# File 'lib/brb/tunnel.rb', line 44 def post_init BrB.logger.info " [BrB] Tunnel initialized on #{@uri}" @active = true if @block EM.defer do @block.call(:register, self) end end end |