From c8d833d1d35b1c5c446113e76d8cbe97700efbb3 Mon Sep 17 00:00:00 2001 From: Nick Gauthier Date: Fri, 29 Jan 2010 13:32:37 -0500 Subject: [PATCH] included message modules in processor classes so you don't have to namespace them --- lib/hydra/master.rb | 5 +++-- lib/hydra/runner.rb | 7 ++++--- lib/hydra/worker.rb | 11 ++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/hydra/master.rb b/lib/hydra/master.rb index f82033a..7da0187 100644 --- a/lib/hydra/master.rb +++ b/lib/hydra/master.rb @@ -3,6 +3,7 @@ module Hydra #:nodoc: # # The Master is run once for any given testing session. class Master + include Hydra::Messages::Master # Create a new Master # # Options: @@ -25,9 +26,9 @@ module Hydra #:nodoc: def send_file(worker) f = @files.pop if f - worker[:io].write(Hydra::Messages::Master::RunFile.new(:file => f)) + worker[:io].write(RunFile.new(:file => f)) else - worker[:io].write(Hydra::Messages::Master::Shutdown.new) + worker[:io].write(Shutdown.new) Thread.exit end end diff --git a/lib/hydra/runner.rb b/lib/hydra/runner.rb index 17bb843..105e17f 100644 --- a/lib/hydra/runner.rb +++ b/lib/hydra/runner.rb @@ -7,13 +7,14 @@ module Hydra #:nodoc: # The general convention is to have one Runner for each logical processor # of a machine. class Runner + include Hydra::Messages::Runner # Boot up a runner. It takes an IO object (generally a pipe from its # parent) to send it messages on which files to execute. def initialize(opts = {}) @io = opts.fetch(:io) { raise "No IO Object" } @verbose = opts.fetch(:verbose) { false } - @io.write Hydra::Messages::Runner::RequestFile.new + @io.write RequestFile.new process_messages end @@ -29,7 +30,7 @@ module Hydra #:nodoc: $stdout.write " | #{message.inspect}\n" if @verbose message.handle(self) else - @io.write Hydra::Messages::Runner::Ping.new + @io.write Ping.new end rescue IOError => ex $stderr.write "Runner lost Worker\n" if @verbose @@ -41,7 +42,7 @@ module Hydra #:nodoc: # Run a test file and report the results def run_file(file) `ruby #{file}` - @io.write Hydra::Messages::Runner::Results.new(:output => "Finished", :file => file) + @io.write Results.new(:output => "Finished", :file => file) end # Stop running diff --git a/lib/hydra/worker.rb b/lib/hydra/worker.rb index 873dcb7..a17e831 100644 --- a/lib/hydra/worker.rb +++ b/lib/hydra/worker.rb @@ -7,6 +7,7 @@ module Hydra #:nodoc: # The general convention is to have one Worker per machine on a distributed # network. class Worker + include Hydra::Messages::Worker # Create a new worker. # * io: The IO object to use to communicate with the master # * num_runners: The number of runners to launch @@ -29,7 +30,7 @@ module Hydra #:nodoc: # When a runner wants a file, it hits this method with a message. # Then the worker bubbles the file request up to the master. def request_file(message, runner) - @io.write(Hydra::Messages::Worker::RequestFile.new) + @io.write(RequestFile.new) runner[:idle] = true end @@ -38,7 +39,7 @@ module Hydra #:nodoc: def delegate_file(message) r = idle_runner r[:idle] = false - r[:io].write(Hydra::Messages::Worker::RunFile.new(eval(message.serialize))) + r[:io].write(RunFile.new(eval(message.serialize))) end # When a runner finishes, it sends the results up to the worker. Then the @@ -47,7 +48,7 @@ module Hydra #:nodoc: # the master implicitly def relay_results(message, runner) runner[:idle] = true - @io.write(Hydra::Messages::Worker::Results.new(eval(message.serialize))) + @io.write(Results.new(eval(message.serialize))) end # When a master issues a shutdown order, it hits this method, which causes @@ -60,7 +61,7 @@ module Hydra #:nodoc: @runners.each do |r| $stdout.write "WORKER| Sending Shutdown to Runner\n" if @verbose $stdout.write " | #{r.inspect}\n" if @verbose - r[:io].write(Hydra::Messages::Worker::Shutdown.new) + r[:io].write(Shutdown.new) end Thread.exit end @@ -101,7 +102,7 @@ module Hydra #:nodoc: $stdout.write " | #{message.inspect}\n" if @verbose message.handle(self) else - @io.write Hydra::Messages::Worker::Ping.new + @io.write Ping.new end rescue IOError => ex $stderr.write "Worker lost Master\n" if @verbose