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
-
#ip_address ⇒ Object
readonly
Returns the value of attribute ip_address.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/brb/tunnel.rb', line 24 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
89 90 91 92 |
# File 'lib/brb/tunnel.rb', line 89 def method_missing(meth, *args, &block) return nil if !@active new_brb_out_request(meth, *args, &block) end |
Instance Attribute Details
#ip_address ⇒ Object (readonly)
Returns the value of attribute ip_address.
19 20 21 |
# File 'lib/brb/tunnel.rb', line 19 def ip_address @ip_address end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
19 20 21 |
# File 'lib/brb/tunnel.rb', line 19 def port @port end |
#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
84 85 86 |
# File 'lib/brb/tunnel.rb', line 84 def active? @active end |
#close_connection(after_writing = false) ⇒ Object
57 58 59 60 |
# File 'lib/brb/tunnel.rb', line 57 def close_connection(after_writing = false) @active = false super end |
#post_init ⇒ Object
EventMachine Callback, called after connection has been initialized
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/brb/tunnel.rb', line 45 def post_init @port, @ip_address = Socket.unpack_sockaddr_in(get_peername) BrB.logger.info " [BrB] Tunnel initialized on #{@uri}" @active = true if @block EM.defer do @block.call(:register, self) end end end |