Class: Falcon::Service::Server

Inherits:
Async::Service::Managed::Service
  • Object
show all
Defined in:
lib/falcon/service/server.rb

Overview

A managed service for running Falcon servers.

Instance Method Summary collapse

Constructor Details

#initializeServer

Initialize the server service.



18
19
20
21
22
# File 'lib/falcon/service/server.rb', line 18

def initialize(...)
	super
	
	@bound_endpoint = nil
end

Instance Method Details

#run(instance, evaluator) ⇒ Object

Run the service logic.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/falcon/service/server.rb', line 42

def run(instance, evaluator)
	if evaluator.respond_to?(:make_supervised_worker)
		Console.warn(self, "Async::Container::Supervisor is replaced by Async::Service::Supervisor, please update your service definition.")
		
		evaluator.make_supervised_worker(instance).run
	end
	
	server = evaluator.make_server(@bound_endpoint)
	
	Async do |task|
		server.run
		
		task.children&.each(&:wait)
	end
	
	server
end

#startObject

Prepare the bound endpoint for the server.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/falcon/service/server.rb', line 25

def start
	@endpoint = @evaluator.endpoint
	
	Sync do
		@bound_endpoint = @endpoint.bound
	end
	
	Console.info(self){"Starting #{self.name} on #{@endpoint}"}
	
	super
end

#stopObject

Close the bound endpoint.



71
72
73
74
75
76
77
78
79
80
# File 'lib/falcon/service/server.rb', line 71

def stop(...)
	if @bound_endpoint
		@bound_endpoint.close
		@bound_endpoint = nil
	end
	
	@endpoint = nil
	
	super
end