Sha256: 779d3f2b2712206379cfb8369e1476f39962856603897fc4f1480b11d0d7e835

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

module Waves
  
  module Servers
    
    # 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.
    
    class Base
      
      attr_reader :application, :host, :port
      def initialize( application, host, port )
        @application = application
        @host = host ;@port = port
      end
      
      # starts server, retrying every second until it succeeds
      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
      
      def stop
        Waves::Logger.info "#{self.class.basename} on #{host}:#{port} stopped."
      end
      
    end
  end
end

Version data entries

10 entries across 10 versions & 4 rubygems

Version Path
dyoder-waves-0.8.0 lib/servers/base.rb
waves-edge-2009.03.10.13.14 lib/servers/base.rb
waves-stable-2009.3.10 lib/servers/base.rb
waves-0.9.3 lib/waves/servers/base.rb
waves-0.9.2 lib/waves/servers/base.rb
waves-0.9.1 lib/waves/servers/base.rb
waves-0.9.0 lib/waves/servers/base.rb
waves-0.8.2 lib/servers/base.rb
waves-0.8.0 lib/servers/base.rb
waves-0.8.1 lib/servers/base.rb