Module: Librevox

Defined in:
lib/librevox.rb,
lib/librevox/commands.rb,
lib/librevox/response.rb,
lib/librevox/applications.rb,
lib/librevox/listener/base.rb,
lib/librevox/command_socket.rb,
lib/librevox/listener/inbound.rb,
lib/librevox/listener/outbound.rb

Defined Under Namespace

Modules: Applications, Commands, Listener Classes: CommandSocket, Response

Class Method Summary collapse

Class Method Details

.loggerObject



16
17
18
# File 'lib/librevox.rb', line 16

def self.logger
  @logger ||= logger!
end

.logger!Object



24
25
26
27
28
# File 'lib/librevox.rb', line 24

def self.logger!
  logger = Logger.new(options[:log_file])
  logger.level = options[:log_level]
  logger
end

.logger=(logger) ⇒ Object



20
21
22
# File 'lib/librevox.rb', line 20

def self.logger= logger
  @logger = logger
end

.optionsObject



9
10
11
12
13
14
# File 'lib/librevox.rb', line 9

def self.options
  @options ||= {
    :log_file   => STDOUT,
    :log_level  => Logger::INFO
  }
end

.reopen_logObject



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

def self.reopen_log
  @logger = logger!
end

.run(klass, args = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/librevox.rb', line 57

def self.run klass, args={}
  args[:host] ||= "localhost"

  if klass.ancestors.include? Librevox::Listener::Inbound
    args[:port] ||= 8021
    EM.connect args[:host], args[:port], klass, args
  elsif klass.ancestors.include? Librevox::Listener::Outbound
    args[:port] ||= 8084
    EM.start_server args[:host], args[:port], klass, args
  end
end

.start(klass = nil, args = {}, &block) ⇒ Object

When called without a block, it will start the listener that is passed as first argument:

Librevox.start SomeListener

To start multiple listeners, call with a block and use `run`:

Librevox.start do
  run SomeListener
  run OtherListner
end


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/librevox.rb', line 45

def self.start klass=nil, args={}, &block
  logger.info "Starting Librevox"

  EM.run do
    trap("TERM") {stop}
    trap("INT") {stop}
    trap("HUP") {reopen_log}

    block_given? ? instance_eval(&block) : run(klass, args)
  end
end

.stopObject



69
70
71
72
# File 'lib/librevox.rb', line 69

def self.stop
  logger.info "Terminating Librevox"
  EM.stop
end