Sha256: e88031ecd7ad49d0918f56ec1924c8c49b3714c91b1931dc74f2e95b97453a85

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

module Pione
  module Agent
    # Messenger is an agent for receiveing message logs.
    class Messenger < TupleSpaceClient
      set_agent_type :messenger, self

      # @param tuple_space [TupleSpace::TupleSpaceServer]
      #   tuple space
      # @param receiver [Log::MessageLogReceiver]
      #   message log receiver
      def initialize(tuple_space, receiver, session_id)
        super(tuple_space)

        # message log receiver
        @receiver = receiver
        @session_id = session_id
      end

      #
      # agent activities
      #

      define_transition :pass

      chain :init => :pass
      chain :pass => :pass

      #
      # transitions
      #

      # Transits to the state `pass`.
      def transit_to_pass
        tuples = take_all(TupleSpace::MessageTuple.any)
        tuples.sort{|a,b| a.timestamp <=> b.timestamp}.each do |tuple|
          tuple.contents.tap do |contents|
            (contents.kind_of?(String) ? [contents] : contents).each do |msg|
              @receiver.receive(msg, tuple.level, tuple.head, tuple.color, @session_id)
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pione-0.5.0 lib/pione/agent/messenger.rb
pione-0.5.0.alpha.2 lib/pione/agent/messenger.rb
pione-0.5.0.alpha.1 lib/pione/agent/messenger.rb
pione-0.4.2 lib/pione/agent/messenger.rb
pione-0.4.1 lib/pione/agent/messenger.rb