Class: BrB::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/brb/service.rb

Constant Summary collapse

@@uri =
nil
@@em_signature =
nil
@@verbose =
false

Class Method Summary collapse

Class Method Details

.instanceObject

Deprecated old method



50
51
52
53
# File 'lib/brb/service.rb', line 50

def instance
  BrB.logger.warn "DEPRECATION WARNING: BrB::Service::instance is deprecated => Just use BrB::Service"
  self
end

.start_service(opts = {}, &block) ⇒ Object

Start a server hosted on the object given, If an uri is given, automatcilay connect to the distant brb object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/brb/service.rb', line 17

def start_service(opts = {}, &block)
  return if @@em_signature
  
  @@verbose = opts[:verbose]
  BrB.logger.level = @@verbose ? Logger::INFO : Logger::WARN

  addr = opts[:uri] || "brb://#{opts[:host] || 'localhost'}:#{opts[:port] || 6200}"

  BrB.logger.info " [BrB] Start service on #{addr} ..."
  @@uri, @@em_signature = BrB::Protocol::open_server(addr, BrB::Tunnel::Handler, opts.merge(:block => block))
  BrB.logger.info " [BrB] Service started on #{@@uri}"
end

.stop_serviceObject

Stop the Brb Service



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/brb/service.rb', line 35

def stop_service
  return if !@@em_signature or !EM::reactor_running?

  BrB.logger.info " [BrB] Stop service on #{@@uri}"
  sign = @@em_signature
  q = Queue.new # Creation of a Queue for waiting server to stop
  EM::schedule do
    q << EM::stop_server(sign)
  end
  q.pop
  @@em_signature = nil
  @@uri = nil
end

.uriObject



30
31
32
# File 'lib/brb/service.rb', line 30

def uri
  @@uri
end