Class: CopyTunerClient::Poller
- Inherits:
-
Object
- Object
- CopyTunerClient::Poller
- Defined in:
- lib/copy_tuner_client/poller.rb
Overview
Starts a background thread that continually resynchronizes with the remote server using the given Cache after a set delay.
Instance Method Summary collapse
-
#initialize(cache, options) ⇒ Poller
constructor
A new instance of Poller.
- #start ⇒ Object
- #start_sync ⇒ Object
- #stop ⇒ Object
- #wait_for_download ⇒ Object
Constructor Details
#initialize(cache, options) ⇒ Poller
Returns a new instance of Poller.
12 13 14 15 16 17 18 19 |
# File 'lib/copy_tuner_client/poller.rb', line 12 def initialize(cache, ) @cache = cache @polling_delay = [:polling_delay] @logger = [:logger] @command_queue = CopyTunerClient::QueueWithTimeout.new @mutex = Mutex.new @thread = nil end |
Instance Method Details
#start ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/copy_tuner_client/poller.rb', line 21 def start @mutex.synchronize do if @thread.nil? @logger.info 'start poller thread' @thread = Thread.new { poll } or logger.error("Couldn't start poller thread") end end end |
#start_sync ⇒ Object
38 39 40 |
# File 'lib/copy_tuner_client/poller.rb', line 38 def start_sync @command_queue.uniq_push(:sync) end |
#stop ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/copy_tuner_client/poller.rb', line 30 def stop @mutex.synchronize do @command_queue.uniq_push(:stop) @thread.join if @thread @thread = nil end end |
#wait_for_download ⇒ Object
42 43 44 |
# File 'lib/copy_tuner_client/poller.rb', line 42 def wait_for_download @cache.wait_for_download end |