Class: StarlingServer::Base
- Inherits:
-
Object
- Object
- StarlingServer::Base
- Defined in:
- lib/starling/server.rb
Constant Summary
- DEFAULT_HOST =
'127.0.0.1'- DEFAULT_PORT =
22122- DEFAULT_PATH =
"/tmp/starling/"- DEFAULT_TIMEOUT =
60
Instance Attribute Summary (collapse)
-
- (Object) logger
readonly
Returns the value of attribute logger.
Class Method Summary (collapse)
- + (Object) logger
-
+ (Object) start(opts = {})
Initialize a new Starling server and immediately start processing requests.
Instance Method Summary (collapse)
-
- (Base) initialize(opts = {})
constructor
Initialize a new Starling server, but do not accept connections or process requests.
-
- (Object) run
Start listening and processing requests.
-
- (Object) stats(stat = nil)
:nodoc:.
-
- (Object) stop
Stop accepting new connections and shutdown gracefully.
Constructor Details
- (Base) initialize(opts = {})
Initialize a new Starling server, but do not accept connections or process requests.
opts is as for start
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/starling/server.rb', line 49 def initialize(opts = {}) @opts = { :host => DEFAULT_HOST, :port => DEFAULT_PORT, :path => DEFAULT_PATH, :timeout => DEFAULT_TIMEOUT, :server => self }.merge(opts) @stats = Hash.new(0) FileUtils.mkdir_p(@opts[:path]) end |
Instance Attribute Details
- (Object) logger (readonly)
Returns the value of attribute logger
16 17 18 |
# File 'lib/starling/server.rb', line 16 def logger @logger end |
Class Method Details
+ (Object) logger
105 106 107 |
# File 'lib/starling/server.rb', line 105 def self.logger @@logger end |
+ (Object) start(opts = {})
Initialize a new Starling server and immediately start processing requests.
opts is an optional hash, whose valid options are:
[:host] Host on which to listen (default is 127.0.0.1).
[:port] Port on which to listen (default is 22122).
[:path] Path to Starling queue logs. Default is /tmp/starling/
[:timeout] Time in seconds to wait before closing connections.
[:logger] A Logger object, an IO handle, or a path to the log.
[:loglevel] Logger verbosity. Default is Logger::ERROR.
Other options are ignored.
38 39 40 41 |
# File 'lib/starling/server.rb', line 38 def self.start(opts = {}) server = self.new(opts) server.run end |
Instance Method Details
- (Object) run
Start listening and processing requests.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/starling/server.rb', line 67 def run @stats[:start_time] = Time.now if @opts[:syslog_channel] begin require 'syslog_logger' @@logger = SyslogLogger.new(@opts[:syslog_channel]) rescue LoadError # SyslogLogger isn't available, so we're just going to use Logger end end @@logger ||= case @opts[:logger] when IO, String; Logger.new(@opts[:logger]) when Logger; @opts[:logger] else; Logger.new(STDERR) end begin @opts[:queue] = QueueCollection.new(@opts[:path]) rescue InaccessibleQueuePath => e puts "Error: #{e.}" exit 1 end @@logger.level = @opts[:log_level] || Logger::ERROR @@logger.info "Starling STARTUP on #{@opts[:host]}:#{@opts[:port]}" EventMachine.epoll EventMachine.set_descriptor_table_size(4096) EventMachine.run do EventMachine.start_server(@opts[:host], @opts[:port], Handler, @opts) end # code here will get executed on shutdown: @opts[:queue].close end |
- (Object) stats(stat = nil)
:nodoc:
117 118 119 120 121 122 123 |
# File 'lib/starling/server.rb', line 117 def stats(stat = nil) #:nodoc: case stat when nil; @stats when :connections; 1 else; @stats[stat] end end |
- (Object) stop
Stop accepting new connections and shutdown gracefully.
113 114 115 |
# File 'lib/starling/server.rb', line 113 def stop EventMachine.stop_event_loop end |