Sha256: 15b17547538c6fdb5b37c700124946d8a2014028b494c6b26ab10edf8e1846d4

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

module Pione
  module Agent
    class CommandListener < TupleSpaceClient
      set_agent_type :command_listener

      define_state :waiting_command
      define_state :doing_command

      define_state_transition :initialized => :waiting_command
      define_state_transition :waiting_command => :doing_command
      define_state_transition :doing_command => :waiting_command

      define_exception_handler Exception => :error

      def hello
      end

      def bye
      end

      def initialize(tuple_space_server, target)
        @target = target
        super(tuple_space_server)
      end

      def transit_to_waiting_command
        return read(Tuple[:command].any)
      end

      def transit_to_doing_command(cmd=nil)
        return unless cmd # the case we got null command
        return unless cmd.kind_of?(Tuple::Command)
        case cmd.type
        when "terminate"
          @target.terminate
          terminate
        end
      end

      def transit_to_error(e)
        terminate
      end
    end

    set_agent CommandListener
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pione-0.2.2 lib/pione/agent/command-listener.rb
pione-0.2.1 lib/pione/agent/command-listener.rb
pione-0.2.0 lib/pione/agent/command-listener.rb
pione-0.1.4 lib/pione/agent/command-listener.rb
pione-0.1.3 lib/pione/agent/command-listener.rb
pione-0.1.2 lib/pione/agent/command-listener.rb
pione-0.1.1 lib/pione/agent/command-listener.rb
pione-0.1.0 lib/pione/agent/command-listener.rb