Module: ShareDataWatcher::InstanceMethods

Included in:
ShareDataWatcher
Defined in:
lib/share-data-watcher/instance_methods.rb

Overview

Instance Methods For Shard Data Watcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#endpointsObject (readonly)

Returns the value of attribute endpoints.



6
7
8
# File 'lib/share-data-watcher/instance_methods.rb', line 6

def endpoints
  @endpoints
end

#healthcheck_intervalObject (readonly)

Returns the value of attribute healthcheck_interval.



7
8
9
# File 'lib/share-data-watcher/instance_methods.rb', line 7

def healthcheck_interval
  @healthcheck_interval
end

Instance Method Details

#initialize(endpoints = nil, **opt) ⇒ Object



9
10
11
12
13
14
# File 'lib/share-data-watcher/instance_methods.rb', line 9

def initialize(endpoints = nil, **opt)
  @endpoints = endpoints || DEFAULT_ENDPOINT
  @healthcheck_thread = nil
  @healthcheck_interval = opt[:healthcheck_interval] || DEFAULT_HEALTHCHECK_INTERVAL
  @mutex = Mutex.new
end

#restartObject



28
29
30
31
32
33
# File 'lib/share-data-watcher/instance_methods.rb', line 28

def restart
  shutdown
  start
  setup_healthcheck
  self
end

#shutdownObject



35
36
37
38
39
40
# File 'lib/share-data-watcher/instance_methods.rb', line 35

def shutdown
  types.each_value(&:shutdown)
  types.clear
  @healthcheck_thread.exit
  self
end

#startObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/share-data-watcher/instance_methods.rb', line 16

def start
  @mutex.synchronize do
    self.class.types.each do |type|
      init_type(type)
    end
  end

  until valid?; sleep 1; end
  setup_healthcheck
  self
end

#to_hObject Also known as: to_hash



49
50
51
52
53
# File 'lib/share-data-watcher/instance_methods.rb', line 49

def to_h
  types.each_with_object({}) do |(key, value), result|
    result[key] = value.to_h
  end
end

#valid?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/share-data-watcher/instance_methods.rb', line 42

def valid?
  types.each do |_, value|
    return false unless value.valid?
  end
  true
end