Class: Falcon::CompositeServer
- Inherits:
-
Object
- Object
- Falcon::CompositeServer
- Defined in:
- lib/falcon/composite_server.rb
Overview
A composite server that manages multiple Server instances.
This class coordinates running multiple server instances concurrently, allowing you to:
-
Serve different applications on different endpoints.
-
Use different configurations per server.
-
Access statistics for each named server.
-
Control all servers as a single unit.
Instance Attribute Summary collapse
-
#servers ⇒ Object
readonly
The individual server instances mapped by name.
Instance Method Summary collapse
-
#detailed_statistics ⇒ Object
Get detailed statistics for each server.
-
#initialize(servers) ⇒ CompositeServer
constructor
Initialize a composite server with the given server instances.
-
#run ⇒ Object
Run the composite server, starting all individual servers.
-
#statistics_string ⇒ Object
Generates a human-readable string representing statistics for all servers.
Constructor Details
#initialize(servers) ⇒ CompositeServer
Initialize a composite server with the given server instances.
36 37 38 |
# File 'lib/falcon/composite_server.rb', line 36 def initialize(servers) @servers = servers end |
Instance Attribute Details
#servers ⇒ Object (readonly)
The individual server instances mapped by name.
42 43 44 |
# File 'lib/falcon/composite_server.rb', line 42 def servers @servers end |
Instance Method Details
#detailed_statistics ⇒ Object
Get detailed statistics for each server.
73 74 75 |
# File 'lib/falcon/composite_server.rb', line 73 def detailed_statistics @servers.transform_values(&:statistics_string) end |
#run ⇒ Object
Run the composite server, starting all individual servers.
This method should be called within an Async context. It will run all server instances concurrently.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/falcon/composite_server.rb', line 49 def run Async do |task| # Run each server - server.run creates its own Async block internally @servers.each do |name, server| server.run end # Wait for all child tasks to complete task.children.each(&:wait) end end |
#statistics_string ⇒ Object
Generates a human-readable string representing statistics for all servers.
64 65 66 67 68 |
# File 'lib/falcon/composite_server.rb', line 64 def statistics_string @servers.map do |name, server| "#{name}: #{server.statistics_string}" end.join(", ") end |