2009-08-30 18:37:24 +00:00
|
|
|
module FSSM::Backends
|
|
|
|
class Polling
|
2009-09-03 05:42:59 +00:00
|
|
|
def initialize(options={})
|
2009-12-16 16:57:16 +00:00
|
|
|
@handlers = []
|
|
|
|
@latency = options[:latency] || 1.5
|
2009-09-03 05:42:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_path(path, preload=true)
|
2009-09-06 05:59:30 +00:00
|
|
|
handler = FSSM::State.new(path)
|
|
|
|
handler.refresh(path.to_pathname, true) if preload
|
|
|
|
@handlers << handler
|
2009-09-03 05:42:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
begin
|
|
|
|
loop do
|
|
|
|
start = Time.now.to_f
|
|
|
|
@handlers.each {|handler| handler.refresh}
|
|
|
|
nap_time = @latency - (Time.now.to_f - start)
|
|
|
|
sleep nap_time if nap_time > 0
|
|
|
|
end
|
|
|
|
rescue Interrupt
|
2009-08-30 18:37:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|