Class: RabbitCage
- Inherits:
-
Object
show all
- Defined in:
- lib/rabbitcage.rb,
lib/rabbitcage/filter.rb,
lib/rabbitcage/client_connection.rb,
lib/rabbitcage/server_connection.rb
Defined Under Namespace
Classes: ClientConnection, Filter, ServerConnection
Constant Summary
collapse
- MAX_FAST_SHUTDOWN_SECONDS =
10
- VERSION =
self.version
Class Method Summary
collapse
Class Method Details
.config ⇒ Object
52
53
54
|
# File 'lib/rabbitcage.rb', line 52
def config
@@config
end
|
.count ⇒ Object
26
27
28
|
# File 'lib/rabbitcage.rb', line 26
def count
@@counter
end
|
.decr ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/rabbitcage.rb', line 38
def 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
.filter(frame) ⇒ Object
68
69
70
|
# File 'lib/rabbitcage.rb', line 68
def filter frame
Filter.filter frame
end
|
.graceful_shutdown(signal) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/rabbitcage.rb', line 72
def graceful_shutdown(signal)
EM.stop_server($server) if $server
LOGGER.info "Received #{signal} signal. No longer accepting new connections."
LOGGER.info "Waiting for #{RabbitCage.count} connections to finish."
$server = nil
EM.stop if RabbitCage.count == 0
end
|
.incr ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/rabbitcage.rb', line 30
def incr
@@totalcounter += 1
@@counter += 1
@@maxcounter = @@counter if @@counter > @@maxcounter
self.update_procline
@@counter
end
|
.rabbit_host ⇒ Object
56
57
58
|
# File 'lib/rabbitcage.rb', line 56
def rabbit_host
@@remote_host
end
|
.rabbit_port ⇒ Object
60
61
62
|
# File 'lib/rabbitcage.rb', line 60
def rabbit_port
@@remote_port
end
|
.run(name, host, port, rhost, rport, log_level) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/rabbitcage.rb', line 93
def run(name, host, port, rhost, rport, log_level)
@@totalcounter = 0
@@maxcounter = 0
@@counter = 0
@@name = name
@@listen = "#{host}:#{port}"
@@remote_host = rhost
@@remote_port = rport
LOGGER.level = log_level
self.update_procline
EM.epoll
RabbitCage.build_filter
EM.run do
RabbitCage::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_config(block) ⇒ Object
48
49
50
|
# File 'lib/rabbitcage.rb', line 48
def set_config(block)
@@config = block
end
|
.stats ⇒ Object
22
23
24
|
# File 'lib/rabbitcage.rb', line 22
def stats
"#{@@counter}/#{@@maxcounter}/#{@@totalcounter}"
end
|
.update_procline ⇒ Object
18
19
20
|
# File 'lib/rabbitcage.rb', line 18
def update_procline
$0 = "rabbitcage #{VERSION} - #{@@name} #{@@listen} - #{self.stats} cur/max/tot conns"
end
|
.version ⇒ Object
122
123
124
125
126
127
|
# File 'lib/rabbitcage.rb', line 122
def version
yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
"#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
rescue
'unknown'
end
|