Class: Falcon::Supervisor

Inherits:
Object
  • Object
show all
Defined in:
lib/falcon/supervisor.rb

Defined Under Namespace

Classes: Statistics

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ Supervisor

Returns a new instance of Supervisor.



68
69
70
# File 'lib/falcon/supervisor.rb', line 68

def initialize(endpoint)
	@endpoint = endpoint
end

Instance Method Details

#handle(message) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/falcon/supervisor.rb', line 85

def handle(message)
	case message[:please]
	when 'restart'
		self.restart(message)
	when 'statistics'
		self.statistics(message)
	end
end

#restart(message) ⇒ Object



72
73
74
75
76
77
# File 'lib/falcon/supervisor.rb', line 72

def restart(message)
	signal = message[:signal] || :INT
	
	# Sepukku:
	Process.kill(signal, -Process.getpgrp)
end

#runObject



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/falcon/supervisor.rb', line 94

def run
	Async.logger.info("Binding to #{@endpoint}")
	@endpoint.accept do |peer|
		stream = Async::IO::Stream.new(peer)
		
		while message = stream.gets("\0")
			response = handle(JSON.parse(message, symbolize_names: true))
			stream.puts(response.to_json, separator: "\0")
		end
	end
end

#statistics(message) ⇒ Object



79
80
81
82
83
# File 'lib/falcon/supervisor.rb', line 79

def statistics(message)
	statistics = Statistics.new
	
	statistics.capture
end