Class: Concurrent::Actor::Root

Inherits:
AbstractContext show all
Defined in:
lib/concurrent-ruby-edge/concurrent/actor/root.rb

Overview

implements the root actor

Instance Attribute Summary

Attributes inherited from AbstractContext

#core

Instance Method Summary collapse

Methods inherited from AbstractContext

#ask, #default_executor, #default_reference_class, #envelope, #on_envelope, #on_event, #pass, spawn, spawn!, #tell

Methods included from InternalDelegations

#behaviour, #behaviour!, #children, #context, #log, #redirect, #terminate!, #terminated?

Methods included from PublicDelegations

#context_class, #executor, #name, #parent, #path, #reference

Methods included from TypeCheck

#Child!, #Child?, #Match!, #Match?, #Type!, #Type?

Constructor Details

#initializeRoot

Returns a new instance of Root.



9
10
11
12
13
14
15
# File 'lib/concurrent-ruby-edge/concurrent/actor/root.rb', line 9

def initialize
  # noinspection RubyArgCount
  @dead_letter_router = Core.new(parent:    reference,
                                 class:     DefaultDeadLetterHandler,
                                 supervise: true,
                                 name:      :default_dead_letter_handler).reference
end

Instance Method Details

#behaviour_definitionObject



33
34
35
36
37
# File 'lib/concurrent-ruby-edge/concurrent/actor/root.rb', line 33

def behaviour_definition
  [*Behaviour.base(:just_log),
   *Behaviour.supervising,
   *Behaviour.user_messages]
end

#dead_letter_routingObject



29
30
31
# File 'lib/concurrent-ruby-edge/concurrent/actor/root.rb', line 29

def dead_letter_routing
  @dead_letter_router
end

#on_message(message) ⇒ Object

to allow spawning of new actors, spawn needs to be called inside the parent Actor



18
19
20
21
22
23
24
25
26
27
# File 'lib/concurrent-ruby-edge/concurrent/actor/root.rb', line 18

def on_message(message)
  case
  when message.is_a?(::Array) && message.first == :spawn
    Actor.spawn message[1], &message[2]
  when message == :dead_letter_routing
    @dead_letter_router
  else
    # ignore
  end
end