class Server

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

Definitions

def initialize(endpoint, control_endpoint, exchange_limit: 8, configuration: Configuration.default)

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.

parameter configuration Configuration

Request classification and scheduling policy.

Implementation

def initialize(endpoint, control_endpoint, exchange_limit: 8, configuration: Configuration.default)
	@registry = Registry.new(exchange_limit: exchange_limit, permit_limit: configuration.permit_limit)
	@proxy = Proxy.new(@registry, configuration: configuration)
	@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 scheduler

Signature

attribute Scheduler

The central request scheduler.

Implementation

def scheduler
	@proxy.scheduler
end

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

Stop pending requests and close the endpoint registry.

Implementation

def close
	@proxy.scheduler.close
	@registry.close
end