Class: Waves::Servers::Base

Inherits:
Object show all
Defined in:
lib/waves/servers/base.rb

Overview

Inherit from this class and define the #call method to create Servers. Like Rack Handlers, except with an attempt at a more generic interface. The #call method should yield with the actual server object.

Direct Known Subclasses

Mongrel, WEBrick

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application, host, port) ⇒ Base

Returns a new instance of Base.



12
13
14
15
# File 'lib/waves/servers/base.rb', line 12

def initialize( application, host, port )
  @application = application
  @host = host ;@port = port
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



11
12
13
# File 'lib/waves/servers/base.rb', line 11

def application
  @application
end

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/waves/servers/base.rb', line 11

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



11
12
13
# File 'lib/waves/servers/base.rb', line 11

def port
  @port
end

Instance Method Details

#startObject

starts server, retrying every second until it succeeds



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/waves/servers/base.rb', line 18

def start
  Thread.new do
    connect = false
    until connect do
      begin
        call do |server| 
          @server = server
          Waves::Logger.info "#{self.class.basename} started on #{host}:#{port}."
        end
      rescue RuntimeError => e
        Waves::Logger.error e.to_s
        sleep 1
      end
      connect = true
    end
  end
end

#stopObject



36
37
38
# File 'lib/waves/servers/base.rb', line 36

def stop
  Waves::Logger.info "#{self.class.basename} on #{host}:#{port} stopped."
end