Class: Falcon::Service::Server
- Inherits:
-
Async::Service::Generic
- Object
- Async::Service::Generic
- Falcon::Service::Server
- Defined in:
- lib/falcon/service/server.rb
Instance Method Summary collapse
-
#initialize ⇒ Server
constructor
A new instance of Server.
-
#preload! ⇒ Object
Preload any resources specified by the environment.
-
#setup(container) ⇒ Object
Setup the container with the application instance.
-
#start ⇒ Object
Prepare the bound endpoint for the server.
-
#stop ⇒ Object
Close the bound endpoint.
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
15 16 17 18 19 |
# File 'lib/falcon/service/server.rb', line 15 def initialize(...) super @bound_endpoint = nil end |
Instance Method Details
#preload! ⇒ Object
Preload any resources specified by the environment.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/falcon/service/server.rb', line 22 def preload! root = @evaluator.root if scripts = @evaluator.preload scripts = Array(scripts) scripts.each do |path| Console.logger.info(self) {"Preloading #{path}..."} full_path = File.(path, root) load(full_path) end end end |
#setup(container) ⇒ Object
Setup the container with the application instance.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/falcon/service/server.rb', line 53 def setup(container) = @evaluator. container.run(name: self.name, **) do |instance| evaluator = @environment.evaluator Async do |task| server = Falcon::Server.new(evaluator.middleware, @bound_endpoint, protocol: @endpoint.protocol, scheme: @endpoint.scheme) server.run instance.ready! task.children.each(&:wait) end end end |
#start ⇒ Object
Prepare the bound endpoint for the server.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/falcon/service/server.rb', line 37 def start @endpoint = @evaluator.endpoint Sync do @bound_endpoint = @endpoint.bound end preload! Console.logger.info(self) {"Starting #{self.name} on #{@endpoint}"} super end |
#stop ⇒ Object
Close the bound endpoint.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/falcon/service/server.rb', line 72 def stop(...) if @bound_endpoint @bound_endpoint.close @bound_endpoint = nil end @endpoint = nil super end |