Class: Actor::Supervisor

Inherits:
Object
  • Object
show all
Includes:
Messaging::Publish::Dependency, Module::Dependencies, Module::Handler, Module::RunLoop, Observable
Defined in:
lib/actor/supervisor.rb,
lib/actor/supervisor/observer.rb,
lib/actor/supervisor/assertions.rb,
lib/actor/supervisor/address/get.rb,
lib/actor/supervisor/address/put.rb,
lib/actor/supervisor/address/registry.rb

Defined Under Namespace

Modules: Address, Assertions, Observer

Constant Summary collapse

NoActorsStarted =
Class.new StandardError

Instance Attribute Summary collapse

Attributes included from Messaging::Publish::Dependency

#publish

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Module::RunLoop

#handle_stop, #run_loop

Methods included from Module::Handler

included

Methods included from Module::Dependencies

included

Constructor Details

#initializeSupervisor

Returns a new instance of Supervisor.



16
17
18
# File 'lib/actor/supervisor.rb', line 16

def initialize
  @actor_count = 0
end

Instance Attribute Details

#actor_countObject

Returns the value of attribute actor_count.



11
12
13
# File 'lib/actor/supervisor.rb', line 11

def actor_count
  @actor_count
end

#assembly_blockObject



109
110
111
# File 'lib/actor/supervisor.rb', line 109

def assembly_block
  @assembly_block ||= proc { }
end

#errorObject

Returns the value of attribute error.



13
14
15
# File 'lib/actor/supervisor.rb', line 13

def error
  @error
end

#thread_groupObject



113
114
115
# File 'lib/actor/supervisor.rb', line 113

def thread_group
  @thread_group ||= ThreadGroup::Default
end

Class Method Details

.build(&assembly_block) ⇒ Object



20
21
22
23
24
25
# File 'lib/actor/supervisor.rb', line 20

def self.build &assembly_block
  instance = new
  instance.assembly_block = assembly_block
  instance.configure
  instance
end

.start(&assembly_block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/actor/supervisor.rb', line 27

def self.start &assembly_block
  thread = Thread.new do
    thread_group = Thread.current.group

    instance = build &assembly_block
    instance.run_loop
  end

  loop do
    ten_seconds = 10

    result = thread.join ten_seconds

    break unless result.nil?
  end
end

Instance Method Details

#configureObject



44
45
46
47
48
49
50
51
52
# File 'lib/actor/supervisor.rb', line 44

def configure
  self.thread_group = Thread.current.group

  Address::Put.(address)

  assembly_block.(self)

  self.publish = Messaging::Publish.build
end

#handle(message) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/actor/supervisor.rb', line 54

def handle message
  result = super

  changed
  notify_observers message

  result
end