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/address/get.rb,
lib/actor/supervisor/address/put.rb,
lib/actor/supervisor/address/registry.rb

Defined Under Namespace

Modules: Address, 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

#address_configured?, #dependencies_configured?, included, #reader_configured?, #send_configured?

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



123
124
125
# File 'lib/actor/supervisor.rb', line 123

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



127
128
129
# File 'lib/actor/supervisor.rb', line 127

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

Class Method Details

.build(&assembly_block) ⇒ Object



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

def self.build(&assembly_block)
  instance = new
  instance.assembly_block = assembly_block
  instance
end

.start(&assembly_block) ⇒ Object



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

def self.start(&assembly_block)
  Thread.report_on_exception = false

  thread = Thread.new do
    instance = Build.(self, &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



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

def configure
  self.thread_group = Thread.current.group

  Address::Put.(address)

  assembly_block.(self)

  self.publish = Messaging::Publish.build
end

#handle(message) ⇒ Object



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

def handle(message)
  result = super

  changed
  notify_observers(message)

  result
end

#registered_actor?(actor) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/actor/supervisor.rb', line 115

def registered_actor?(actor)
  publish.registered?(actor.address)
end

#unregistered_actor?(actor) ⇒ Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/actor/supervisor.rb', line 119

def unregistered_actor?(actor)
  publish.unregistered?(actor.address)
end