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_or_actor_class, *arguments, &block) ⇒ Object



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

def self.call actor_or_actor_class, *arguments, &block
  if actor_or_actor_class.is_a? Actor and not actor_or_actor_class.is_a? Class
    actor = actor_or_actor_class
  else
    actor = Build.(actor_or_actor_class, *arguments, &block)
  end

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

Instance Method Details

#actor_crashed(error) ⇒ Object



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

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

#actor_startedObject



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

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

#actor_stoppedObject



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

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

#addressObject



57
58
59
# File 'lib/actor/start.rb', line 57

def address
  actor.address
end

#callObject



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

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