File: abstract.rb

package info (click to toggle)
ruby-concurrent 1.1.6%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 30,284 kB
  • sloc: ruby: 30,875; java: 6,117; ansic: 288; makefile: 9; sh: 6
file content (50 lines) | stat: -rw-r--r-- 1,428 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'concurrent/concern/logging'

module Concurrent
  module Actor
    module Behaviour
      class Abstract
        include TypeCheck
        include InternalDelegations

        attr_reader :core, :subsequent

        def initialize(core, subsequent, core_options)
          @core       = Type! core, Core
          @subsequent = Type! subsequent, Abstract, NilClass
        end

        # override to add extra behaviour
        # @note super needs to be called not to break the chain
        def on_envelope(envelope)
          pass envelope
        end

        # @param [Envelope] envelope to pass to {#subsequent} behaviour
        def pass(envelope)
          subsequent.on_envelope envelope
        end

        # override to add extra behaviour
        # @note super needs to be called not to break the chain
        def on_event(public, event)
          subsequent.on_event public, event if subsequent
        end

        # broadcasts event to all behaviours and context
        # @see #on_event
        # @see AbstractContext#on_event
        def broadcast(public, event)
          core.broadcast(public, event)
        end

        def reject_envelope(envelope)
          envelope.reject! ActorTerminated.new(reference)
          dead_letter_routing << envelope unless envelope.future
          log(DEBUG) { "rejected #{envelope.message} from #{envelope.sender_path}"}
        end
      end
    end
  end
end