class DbSucker::Application::SklavenTreiber::Worker::IO::Throughput
Constants
- InstanceAlreadyRegisteredError
Attributes
sklaventreiber[R]
stats[R]
Public Class Methods
new(sklaventreiber)
click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 11 def initialize sklaventreiber @sklaventreiber = sklaventreiber @instances = {} @stats = {} @monitor = Monitor.new @polling = [] end
Public Instance Methods
app()
click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 19 def app sklaventreiber.app end
commit!(bytes, *categories)
click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 57 def commit! bytes, *categories sync do return unless bytes categories.flatten.each do |cat| @stats[cat] ||= 0 @stats[cat] += bytes end end end
nopoll!(instance)
click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 31 def nopoll! instance sync { @polling.delete(instance) } end
poll!(instance)
click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 27 def poll! instance sync { @polling.push(instance) } end
register(target)
click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 67 def register target sync do if @instances[target.object_id] raise InstanceAlreadyRegisteredError, "throughput manager cannot register more than once on the same target: `#{target}'" else raise NotImplementedError, "throughput manager requires the target to respond_to?(:filesize)" unless target.respond_to?(:filesize) raise NotImplementedError, "throughput manager requires the target to respond_to?(:offset)" unless target.respond_to?(:offset) @instances[target.object_id] = Instance.new(self, target) end end end
start_loop()
click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 35 def start_loop @poll = app.spawn_thread(:sklaventreiber_throughput) do |thr| thr[:polling] = 0 loop do sync { thr[:polling] = @polling.length @polling.each(&:ping) } break if thr[:stop] thr.wait(0.1) end end end
stop_loop()
click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 49 def stop_loop sync do return unless @poll @poll[:stop] = true end @poll.signal.join end
sync(&block)
click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 23 def sync &block @monitor.synchronize(&block) end
unregister(instance)
click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 79 def unregister instance sync do @instances.clone.each do |k, v| if v == instance @instances.delete(k) break end end end end