Class: RComet::Server

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Server

Create a new Comet server



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

def initialize( options = {}, &block )
  @conf = {
    :host => "0.0.0.0",
    :port => 8990,
    :mount => "/comet",
    :log => $stdout,
    :server => :webrick
  }.merge( options )
  
  if block_given?
    @comet = RComet::RackAdapter.new( &block )
  else
    @comet = RComet::RackAdapter.new( )
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

:nodoc:



53
54
55
# File 'lib/rcomet/server.rb', line 53

def method_missing(method_name, *args, &block) #:nodoc:
  @comet.send(method_name,*args, &block)
end

Instance Method Details

#startObject

Start the Comet server



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rcomet/server.rb', line 25

def start
  route = { @conf[:mount] => @comet }
  app = Rack::URLMap.new(route)
  app = Rack::ContentLength.new(app)
  app = Rack::CommonLogger.new(app, Logger.new(@conf[:log]))
  
  @main_loop = Thread.new do
    case @conf[:server].to_sym
    when :mongrel
      puts "** Starting Mongrel on #{@conf[:host]}:#{@conf[:port]}"
      @server = Rack::Handler::Mongrel.run( app, {:Port => @conf[:port], :Host => @conf[:host]} )
    when :webrick
      puts "** Starting WEBrick on #{@conf[:host]}:#{@conf[:port]}"
      @server = Rack::Handler::WEBrick.run( app, {:Port => @conf[:port], :BindAddress => @conf[:host]} )
    when :thin
      puts "** Starting Thin on #{@conf[:host]}:#{@conf[:port]}"
      @server = Rack::Handler::Thin.run( app, {:Port => @conf[:port], :Host => @conf[:host]} )
    end
    
    puts "Thread end !"
    exit
  end
  
  at_exit {
    puts "Quitting..."
  }
end