class Server

Runs the HTTP load balancer and endpoint-control server together.

Definitions

def initialize(endpoint, control_endpoint, exchange_limit: 8)

Initialize a Fantail server.

Signature

parameter endpoint Async::HTTP::Endpoint

The downstream HTTP endpoint.

parameter control_endpoint IO::Endpoint

The async-bus control endpoint.

parameter exchange_limit Integer

The maximum outstanding responses per backend.

Implementation

def initialize(endpoint, control_endpoint, exchange_limit: 8)
	@registry = Registry.new(exchange_limit: exchange_limit)
	@proxy = Proxy.new(@registry)
	@http_server = Async::HTTP::Server.new(@proxy, endpoint)
	@control_server = Control.new(control_endpoint, @registry)
end

attr :registry

Signature

attribute Registry

The server's endpoint registry.

def run(parent: Async::Task.current)

Run the HTTP and control servers.

Signature

parameter parent Interface(:async)

The parent task.

returns Async::Task

The server task.

Implementation

def run(parent: Async::Task.current)
	parent.async do |task|
		task.async do
			@control_server.accept
		end
		
		@http_server.run.wait
	end
end

def close

Close the endpoint registry.

Implementation

def close
	@registry.close
end