Sha256: 2a6278a928cf251d352d2033422116d9f4beebd8c14d3e002b80f0fcbd700faf

Contents?: true

Size: 1.83 KB

Versions: 20

Compression:

Stored size: 1.83 KB

Contents

module Concurrent
  module Actor
    module Behaviour

      # Allows to pause actors on errors.
      # When paused all arriving messages are collected and processed after the actor
      # is resumed or reset. Resume will simply continue with next message.
      # Reset also reinitialized context.
      # TODO example
      class Pausing < Abstract
        def initialize(core, subsequent)
          super core, subsequent
          @paused = false
          @buffer = []
        end

        def on_envelope(envelope)
          case envelope.message
          when :pause!
            pause!
          when :resume!
            resume!
          when :reset!
            reset!
          when :restart!
            restart!
          else
            if @paused
              @buffer << envelope
              MESSAGE_PROCESSED
            else
              pass envelope
            end
          end
        end

        def pause!(error = nil)
          @paused = true
          broadcast(error || :paused)
          true
        end

        def resume!(broadcast = true)
          @paused = false
          broadcast(:resumed) if broadcast
          true
        end

        def reset!(broadcast = true)
          core.allocate_context
          core.build_context
          resume!(false)
          broadcast(:reset) if broadcast
          true
        end

        def restart!
          reset! false
          broadcast(:restarted)
          true
        end

        def on_event(event)
          case event
          when :terminated, :restarted
            @buffer.each { |envelope| reject_envelope envelope }
            @buffer.clear
          when :resumed, :reset
            @buffer.each { |envelope| core.schedule_execution { pass envelope } }
            @buffer.clear
          end
          super event
        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/pausing.rb
concurrent-ruby-0.8.0-java lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.2 lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.2-x86_64-linux lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.2-x86-solaris-2.11 lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.2-x86-mingw32 lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.2-x86-linux lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.2-x64-mingw32 lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.2-java lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.8.0.pre2 lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.8.0.pre2-java lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.8.0.pre1 lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.8.0.pre1-java lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.1 lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.1-x86_64-linux lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.1-x86-solaris-2.11 lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.1-x86-mingw32 lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.1-x86-linux lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.1-x64-mingw32 lib/concurrent/actor/behaviour/pausing.rb
concurrent-ruby-0.7.1-java lib/concurrent/actor/behaviour/pausing.rb