Sha256: 6856a9f22aa67457aaa2bbb7a77027ae683d285179b0cf86de3be52837be22f2

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

require 'thin'
require 'logging'
require 'forwardable'

module Boned
  class Server < Thin::Backends::Base
    DEFAULT_PORT = 6043.freeze
    
    class ServerRunning < Boned::Problem
      def message() "Server already running on port: #{super}" end
    end
    
    class ServerNotRunning < Boned::Problem
      def message() "Server not running on port: #{super}" end
    end
    
    class << self
    end
    
    # Address and port on which the server is listening for connections.
    attr_accessor :host, :port
    
    def initialize(host, port, options)
      @host = host
      @port = port
      super()
    end

    # Connect the server
    def connect
      @signature = EventMachine.start_server(@host, @port, Thin::Connection, &method(:initialize_connection))
    rescue => ex
      puts ex.message
      puts ex.backtrace if Boned.debug
      stop!
    end

    # Stops the server
    def disconnect
      EventMachine.stop_server(@signature)
    end
    
    def to_s
      "#{@host}:#{@port}"
    end
    
  end
  module Controllers
    class Controller < Thin::Controllers::Controller
    end
    class Service < Thin::Controllers::Service
    end
    class Cluster < Thin::Controllers::Cluster
    end
  end
end




#controller = case
#when cluster? then Thin::Controllers::Cluster.new(options)
#when service? then Thin::Controllers::Service.new(options)
#else               Thin::Controllers::Controller.new(options)
#end


Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
boned-0.2.6 lib/boned/server.rb
boned-0.2.5 lib/boned/server.rb
boned-0.2.4 lib/boned/server.rb
boned-0.2.3 lib/boned/server.rb
boned-0.2.2 lib/boned/server.rb
boned-0.2.1 lib/boned/server.rb
boned-0.2.0 lib/boned/server.rb