FalconSourceFalconCompositeServer

class CompositeServer

A composite server that manages multiple class Falcon::Server instances.

This class coordinates running multiple server instances concurrently, allowing you to:

Example: Create and run several applications.

require 'falcon/composite_server'
require 'falcon/server'

# Create individual servers
servers = {
  "http" => Falcon::Server.new(app1, endpoint1),
  "https" => Falcon::Server.new(app2, endpoint2)
}

# Create the composite server
composite = Falcon::CompositeServer.new(servers)

# Run all servers
composite.run

Signature

Definitions

def initialize(servers)

Initialize a composite server with the given server instances.

Signature

parameter servers Hash(String, Falcon::Server)

A hash mapping server names to server instances.

Implementation

def initialize(servers)
	@servers = servers
end

attr :servers

The individual server instances mapped by name.

Signature

attribute Hash(String, Falcon::Server)

def run

Run the composite server, starting all individual servers.

This method should be called within an Async context. It will run all server instances concurrently.

Signature

returns Async::Task

The task running the servers. Call stop on the returned task to stop all servers.

Implementation

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

def statistics_string

Generates a human-readable string representing statistics for all servers.

Signature

returns String

A string representing the current statistics for each server.

Implementation

def statistics_string
	@servers.map do |name, server|
		"#{name}: #{server.statistics_string}"
	end.join(", ")
end

def detailed_statistics

Get detailed statistics for each server.

Signature

returns Hash(String, String)

A hash mapping server names to their statistics strings.

Implementation

def detailed_statistics
	@servers.transform_values(&:statistics_string)
end