Class: ProxyMachine
- Inherits:
-
Object
show all
- Defined in:
- lib/proxymachine.rb,
lib/proxymachine/client_connection.rb,
lib/proxymachine/server_connection.rb
Defined Under Namespace
Classes: ClientConnection, ServerConnection
Constant Summary
collapse
- MAX_FAST_SHUTDOWN_SECONDS =
10
- VERSION =
self.version
Class Method Summary
collapse
Class Method Details
.connect_error_callback ⇒ Object
77
78
79
|
# File 'lib/proxymachine.rb', line 77
def self.connect_error_callback
@@connect_error_callback
end
|
.count ⇒ Object
22
23
24
|
# File 'lib/proxymachine.rb', line 22
def self.count
@@counter
end
|
.decr ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/proxymachine.rb', line 34
def self.decr
@@counter -= 1
if $server.nil?
LOGGER.info "Waiting for #{@@counter} connections to finish."
end
self.update_procline
EM.stop if $server.nil? and @@counter == 0
@@counter
end
|
.fast_shutdown(signal) ⇒ Object
.graceful_shutdown(signal) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/proxymachine.rb', line 52
def self.graceful_shutdown(signal)
EM.stop_server($server) if $server
LOGGER.info "Received #{signal} signal. No longer accepting new connections."
LOGGER.info "Waiting for #{ProxyMachine.count} connections to finish."
$server = nil
EM.stop if ProxyMachine.count == 0
end
|
.inactivity_error_callback ⇒ Object
85
86
87
|
# File 'lib/proxymachine.rb', line 85
def self.inactivity_error_callback
@@inactivity_error_callback
end
|
.incr ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/proxymachine.rb', line 26
def self.incr
@@totalcounter += 1
@@counter += 1
@@maxcounter = @@counter if @@counter > @@maxcounter
self.update_procline
@@counter
end
|
.router ⇒ Object
48
49
50
|
# File 'lib/proxymachine.rb', line 48
def self.router
@@router
end
|
.run(name, host, port) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/proxymachine.rb', line 89
def self.run(name, host, port)
@@totalcounter = 0
@@maxcounter = 0
@@counter = 0
@@name = name
@@listen = "#{host}:#{port}"
@@connect_error_callback ||= proc { |remote| }
@@inactivity_error_callback ||= proc { |remote| }
self.update_procline
EM.epoll
EM.run do
ProxyMachine::ClientConnection.start(host, port)
trap('QUIT') do
self.graceful_shutdown('QUIT')
end
trap('TERM') do
self.fast_shutdown('TERM')
end
trap('INT') do
self.fast_shutdown('INT')
end
end
end
|
.set_connect_error_callback(&block) ⇒ Object
73
74
75
|
# File 'lib/proxymachine.rb', line 73
def self.set_connect_error_callback(&block)
@@connect_error_callback = block
end
|
.set_inactivity_error_callback(&block) ⇒ Object
81
82
83
|
# File 'lib/proxymachine.rb', line 81
def self.set_inactivity_error_callback(&block)
@@inactivity_error_callback = block
end
|
.set_router(block) ⇒ Object
44
45
46
|
# File 'lib/proxymachine.rb', line 44
def self.set_router(block)
@@router = block
end
|
.stats ⇒ Object
18
19
20
|
# File 'lib/proxymachine.rb', line 18
def self.stats
"#{@@counter}/#{@@maxcounter}/#{@@totalcounter}"
end
|
.update_procline ⇒ Object
14
15
16
|
# File 'lib/proxymachine.rb', line 14
def self.update_procline
$0 = "proxymachine #{VERSION} - #{@@name} #{@@listen} - #{self.stats} cur/max/tot conns"
end
|
.version ⇒ Object
114
115
116
117
118
119
|
# File 'lib/proxymachine.rb', line 114
def self.version
yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
"#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
rescue
'unknown'
end
|