Class: Falcon::Service::Application
- Defined in:
- lib/falcon/service/application.rb
Overview
Implements an application server using an internal clear-text proxy.
Instance Method Summary collapse
-
#count ⇒ Object
Number of instances to start.
-
#initialize(environment) ⇒ Application
constructor
A new instance of Application.
-
#middleware ⇒ Object
The middleware that will be served by this application.
-
#preload! ⇒ Object
Preload any resources specified by the environment.
-
#setup(container) ⇒ Object
Setup instances of the application into the container.
-
#start ⇒ Object
Prepare the bound endpoint for the application instances.
-
#stop ⇒ Object
Close the bound endpoint.
Methods inherited from Proxy
#authority, #endpoint, #name, #protocol, #root, #scheme, #ssl_context
Methods inherited from Generic
#include?, #logger, #name, wrap
Constructor Details
#initialize(environment) ⇒ Application
Returns a new instance of Application.
16 17 18 19 20 |
# File 'lib/falcon/service/application.rb', line 16 def initialize(environment) super @bound_endpoint = nil end |
Instance Method Details
#count ⇒ Object
Number of instances to start.
31 32 33 |
# File 'lib/falcon/service/application.rb', line 31 def count @environment.evaluator.count end |
#middleware ⇒ Object
The middleware that will be served by this application.
24 25 26 27 |
# File 'lib/falcon/service/application.rb', line 24 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! ⇒ Object
Preload any resources specified by the environment.
36 37 38 39 40 41 42 43 44 |
# File 'lib/falcon/service/application.rb', line 36 def preload! if scripts = @evaluator.preload scripts.each do |path| Console.logger.info(self) {"Preloading #{path}..."} full_path = File.(path, self.root) load(full_path) end end end |
#setup(container) ⇒ Object
Setup instances of the application into the container.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/falcon/service/application.rb', line 62 def setup(container) protocol = self.protocol scheme = self.scheme = { name: self.name, restart: true, } [:count] = count unless count.nil? container.run(**) 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 ⇒ Object
Prepare the bound endpoint for the application instances. Invoke #preload! to load shared resources into the parent process.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/falcon/service/application.rb', line 48 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 ⇒ Object
Close the bound endpoint.
91 92 93 94 95 96 |
# File 'lib/falcon/service/application.rb', line 91 def stop @bound_endpoint&.close @bound_endpoint = nil super end |