Sha256: ce9feb9370c1f838bb86ece290fe1d4ca1afeb619216ad469f5d3a73b4fa1e3c

Contents?: true

Size: 1.45 KB

Versions: 20

Compression:

Stored size: 1.45 KB

Contents

module Concurrent
  module Actor
    module Behaviour

      # Handles actor termination.
      # @note Actor rejects envelopes when terminated.
      class Termination < Abstract

        # @!attribute [r] terminated
        #   @return [Event] event which will become set when actor is terminated.
        attr_reader :terminated

        def initialize(core, subsequent)
          super core, subsequent
          @terminated = Event.new
        end

        # @note Actor rejects envelopes when terminated.
        # @return [true, false] if actor is terminated
        def terminated?
          @terminated.set?
        end

        def on_envelope(envelope)
          case envelope.message
          when :terminated?
            terminated?
          when :terminate!
            terminate!
          when :terminated_event
            terminated
          else
            if terminated?
              reject_envelope envelope
              MESSAGE_PROCESSED
            else
              pass envelope
            end
          end
        end

        # Terminates the actor. Any Envelope received after termination is rejected.
        # Terminates all its children, does not wait until they are terminated.
        def terminate!
          return true if terminated?
          terminated.set
          broadcast(:terminated) # TODO do not end up in Dead Letter Router
          parent << :remove_child if parent
          true
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
concurrent-ruby-0.8.0 lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.8.0-java lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.2 lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.2-x86_64-linux lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.2-x86-solaris-2.11 lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.2-x86-mingw32 lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.2-x86-linux lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.2-x64-mingw32 lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.2-java lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.8.0.pre2 lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.8.0.pre2-java lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.8.0.pre1 lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.8.0.pre1-java lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.1 lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.1-x86_64-linux lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.1-x86-solaris-2.11 lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.1-x86-mingw32 lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.1-x86-linux lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.1-x64-mingw32 lib/concurrent/actor/behaviour/termination.rb
concurrent-ruby-0.7.1-java lib/concurrent/actor/behaviour/termination.rb