Module: Ramaze::Adapter
- Defined in:
- lib/ramaze/adapter.rb,
lib/ramaze/adapter/cgi.rb,
lib/ramaze/adapter/ebb.rb,
lib/ramaze/adapter/base.rb,
lib/ramaze/adapter/fcgi.rb,
lib/ramaze/adapter/lsws.rb,
lib/ramaze/adapter/scgi.rb,
lib/ramaze/adapter/thin.rb,
lib/ramaze/adapter/mongrel.rb,
lib/ramaze/adapter/webrick.rb,
lib/ramaze/spec/helper/mock_http.rb
Overview
This module holds all classes and methods related to the adapters like webrick or mongrel. It’s responsible for starting and stopping them.
Defined Under Namespace
Classes: Base, Cgi, Ebb, Fake, Fcgi, Lsws, Mongrel, Scgi, Thin, WEBrick
Constant Summary collapse
- MIDDLEWARE =
(Rack) middleware injected around Adapter::Base::call
OrderedSet.new( Ramaze::Current, Rack::ShowStatus, Rack::ShowExceptions )
Class Method Summary collapse
-
.shutdown ⇒ Object
Calls ::shutdown on all running adapters and waits up to 1 second for them to finish, then goes on to kill them and exit still.
-
.start_adapter ⇒ Object
Takes Global.adapter and starts if test_connections is positive that a connection can be made to the specified host and port.
-
.startup(options = {}) ⇒ Object
Is called by Ramaze.startup and will first call start_adapter and wait up to 3 seconds for an adapter to appear.
-
.test_connection(host, port) ⇒ Object
Opens a TCPServer temporarily and returns true if a connection is possible and false if none can be made.
Class Method Details
.shutdown ⇒ Object
Calls ::shutdown on all running adapters and waits up to 1 second for them to finish, then goes on to kill them and exit still.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ramaze/adapter.rb', line 74 def shutdown Timeout.timeout(3) do a = Global.server[:adapter] a.shutdown if a.respond_to?(:shutdown) end rescue Timeout::Error Global.server.kill! # Hard exit! because it won't be able to kill Webrick otherwise exit! end |
.start_adapter ⇒ Object
Takes Global.adapter and starts if test_connections is positive that a connection can be made to the specified host and port. If you set Global.adapter to false it won’t start any but deploy a dummy which is useful for testing purposes where you just send fake requests to Dispatcher.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ramaze/adapter.rb', line 53 def start_adapter if adapter = Global.adapter host, port = Global.host, Global.port if Global.test_connections test_connection(host, port) Log.info("Ramaze is ready to run on: #{host}:#{port}") end adapter.start(host, port) else # run dummy Global.server = Thread.new{ sleep } Log.warn("Seems like Global.adapter is turned off", "Continue without adapter.") end rescue LoadError => ex Log.warn(ex, "Continue without adapter.") end |
.startup(options = {}) ⇒ Object
Is called by Ramaze.startup and will first call start_adapter and wait up to 3 seconds for an adapter to appear. It will then wait for the adapters to finish If Global.run_loose is set or otherwise pass you on control which is useful for testing or IRB sessions.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ramaze/adapter.rb', line 31 def startup = {} start_adapter Timeout.timeout(3) do sleep 0.01 until Global.server end Global.server.join unless Global.run_loose rescue SystemExit Ramaze.shutdown rescue Object => ex Log.error(ex) Ramaze.shutdown end |
.test_connection(host, port) ⇒ Object
Opens a TCPServer temporarily and returns true if a connection is possible and false if none can be made
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ramaze/adapter.rb', line 88 def test_connection(host, port) Timeout.timeout(1) do testsock = TCPServer.new(host, port) testsock.close true end rescue => ex Log.error(ex) Log.error("Cannot open connection on #{host}:#{port}") Ramaze.shutdown end |