Class: Evesync::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/evesync/watcher.rb,
lib/evesync/watcher/file.rb,
lib/evesync/watcher/package.rb,
lib/evesync/watcher/interface.rb

Overview

Watcher class responds for starting all watchers (e.g. package and file). Watchers are initialized in their own threads. Watcher::Main supports start/stop methods or starting and stopping watchers.

Example:

w = Evesync::Watcher.new
w.start # so, all needful watchers are started

TODO:

* Add ability to restart watchers if something happend

Defined Under Namespace

Classes: File, Interface

Constant Summary collapse

WATCHER_CLASSES =
[
  Watcher::Package,
  Watcher::File
].freeze
Package =

Package class is a reference to Distro::PackageWatcher

Evesync::OS::PackageWatcher

Instance Method Summary collapse

Constructor Details

#initialize(queue) ⇒ Watcher

Returns a new instance of Watcher.



28
29
30
31
32
33
34
35
36
37
# File 'lib/evesync/watcher.rb', line 28

def initialize(queue)
  # Creating subwatchers
  Log.debug('Watcher initialization started...')
  @queue = queue
  @watchers = []
  WATCHER_CLASSES.each do |w_class|
    @watchers << w_class.new(@queue)
  end
  Log.debug('Watcher initialization done!')
end

Instance Method Details

#startObject

Starts watchers threads

Returns

self



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/evesync/watcher.rb', line 42

def start
  @threads ||= []
  if @threads.empty?
    @watchers.each do |watcher|
      @threads << watcher.start
    end
  end

  Log.debug('Watcher thread started')
  self
end

#stopObject

Stops all watcher threads

Returns

self



57
58
59
60
61
62
63
64
65
# File 'lib/evesync/watcher.rb', line 57

def stop
  @watchers.each do |watcher|
    @threads << watcher.stop
  end
  @threads.each(&:exit)

  Log.debug('Watcher threads stopped')
  self
end