Class: WideReceiver::Master

Inherits:
Object
  • Object
show all
Defined in:
lib/wide_receiver/master.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry: Registry.instance, adapter: Config.instance.adapter) ⇒ Master

Returns a new instance of Master.



11
12
13
14
15
# File 'lib/wide_receiver/master.rb', line 11

def initialize(registry: Registry.instance, adapter: Config.instance.adapter)
  @adapter  = adapter
  @registry = registry
  @threads  = []
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



9
10
11
# File 'lib/wide_receiver/master.rb', line 9

def adapter
  @adapter
end

#registryObject (readonly)

Returns the value of attribute registry.



9
10
11
# File 'lib/wide_receiver/master.rb', line 9

def registry
  @registry
end

Instance Method Details

#startObject



17
18
19
20
21
22
23
24
25
# File 'lib/wide_receiver/master.rb', line 17

def start
  registry.channels.each do |channel|
    workers = registry[channel]

    @threads << Thread.new do
      adapter.new(channel, workers).work
    end
  end
end

#stopObject



27
28
29
# File 'lib/wide_receiver/master.rb', line 27

def stop
  @threads.each { |t| Thread.kill(t) }
end

#thread_countObject



31
32
33
# File 'lib/wide_receiver/master.rb', line 31

def thread_count
  @threads.size
end