my_stuff-fb303 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/my_stuff/fb303/proxy_handler.rb +24 -0
- data/lib/my_stuff/fb303/server.rb +82 -0
- metadata +3 -1
@@ -0,0 +1,24 @@
|
|
1
|
+
# Copyright 2011-present Fred Emmott. All Rights Reserved.
|
2
|
+
|
3
|
+
module MyStuff
|
4
|
+
module Fb303
|
5
|
+
class ProxyHandler
|
6
|
+
def initialize server
|
7
|
+
@s = server
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing meth, *args
|
11
|
+
@s.increment_counter "#{meth}.called"
|
12
|
+
begin
|
13
|
+
result = @s.send(meth, *args)
|
14
|
+
@s.increment_counter "#{meth}.success"
|
15
|
+
result
|
16
|
+
rescue => e
|
17
|
+
@s.increment_counter "#{meth}.exception"
|
18
|
+
@s.increment_counter "#{meth}.exception.#{e.class.name}"
|
19
|
+
raise
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Copyright 2011-present Fred Emmott. All Rights Reserved.
|
2
|
+
|
3
|
+
require 'my_stuff/fb303/proxy_handler'
|
4
|
+
|
5
|
+
# Code used for MyStuff.ws
|
6
|
+
module MyStuff
|
7
|
+
module Fb303
|
8
|
+
class Server
|
9
|
+
def initialize interface, name, version = ''
|
10
|
+
@name = name
|
11
|
+
@version = version
|
12
|
+
@interface = interface
|
13
|
+
|
14
|
+
@status = Fb_status::STARTING
|
15
|
+
@status_details = ''
|
16
|
+
@started_at = Time.new.to_i
|
17
|
+
@counters = Hash.new(0)
|
18
|
+
|
19
|
+
start_fb303_server
|
20
|
+
end
|
21
|
+
|
22
|
+
def run!
|
23
|
+
@status = Fb_status::ALIVE
|
24
|
+
@server_thread.join
|
25
|
+
end
|
26
|
+
|
27
|
+
##### fb303 implementation #####
|
28
|
+
|
29
|
+
def getName; @name; end
|
30
|
+
def getVersion; @version; end
|
31
|
+
def getStatus; @status; end
|
32
|
+
def getStatusDetails; @status_details; end
|
33
|
+
def aliveSince; @started_at; end
|
34
|
+
def getCounters; @counters; end
|
35
|
+
def getCounter key; @counters[key]; end
|
36
|
+
def getOption key; ''; end
|
37
|
+
def getOptions; {}; end
|
38
|
+
def getCpuProfile duration; ''; end
|
39
|
+
def setOption key, value; end
|
40
|
+
def reinitialize; raise NotImplementedError.new; end
|
41
|
+
|
42
|
+
def shutdown
|
43
|
+
@status = Fb_status::STOPPING
|
44
|
+
@status_details = 'Shutdown requested via fb303'
|
45
|
+
@fb303_thread.kill
|
46
|
+
@status = Fb_status::STOPPED
|
47
|
+
end
|
48
|
+
|
49
|
+
def increment_counter name
|
50
|
+
@counters[name] += 1
|
51
|
+
end
|
52
|
+
|
53
|
+
def method_missing *args
|
54
|
+
if self.handler != self
|
55
|
+
self.handler.send *args
|
56
|
+
else
|
57
|
+
super *args
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def handler
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
|
67
|
+
def server_for processor
|
68
|
+
raise NotImplementedError.new
|
69
|
+
end
|
70
|
+
|
71
|
+
def start_fb303_server
|
72
|
+
handler = MyStuff::Fb303::ProxyHandler.new(self)
|
73
|
+
processor = @interface.const_get(:Processor).new(handler)
|
74
|
+
@server = server_for(processor)
|
75
|
+
|
76
|
+
@server_thread = Thread.new do
|
77
|
+
@server.serve
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: my_stuff-fb303
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Fred Emmott
|
@@ -24,6 +24,8 @@ extra_rdoc_files: []
|
|
24
24
|
|
25
25
|
files:
|
26
26
|
- lib/my_stuff/fb303_server.rb
|
27
|
+
- lib/my_stuff/fb303/proxy_handler.rb
|
28
|
+
- lib/my_stuff/fb303/server.rb
|
27
29
|
homepage: https://github.com/fredemmott/my_stuff-fb303
|
28
30
|
licenses: []
|
29
31
|
|