Class: Jp::Server::InstrumentedServer
- Inherits:
-
Server
show all
- Defined in:
- lib/rb/jp/server/instrumented_server.rb
Instance Attribute Summary
Attributes inherited from Handler
#retry_attempts, #retry_delay
#database
Instance Method Summary
collapse
Methods inherited from Server
#aliveSince, #getCounter, #getCpuProfile, #getName, #getOption, #getOptions, #getStatus, #getStatusDetails, #getVersion, #reinitialize, #setOption, #shutdown
Methods inherited from Handler
#rescue_connection_failure
#connect_to_mongo
Constructor Details
Returns a new instance of InstrumentedServer.
6
7
8
9
10
11
12
13
14
|
# File 'lib/rb/jp/server/instrumented_server.rb', line 6
def initialize options = {}
options[:jp_server] ||= Jp::Server::Server.new options.merge(thrift_processor: JobPoolInstrumented::Processor.new(self))
@server = options[:jp_server]
@pools = options[:pools].keys
@add_count = Hash.new 0
@acquire_count = Hash.new 0
@purge_count = Hash.new 0
@empty_count = Hash.new 0
end
|
Instance Method Details
#acquire(pool) ⇒ Object
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/rb/jp/server/instrumented_server.rb', line 58
def acquire pool
begin
result = @server.acquire pool
@acquire_count[pool] += 1
rescue EmptyPool => e
@empty_count[pool] += 1
raise e
end
result
end
|
#acquire_count(pool) ⇒ Object
31
32
33
34
|
# File 'lib/rb/jp/server/instrumented_server.rb', line 31
def acquire_count pool
raise Jp::NoSuchPool.new unless @pools.include? pool
@acquire_count[pool]
end
|
#add(pool, message) ⇒ Object
52
53
54
55
56
|
# File 'lib/rb/jp/server/instrumented_server.rb', line 52
def add pool, message
result = @server.add pool, message
@add_count[pool] += 1
result
end
|
#add_count(pool) ⇒ Object
26
27
28
29
|
# File 'lib/rb/jp/server/instrumented_server.rb', line 26
def add_count pool
raise Jp::NoSuchPool.new unless @pools.include? pool
@add_count[pool]
end
|
#empty_count(pool) ⇒ Object
36
37
38
39
|
# File 'lib/rb/jp/server/instrumented_server.rb', line 36
def empty_count pool
raise Jp::NoSuchPool.new unless @pools.include? pool
@empty_count[pool]
end
|
#getCounters ⇒ Object
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/rb/jp/server/instrumented_server.rb', line 75
def getCounters
counters = Hash.new
pools.each do |pool|
counters["#{pool}.added"] = add_count(pool)
counters["#{pool}.acquired"] = acquire_count(pool)
counters["#{pool}.empty"] = empty_count(pool)
counters["#{pool}.purged"] = purge_count(pool)
end
counters
end
|
#pools ⇒ Object
22
23
24
|
# File 'lib/rb/jp/server/instrumented_server.rb', line 22
def pools
@pools
end
|
#purge(pool, id) ⇒ Object
69
70
71
72
73
|
# File 'lib/rb/jp/server/instrumented_server.rb', line 69
def purge pool, id
result = @server.purge pool, id
@purge_count[pool] += 1
result
end
|
#purge_count(pool) ⇒ Object
41
42
43
44
|
# File 'lib/rb/jp/server/instrumented_server.rb', line 41
def purge_count pool
raise Jp::NoSuchPool.new unless @pools.include? pool
@purge_count[pool]
end
|
#serve ⇒ Object
48
49
50
|
# File 'lib/rb/jp/server/instrumented_server.rb', line 48
def serve
@server.serve
end
|
#start_time ⇒ Object
18
19
20
|
# File 'lib/rb/jp/server/instrumented_server.rb', line 18
def start_time
@server.aliveSince
end
|