Sha256: 5e6b5bcfa49e24963ab4ec018a2f79417a88bb88abf3bf73089d3e61244733d2

Contents?: true

Size: 1.48 KB

Versions: 51

Compression:

Stored size: 1.48 KB

Contents

module Dynflow

  module MethodicActor
    def on_message(message)
      method, *args = message
      self.send(method, *args)
    end
  end

  # Common parent for all the Dynflow actors defining some defaults
  # that we preffer here.
  class Actor < Concurrent::Actor::Context

    include MethodicActor

    # Behaviour that watches for polite asking for termination
    # and calls corresponding method on the context to do so
    class PoliteTermination < Concurrent::Actor::Behaviour::Abstract
      def on_envelope(envelope)
        message, terminated_future = envelope
        if :start_termination == message
          context.start_termination(terminated_future)
          envelope.future.success true if !envelope.future.nil?
          Concurrent::Actor::Behaviour::MESSAGE_PROCESSED
        else
          pass envelope
        end
      end
    end

    include Algebrick::Matching

    def start_termination(future)
      @terminated = future
    end

    def finish_termination
      @terminated.success(true)
      reference.tell(:terminate!)
    end

    def terminating?
      !!@terminated
    end

    def behaviour_definition
      [*Concurrent::Actor::Behaviour.base(:just_log),
       Concurrent::Actor::Behaviour::Buffer,
       [Concurrent::Actor::Behaviour::SetResults, :just_log],
       Concurrent::Actor::Behaviour::Awaits,
       PoliteTermination,
       Concurrent::Actor::Behaviour::ExecutesContext,
       Concurrent::Actor::Behaviour::ErrorsOnUnknownMessage]
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
dynflow-1.1.6 lib/dynflow/actor.rb
dynflow-1.1.5 lib/dynflow/actor.rb
dynflow-1.1.4 lib/dynflow/actor.rb
dynflow-1.1.3 lib/dynflow/actor.rb
dynflow-1.1.2 lib/dynflow/actor.rb
dynflow-1.1.1 lib/dynflow/actor.rb
dynflow-1.1.0 lib/dynflow/actor.rb
dynflow-1.0.5 lib/dynflow/actor.rb
dynflow-1.0.4 lib/dynflow/actor.rb
dynflow-1.0.3 lib/dynflow/actor.rb
dynflow-1.0.2 lib/dynflow/actor.rb
dynflow-1.0.1 lib/dynflow/actor.rb
dynflow-1.0.0 lib/dynflow/actor.rb
dynflow-0.8.37 lib/dynflow/actor.rb
dynflow-0.8.36 lib/dynflow/actor.rb
dynflow-0.8.35 lib/dynflow/actor.rb
dynflow-0.8.34 lib/dynflow/actor.rb
dynflow-0.8.33 lib/dynflow/actor.rb
dynflow-0.8.32 lib/dynflow/actor.rb
dynflow-0.8.31 lib/dynflow/actor.rb