Class: Nonnative::Server
Overview
Runtime runner that manages an in-process Ruby server.
A server runner:
- starts a Ruby thread that runs #perform_start,
- waits briefly (via the runner
wait), and - participates in readiness/shutdown via TCP port checks orchestrated by Pool.
Concrete server implementations are expected to subclass Server and implement:
- #perform_start (to bind/listen and begin serving), and
- #perform_stop (to gracefully shut down).
The underlying configuration is a ConfigurationServer.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(service) ⇒ Server
constructor
A new instance of Server.
-
#start ⇒ Array<(Integer, TrueClass)>
Starts the server thread if it is not already started.
-
#stop ⇒ Integer
Stops the server if it is running.
-
#termination ⇒ String?
Describes how the server thread terminated before becoming ready, for lifecycle diagnostics.
Methods inherited from Runner
Constructor Details
Instance Method Details
#start ⇒ Array<(Integer, TrueClass)>
Starts the server thread if it is not already started.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nonnative/server.rb', line 33 def start unless thread @error = nil @thread = Thread.new do perform_start rescue StandardError => e @error = e raise end @thread.report_on_exception = true wait_start Nonnative.logger.info "started server '#{service.name}'" end [object_id, true] end |
#stop ⇒ Integer
Stops the server if it is running.
Calls #perform_stop, terminates the server thread, and waits briefly.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/nonnative/server.rb', line 57 def stop if thread perform_stop thread.terminate @thread = nil wait_stop Nonnative.logger.info "stopped server '#{service.name}'" end object_id end |
#termination ⇒ String?
Describes how the server thread terminated before becoming ready, for lifecycle diagnostics.
Returns nil while the thread is still alive, so callers can distinguish a dead thread from a
live server that merely missed its readiness window.
77 78 79 80 81 82 83 |
# File 'lib/nonnative/server.rb', line 77 def termination return if thread.nil? || thread.alive? return "server thread raised #{error.class}: #{error.}" if error 'server thread exited before readiness' end |