Sha256: a346417ef4cb3e0036180214c3a01e5fb071db071e199f6eb80a9873546825e9

Contents?: true

Size: 1.4 KB

Versions: 8

Compression:

Stored size: 1.4 KB

Contents

module Concurrent
  module Actor
    module Behaviour

      # Sets nad holds the supervisor of the actor if any. There is only one or none supervisor
      # for each actor. Each supervisor is automatically linked.
      class Supervised < Abstract
        attr_reader :supervisor

        def initialize(core, subsequent)
          super core, subsequent
          @supervisor = nil
        end

        def on_envelope(envelope)
          case envelope.message
          when :supervise
            supervise envelope.sender
          when :supervisor
            supervisor
          when :un_supervise
            un_supervise envelope.sender
          when :pause!, :resume!, :reset!, :restart!
            # allow only supervisor to control the actor
            if @supervisor == envelope.sender
              pass envelope
            else
              false
            end
          else
            pass envelope
          end
        end

        def supervise(ref)
          @supervisor = ref
          behaviour!(Linking).link ref
          true
        end

        def un_supervise(ref)
          if @supervisor == ref
            behaviour!(Linking).unlink ref
            @supervisor = nil
            true
          else
            false
          end
        end

        def on_event(event)
          @supervisor = nil if event == :terminated
          super event
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
concurrent-ruby-0.7.0.rc2 lib/concurrent/actor/behaviour/supervised.rb
concurrent-ruby-0.7.0.rc2-x86_64-linux lib/concurrent/actor/behaviour/supervised.rb
concurrent-ruby-0.7.0.rc2-x86_64-darwin-13 lib/concurrent/actor/behaviour/supervised.rb
concurrent-ruby-0.7.0.rc2-x86-solaris-2.11 lib/concurrent/actor/behaviour/supervised.rb
concurrent-ruby-0.7.0.rc2-x86-mingw32 lib/concurrent/actor/behaviour/supervised.rb
concurrent-ruby-0.7.0.rc2-x86-linux lib/concurrent/actor/behaviour/supervised.rb
concurrent-ruby-0.7.0.rc2-x64-mingw32 lib/concurrent/actor/behaviour/supervised.rb
concurrent-ruby-0.7.0.rc2-java lib/concurrent/actor/behaviour/supervised.rb