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
-
#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.
32 33 34 35 36 |
# File 'lib/falcon/service/application.rb', line 32 def initialize(environment) super @bound_endpoint = nil end |
Instance Method Details
#middleware ⇒ Object
The middleware that will be served by this application.
40 41 42 43 |
# 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! ⇒ Object
Preload any resources specified by the environment.
46 47 48 49 50 51 52 53 54 |
# File 'lib/falcon/service/application.rb', line 46 def preload! if scripts = @evaluator.preload scripts.each do |path| Async.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.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/falcon/service/application.rb', line 72 def setup(container) protocol = self.protocol scheme = self.scheme container.run(name: self.name, restart: true) do |instance| Async(logger: logger) do |task| Async.logger.info(self) {"Starting application server for #{self.root}..."} server = Server.new(self.middleware, @bound_endpoint, protocol, 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.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/falcon/service/application.rb', line 58 def start Async.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.
94 95 96 97 98 99 |
# File 'lib/falcon/service/application.rb', line 94 def stop @bound_endpoint&.close @bound_endpoint = nil super end |