Parent

BrB::Tunnel::Handler

Brb interface Handler for Tunnel over Event machine

Attributes

uri[R]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/brb/tunnel.rb, line 22
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

Public Instance Methods

active?() click to toggle source

Return true if the tunnel is currently active

# File lib/brb/tunnel.rb, line 80
def active?
  @active
end
close_connection(after_writing = false) click to toggle source
# File lib/brb/tunnel.rb, line 53
def close_connection(after_writing = false)
  @active = false
  super
end
method_missing(meth, *args, &block) click to toggle source

When no method is found on tunnel interface, create an brb out request

# File lib/brb/tunnel.rb, line 85
def method_missing(meth, *args, &block)
  return nil if !@active
  new_brb_out_request(meth, *args, &block)
end
post_init() click to toggle source

EventMachine Callback, called after connection has been initialized

# File lib/brb/tunnel.rb, line 43
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
stop_service() click to toggle source

Stop the service

# File lib/brb/tunnel.rb, line 71
def stop_service
  BrB.logger.info ' [BrB] Stopping Tunnel service...'
  @active = false
  EM.schedule do
    close_connection
  end
end
unbind() click to toggle source

EventMachine unbind event The connection has been closed

# File lib/brb/tunnel.rb, line 60
def unbind
  BrB.logger.info ' [BrB] Tunnel service closed'
  @active = false
  if @block
    EM.defer do
      @block.call(:unregister, self)
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.