Class: JettyRails::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/jetty_rails/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Runner

Returns a new instance of Runner.


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jetty_rails/runner.rb', line 8

def initialize(config = {})
  @servers = {}
  config.symbolize_keys!
  if config[:servers].nil?
    add_server(config) 
  else
    config[:servers].each do |server_config|
      server_config.symbolize_keys!
      server_config.reverse_merge!(config)
      server_config.delete(:servers)
      add_server(server_config)
    end
  end
end

Instance Attribute Details

#serversObject (readonly)

Returns the value of attribute servers


6
7
8
# File 'lib/jetty_rails/runner.rb', line 6

def servers
  @servers
end

Instance Method Details

#add_server(config = {}) ⇒ Object


23
24
25
26
# File 'lib/jetty_rails/runner.rb', line 23

def add_server(config = {})
  server = JettyRails::Server.new(config)
  @servers[server.config[:port]] = server
end

#startObject


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jetty_rails/runner.rb', line 28

def start
  server_threads = ThreadGroup.new
  @servers.each do |base, server|
    log("Starting server #{base}")
    server_threads.add(Thread.new do
      server.start
    end)
  end
  
  server_threads.list.each {|thread| thread.join } unless server_threads.list.empty?
end