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
endpointAsync::HTTP::Endpoint The downstream HTTP endpoint.
-
parameter
control_endpointIO::Endpoint The async-bus control endpoint.
-
parameter
exchange_limitInteger 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
parentInterface(: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