Sha256: 7b13c0e05cc40fd55e655cc879795dfcaa4bc01bad2320cce1d3e2001f3251cc

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require 'concurrent/actor/context'
require 'concurrent/actor/core'

module Concurrent
  module Actor
    # implements the root actor
    class Root < AbstractContext

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

      # to allow spawning of new actors, spawn needs to be called inside the parent Actor
      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

      def dead_letter_routing
        @dead_letter_router
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
concurrent-ruby-edge-0.7.2 lib/concurrent-ruby-edge/concurrent/actor/root.rb
concurrent-ruby-edge-0.7.1 lib/concurrent-ruby-edge/concurrent/actor/root.rb
concurrent-ruby-edge-0.7.0 lib/concurrent-ruby-edge/concurrent/actor/root.rb