class Falcon::Service::Application
Implements an application server using an internal clear-text proxy.
Public Class Methods
new(environment)
click to toggle source
Calls superclass method
# File lib/falcon/service/application.rb, line 32 def initialize(environment) super @bound_endpoint = nil end
Public Instance Methods
count()
click to toggle source
Number of instances to start. @returns [Integer | nil]
# File lib/falcon/service/application.rb, line 47 def count @environment.evaluator.count end
middleware()
click to toggle source
The middleware that will be served by this application. @returns [Protocol::HTTP::Middleware]
# File lib/falcon/service/application.rb, line 40 def middleware # In a multi-threaded container, we don't want to modify the shared evaluator's cache, so we create a new evaluator: @environment.evaluator.middleware end
preload!()
click to toggle source
Preload any resources specified by the environment.
# File lib/falcon/service/application.rb, line 52 def preload! if scripts = @evaluator.preload scripts.each do |path| Console.logger.info(self) {"Preloading #{path}..."} full_path = File.expand_path(path, self.root) load(full_path) end end end
setup(container)
click to toggle source
Setup instances of the application into the container. @parameter container [Async::Container::Generic]
Calls superclass method
# File lib/falcon/service/application.rb, line 78 def setup(container) protocol = self.protocol scheme = self.scheme run_options = { name: self.name, restart: true, } run_options[:count] = count unless count.nil? container.run(**run_options) do |instance| Async do |task| Console.logger.info(self) {"Starting application server for #{self.root}..."} server = Server.new(self.middleware, @bound_endpoint, protocol: protocol, scheme: scheme) server.run instance.ready! task.children.each(&:wait) end end super end
start()
click to toggle source
Prepare the bound endpoint for the application instances. Invoke {preload!} to load shared resources into the parent process.
Calls superclass method
# File lib/falcon/service/application.rb, line 64 def start Console.logger.info(self) {"Binding to #{self.endpoint}..."} @bound_endpoint = Async::Reactor.run do Async::IO::SharedEndpoint.bound(self.endpoint) end.wait preload! super end
stop()
click to toggle source
Close the bound endpoint.
Calls superclass method
# File lib/falcon/service/application.rb, line 107 def stop @bound_endpoint&.close @bound_endpoint = nil super end