Class: HttpKit::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/http_kit/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(app, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/http_kit/server.rb', line 8

def Server.run(app, options = {})
  @lock.synchronize do
    return if @server
    @server = new
    @server.run(app, options)

    @server
  end
end

.stopObject



18
19
20
21
22
23
24
25
# File 'lib/http_kit/server.rb', line 18

def Server.stop
  @lock.synchronize do
    return unless @server

    @server.stop
    @handler = nil
  end
end

Instance Method Details

#run(app, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/http_kit/server.rb', line 27

def run(app, options={})
  options = {
      :host    => "0.0.0.0",
      :port    => 9292,
      :threads => 50,
      :queue   => 1000,
    }.merge(options)

  @handler  = HttpKit::RackHandler.new(options[:threads], app, "prefix-", options[:queue])
  @http_kit = Java::OrgHttpkitServer::HttpServer.new(options[:host], options[:port], @handler, 80000, 4000)

  @http_kit.start

  $stdout.printf("HTTP Kit is listening on %s:%s\n", options[:host], options[:port])

  trap("SIGINT") {
    @http_kit.stop
    exit
  }
end

#startObject



48
49
50
# File 'lib/http_kit/server.rb', line 48

def start
  @http_kit.start
end

#stopObject Also known as: shutdown



52
53
54
55
56
57
# File 'lib/http_kit/server.rb', line 52

def stop
  return unless @http_kit
  $stdout.print "Stopping Http kit..." unless @options[:quiet]
  @http_kit.stop
  $stdout.puts "done." unless @options[:quiet]
end