Class: Actor::Start

Inherits:
Object
  • Object
show all
Includes:
Messaging::Send::Dependency
Defined in:
lib/actor/start.rb

Instance Attribute Summary collapse

Attributes included from Messaging::Send::Dependency

#send

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actor) ⇒ Start

Returns a new instance of Start.



8
9
10
# File 'lib/actor/start.rb', line 8

def initialize actor
  @actor = actor
end

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.



5
6
7
# File 'lib/actor/start.rb', line 5

def actor
  @actor
end

#supervisor_addressObject

Returns the value of attribute supervisor_address.



6
7
8
# File 'lib/actor/start.rb', line 6

def supervisor_address
  @supervisor_address
end

Class Method Details

.call(actor_class, *arguments, &block) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/actor/start.rb', line 12

def self.call actor_class, *arguments, &block
  actor = Build.(actor_class, *arguments, &block)

  instance = new actor
  instance.send = Messaging::Send.new
  instance.supervisor_address = Supervisor::Address::Get.()
  instance.()
end

Instance Method Details

#actor_crashed(error) ⇒ Object



38
39
40
41
# File 'lib/actor/start.rb', line 38

def actor_crashed error
  actor_crashed = Messages::ActorCrashed.new error
  send.(actor_crashed, supervisor_address)
end

#actor_startedObject



43
44
45
46
# File 'lib/actor/start.rb', line 43

def actor_started
  actor_started = Messages::ActorStarted.new address
  send.(actor_started, supervisor_address)
end

#actor_stoppedObject



48
49
50
51
# File 'lib/actor/start.rb', line 48

def actor_stopped
  actor_stopped = Messages::ActorStopped.new address
  send.(actor_stopped, supervisor_address)
end

#addressObject



53
54
55
# File 'lib/actor/start.rb', line 53

def address
  actor.address
end

#callObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/actor/start.rb', line 21

def call
  send.(Messages::Start, address)

  thread = Thread.new do
    actor_started

    begin
      actor.run_loop
      actor_stopped
    rescue => error
      actor_crashed error
    end
  end

  return actor, thread
end