Sha256: 2eda94c8d11e2f3c862f6ddd47ea9c0fd45dd2af2b9e2d14b8a9ba54a75aaaac

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

module Pione
  module Command
    # PioneBroker is a command for starting a PIONE broker agent. Brokers
    # provides task processing ability to the system.
    class PioneBroker < DaemonProcess
      define_info do
        set_name "pione-broker"
        set_tail {|cmd| "{TaskWorker: %s}" % cmd.option[:task_worker]}
        set_banner "Run broker agent to launch task workers."
      end

      define_option do
        use Option::TupleSpaceReceiverOption
        use Option::TaskWorkerOwnerOption

        validate do |data|
          unless data[:task_worker] > 0
            abort("error: no task worker resources")
          end
        end
      end

      attr_reader :broker

      def create_front
        Front::BrokerFront.new(self)
      end

      prepare do
        @broker = Pione::Agent[:broker].new(
          option[:features],
          task_worker_resource: option[:task_worker]
        )
        @tuple_space_receiver = Pione::TupleSpaceReceiver.instance
      end

      start do
        # start broker agent
        @broker.start

        # start tuple space receiver with the broker agent
        @tuple_space_receiver.register(@broker)

        # wait
        begin
          DRb.thread.join
        rescue DRb::ReplyReaderThreadError
          retry
        end
      end

      terminate do
        @broker.terminate
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pione-0.2.0 lib/pione/command/pione-broker.rb
pione-0.1.4 lib/pione/command/pione-broker.rb
pione-0.1.3 lib/pione/command/pione-broker.rb