Class: Falcon::Service::Application

Inherits:
Proxy show all
Defined in:
lib/falcon/service/application.rb

Instance Method Summary collapse

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



31
32
33
34
35
# File 'lib/falcon/service/application.rb', line 31

def initialize(environment)
  super
  
  @bound_endpoint = nil
end

Instance Method Details

#middlewareObject



37
38
39
# File 'lib/falcon/service/application.rb', line 37

def middleware
  @evaluator.middleware
end

#preload!Object



41
42
43
44
45
46
47
48
49
# File 'lib/falcon/service/application.rb', line 41

def preload!
  if scripts = @evaluator.preload
    scripts.each do |path|
      Async.logger.info(self) {"Preloading #{path}..."}
      full_path = File.expand_path(path, self.root)
      load(full_path)
    end
  end
end

#setup(container) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/falcon/service/application.rb', line 63

def setup(container)
  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, self.protocol, self.scheme)
      
      server.run
      
      instance.ready!
      
      task.children.each(&:wait)
    end
  end
  
  super
end

#startObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/falcon/service/application.rb', line 51

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

#stopObject



81
82
83
84
85
86
# File 'lib/falcon/service/application.rb', line 81

def stop
  @bound_endpoint&.close
  @bound_endpoint = nil
  
  super
end