Class: Mizuno::Server
- Inherits:
-
Object
- Object
- Mizuno::Server
- Defined in:
- lib/mizuno/server.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
-
#rewindable(request) ⇒ Object
Wraps the Java InputStream for the level of Rack compliance desired.
-
#run(app, options = {}) ⇒ Object
Start up an instance of Jetty, running a Rack application.
-
#stop ⇒ Object
Shuts down an embedded Jetty instance.
-
#version ⇒ Object
Returns the full version string.
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
23 24 25 |
# File 'lib/mizuno/server.rb', line 23 def logger @logger end |
Class Method Details
.logger ⇒ Object
43 44 45 |
# File 'lib/mizuno/server.rb', line 43 def Server.logger Logger.logger end |
.run(app, options = {}) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/mizuno/server.rb', line 27 def Server.run(app, = {}) @lock.synchronize do return if @server @server = new @server.run(app, ) end end |
.stop ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/mizuno/server.rb', line 35 def Server.stop @lock.synchronize do return unless @server @server.stop @server = nil end end |
Instance Method Details
#rewindable(request) ⇒ Object
Wraps the Java InputStream for the level of Rack compliance desired.
140 141 142 143 144 145 146 |
# File 'lib/mizuno/server.rb', line 140 def rewindable(request) input = request.getInputStream @options[:rewindable] ? Rack::RewindableInput.new(input.to_io.binmode) : RewindableInputStream.new(input).to_io.binmode end |
#run(app, options = {}) ⇒ Object
Start up an instance of Jetty, running a Rack application. Options can be any of the follwing, and are not case-sensitive:
- :host
-
String specifying the IP address to bind to; defaults to 0.0.0.0.
- :port
-
String or integer with the port to bind to; defaults to 9292.
60 61 62 63 64 65 66 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/mizuno/server.rb', line 60 def run(app, = {}) # Symbolize and downcase keys. @options = = Hash[.map { |k, v| [ k.to_s.downcase.to_sym, v ] }] [:quiet] ||= true if [:embedded] # The Jetty server Logger.configure() @logger = Logger.logger @server = Java.org.eclipse.jetty.server.Server.new @server.setSendServerVersion(false) # Thread pool threads = [:threads] || 50 thread_pool = QueuedThreadPool.new thread_pool.min_threads = [ threads.to_i / 10, 5 ].max thread_pool.max_threads = [ threads.to_i, 10 ].max @server.set_thread_pool(thread_pool) # Connector connector = SelectChannelConnector.new connector.setPort([:port].to_i) connector.setHost([:host]) @server.addConnector(connector) # SSL Connector configure_https() if [:ssl_port] # Switch to a different user or group if we were asked to. Runner.setgid() if [:group] Runner.setuid() if [:user] # Optionally wrap with Mizuno::Reloader. threshold = (ENV['RACK_ENV'] == 'production' ? 10 : 1) app = Mizuno::Reloader.new(app, threshold) \ if [:reloadable] # The servlet itself. rack_handler = RackHandler.new(self) rack_handler.rackup(app) # Add the context to the server and start. @server.set_handler(rack_handler) @server.start $stderr.printf("%s listening on %s:%s\n", version, connector.host, connector.port) unless [:quiet] # If we're embedded, we're done. return if [:embedded] # Stop the server when we get The Signal. trap("SIGTERM") { @server.stop and exit } # Join with the server thread, so that currently open file # descriptors don't get closed by accident. # http://www.ruby-forum.com/topic/209252 @server.join end |
#stop ⇒ Object
Shuts down an embedded Jetty instance.
122 123 124 125 126 127 |
# File 'lib/mizuno/server.rb', line 122 def stop return unless @server $stderr.print "Stopping Jetty..." unless @options[:quiet] @server.stop $stderr.puts "done." unless @options[:quiet] end |