Class: Falcon::Server

Inherits:
Async::HTTP::Server
  • Object
show all
Defined in:
lib/falcon/server.rb

Overview

A server listening on a specific endpoint, hosting a specific middleware.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



39
40
41
42
43
44
45
46
47
# File 'lib/falcon/server.rb', line 39

def initialize(...)
	super
	
	@accept_count = 0
	@connection_count = 0
	
	@request_count = 0
	@active_count = 0
end

Instance Attribute Details

#accept_countObject (readonly)

Returns the value of attribute accept_count.



50
51
52
# File 'lib/falcon/server.rb', line 50

def accept_count
  @accept_count
end

#connect_countObject (readonly)

Returns the value of attribute connect_count.



51
52
53
# File 'lib/falcon/server.rb', line 51

def connect_count
  @connect_count
end

#request_countObject (readonly)

Returns the value of attribute request_count.



49
50
51
# File 'lib/falcon/server.rb', line 49

def request_count
  @request_count
end

Class Method Details

.middleware(rack_app, verbose: false, cache: true) ⇒ Object

Wrap a rack application into a middleware suitable the server.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/falcon/server.rb', line 22

def self.middleware(rack_app, verbose: false, cache: true)
	::Protocol::HTTP::Middleware.build do
		if verbose
			use Middleware::Verbose
		end
		
		if cache
			use Async::HTTP::Cache::General
		end
		
		use ::Protocol::HTTP::ContentEncoding
		
		use ::Protocol::Rack::Adapter
		run rack_app
	end
end

Instance Method Details

#acceptObject



53
54
55
56
57
58
59
60
# File 'lib/falcon/server.rb', line 53

def accept(...)
	@accept_count += 1
	@connection_count += 1
	
	super
ensure
	@connection_count -= 1
end

#callObject



62
63
64
65
66
67
68
69
# File 'lib/falcon/server.rb', line 62

def call(...)
	@request_count += 1
	@active_count += 1
	
	super
ensure
	@active_count -= 1
end

#statistics_stringObject

Generates a human-readable string representing the current statistics.

e.g. ‘C=23/3.42K R=2/3.42K L=0.273`

This can be interpreted as:

  • ‘C=23/3.42K` - The number of connections currently open and the total number of connections accepted.

  • ‘R=2/3.42K` - The number of requests currently being processed and the total number of requests received.

  • ‘L=0.273` - The average scheduler load of the server, where 0.0 is idle and 1.0 is fully loaded.



82
83
84
# File 'lib/falcon/server.rb', line 82

def statistics_string
	"C=#{format_count @connection_count}/#{format_count @accept_count} R=#{format_count @active_count}/#{format_count @request_count}"
end