my_stuff-fb303 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/my_stuff/fb303_server.rb +70 -0
  2. metadata +4 -4
@@ -0,0 +1,70 @@
1
+ # Copyright 2011-present Fred Emmott. All Rights Reserved.
2
+
3
+ # Code used for MyStuff.ws
4
+ module MyStuff
5
+ # Ruby implementation of Facebook's fb303 interface.
6
+ class Fb303Server
7
+ def initialize interface, name, version = ''
8
+ @name = name
9
+ @version = version
10
+ @interface = interface
11
+
12
+ @status = Fb_status::STARTING
13
+ @status_details = ''
14
+ @started_at = Time.new.to_i
15
+ @counters = Hash.new(0)
16
+
17
+ start_fb303_server
18
+ end
19
+
20
+ def run!
21
+ @status = Fb_status::ALIVE
22
+ @server_thread.join
23
+ end
24
+
25
+ ##### fb303 implementation #####
26
+
27
+ def getName; @name; end
28
+ def getVersion; @version; end
29
+ def getStatus; @status; end
30
+ def getStatusDetails; @status_details; end
31
+ def aliveSince; @started_at; end
32
+ def getCounters; @counters; end
33
+ def getCounter key; @counters[key]; end
34
+ def getOption key; ''; end
35
+ def getOptions; {}; end
36
+ def getCpuProfile duration; ''; end
37
+ def setOption key, value; end
38
+ def reinitialize; raise NotImplementedError.new; end
39
+
40
+ def shutdown
41
+ @status = Fb_status::STOPPING
42
+ @status_details = 'Shutdown requested via fb303'
43
+ @fb303_thread.kill
44
+ @status = Fb_status::STOPPED
45
+ end
46
+
47
+ def increment_counter name
48
+ @counters[name] += 1
49
+ end
50
+
51
+ protected
52
+
53
+ def server_for processor
54
+ raise NotImplementedError.new
55
+ end
56
+
57
+ def handler
58
+ self
59
+ end
60
+
61
+ def start_fb303_server
62
+ processor = @interface.const_get(:Processor).new(handler)
63
+ @server = server_for(processor)
64
+
65
+ @server_thread = Thread.new do
66
+ @server.serve
67
+ end
68
+ end
69
+ end
70
+ 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.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Fred Emmott
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-14 00:00:00 Z
13
+ date: 2011-08-15 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: Basic implementation of fb303 for Ruby services
@@ -22,8 +22,8 @@ extensions: []
22
22
 
23
23
  extra_rdoc_files: []
24
24
 
25
- files: []
26
-
25
+ files:
26
+ - lib/my_stuff/fb303_server.rb
27
27
  homepage: https://github.com/fredemmott/my_stuff-fb303
28
28
  licenses: []
29
29