Sha256: 9b7831c677fd30cbfb06efd59f7895a93acd1308157b3e1f03f9816ae4909555
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
## # Abstract runner class to control instance of Midori Server # @attr [ String ] bind the address to bind # @attr [ Fixnum ] port the port to bind class Midori::Runner attr_reader :bind, :port # Define status of a runner # @param [ Class ] api inherited from [ Midori::API ] # @param [ Class ] configure inherited from [ Midori::Configure ] def initialize(api, configure = Midori::Configure) @logger = configure.logger @bind = configure.bind @port = configure.port @before = configure.before @api = ((api.is_a?Midori::APIEngine) ? api : Midori::APIEngine.new(api, configure.route_type)) end # Get Midori server whether running # @return [Boolean] [true] running # @return [Boolean] [false] not running def running? !!@server_signature end # Start the Midori server # @note This is an async method, but no callback def start return if running? EventMachine.set_simultaneous_accept_count(40) unless RUBY_PLATFORM == 'java' EventMachine.run do async :before do @before.call end before @logger.info "Midori #{Midori::VERSION} is now running on #{bind}:#{port}".blue @server_signature = EventMachine.start_server bind, port, Midori::Server, @api, @logger end nil end # Stop the Midori server # @note This is an async method, but no callback # @return [Boolean] [true] stop successfully # @return [Boolean] [false] nothing to stop def stop if running? @logger.info 'Goodbye Midori'.blue EventMachine.stop_server(@server_signature) @server_signature = nil EM.stop true else @logger.error 'Midori Server has NOT been started'.red false end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
em-midori-0.1.7 | lib/midori/runner.rb |