Class: Hokuto::Server
- Inherits:
-
Object
- Object
- Hokuto::Server
- Defined in:
- lib/hokuto/server.rb
Constant Summary collapse
- Jetty =
org.eclipse.jetty.server.Server
Instance Attribute Summary collapse
-
#applications ⇒ Object
readonly
Returns the value of attribute applications.
-
#certs ⇒ Object
readonly
Returns the value of attribute certs.
-
#handler_collection ⇒ Object
readonly
Returns the value of attribute handler_collection.
-
#http_port ⇒ Object
readonly
Returns the value of attribute http_port.
-
#https_port ⇒ Object
readonly
Returns the value of attribute https_port.
-
#jetty ⇒ Object
readonly
Returns the value of attribute jetty.
Instance Method Summary collapse
-
#add(application) ⇒ Object
register the application.
-
#initialize(options = {}) ⇒ Server
constructor
initialize the server.
-
#run ⇒ Object
booting the server.
-
#stop ⇒ Object
shutting down the server.
Constructor Details
#initialize(options = {}) ⇒ Server
initialize the server.
16 17 18 19 20 21 22 23 |
# File 'lib/hokuto/server.rb', line 16 def initialize( = {}) @http_port = [:port].to_i @https_port = [:https_port].to_i if [:https_port] @jetty = Jetty.new @applications = {} @handler_collection = ContextHandlerCollection.new jetty.handler = @handler_collection end |
Instance Attribute Details
#applications ⇒ Object (readonly)
Returns the value of attribute applications.
12 13 14 |
# File 'lib/hokuto/server.rb', line 12 def applications @applications end |
#certs ⇒ Object (readonly)
Returns the value of attribute certs.
12 13 14 |
# File 'lib/hokuto/server.rb', line 12 def certs @certs end |
#handler_collection ⇒ Object (readonly)
Returns the value of attribute handler_collection.
12 13 14 |
# File 'lib/hokuto/server.rb', line 12 def handler_collection @handler_collection end |
#http_port ⇒ Object (readonly)
Returns the value of attribute http_port.
11 12 13 |
# File 'lib/hokuto/server.rb', line 11 def http_port @http_port end |
#https_port ⇒ Object (readonly)
Returns the value of attribute https_port.
11 12 13 |
# File 'lib/hokuto/server.rb', line 11 def https_port @https_port end |
#jetty ⇒ Object (readonly)
Returns the value of attribute jetty.
12 13 14 |
# File 'lib/hokuto/server.rb', line 12 def jetty @jetty end |
Instance Method Details
#add(application) ⇒ Object
register the application.
26 27 28 29 30 31 32 |
# File 'lib/hokuto/server.rb', line 26 def add(application) previous_application = applications.delete application.context_root handler_collection.remove_handler previous_application.context if previous_application handler_collection.add_handler application.context applications[application.context_root] = application end |
#run ⇒ Object
booting the server.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hokuto/server.rb', line 35 def run [:INT, :TERM, :ABRT].each{|signal|Signal.trap(signal, ->{stop})} connector = SelectChannelConnector.new connector.port = http_port connector.confidential_port = https_port if https_port jetty.add_connector connector jetty.start jetty.join end |
#stop ⇒ Object
shutting down the server.
49 50 51 |
# File 'lib/hokuto/server.rb', line 49 def stop jetty.stop end |