Class: Zoidberg::Supervisor
- Inherits:
-
Object
- Object
- Zoidberg::Supervisor
- Includes:
- SoftShell
- Defined in:
- lib/zoidberg/supervisor.rb
Instance Attribute Summary collapse
-
#registry ⇒ Registry
readonly
Current supervision registry.
Instance Method Summary collapse
-
#[](k) ⇒ Object
Fetch the supervised instance or pool.
-
#initialize ⇒ self
constructor
Create a new supervisor.
-
#pool(klass, args = {}, &block) ⇒ Object
Supervise a pool.
-
#supervise_as(name, klass, *args, &block) ⇒ Object
Supervise an instance.
-
#terminate ⇒ Object
Destroy all supervised instances prior to destruction.
Methods included from SoftShell
#_zoidberg_thread, #async, #defer, included, #sleep
Constructor Details
#initialize ⇒ self
Create a new supervisor
14 15 16 |
# File 'lib/zoidberg/supervisor.rb', line 14 def initialize @registry = Registry.new end |
Instance Attribute Details
#registry ⇒ Registry (readonly)
Returns current supervision registry.
9 10 11 |
# File 'lib/zoidberg/supervisor.rb', line 9 def registry @registry end |
Instance Method Details
#[](k) ⇒ Object
Fetch the supervised instance or pool
22 23 24 |
# File 'lib/zoidberg/supervisor.rb', line 22 def [](k) registry[k] end |
#pool(klass, args = {}, &block) ⇒ Object
Supervise a pool
47 48 49 50 51 52 53 54 55 |
# File 'lib/zoidberg/supervisor.rb', line 47 def pool(klass, args={}, &block) name = args[:as] size = args[:size].to_i args = args.fetch(:args, []) klass = supervised_class(klass) s_pool = Pool.new(klass, *args, &block) s_pool._worker_count(size > 0 ? size : 1) registry[name] = s_pool end |
#supervise_as(name, klass, *args, &block) ⇒ Object
Supervise an instance
33 34 35 36 |
# File 'lib/zoidberg/supervisor.rb', line 33 def supervise_as(name, klass, *args, &block) klass = supervised_class(klass) registry[name] = klass.new(*args, &block) end |
#terminate ⇒ Object
Destroy all supervised instances prior to destruction
58 59 60 61 62 |
# File 'lib/zoidberg/supervisor.rb', line 58 def terminate registry.values.each do |item| item._zoidberg_destroy! end end |