Class: WideReceiver::Master
- Inherits:
-
Object
- Object
- WideReceiver::Master
- Defined in:
- lib/wide_receiver/master.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
-
#initialize(registry: Registry.instance, adapter: Config.instance.adapter) ⇒ Master
constructor
A new instance of Master.
- #start ⇒ Object
- #stop ⇒ Object
- #thread_count ⇒ Object
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
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
9 10 11 |
# File 'lib/wide_receiver/master.rb', line 9 def adapter @adapter end |
#registry ⇒ Object (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
#start ⇒ Object
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 |
#stop ⇒ Object
27 28 29 |
# File 'lib/wide_receiver/master.rb', line 27 def stop @threads.each { |t| Thread.kill(t) } end |
#thread_count ⇒ Object
31 32 33 |
# File 'lib/wide_receiver/master.rb', line 31 def thread_count @threads.size end |