included message modules in processor classes so you don't have to namespace them

This commit is contained in:
Nick Gauthier 2010-01-29 13:32:37 -05:00
parent 847c77ef0f
commit c8d833d1d3
3 changed files with 13 additions and 10 deletions

View File

@ -3,6 +3,7 @@ module Hydra #:nodoc:
# #
# The Master is run once for any given testing session. # The Master is run once for any given testing session.
class Master class Master
include Hydra::Messages::Master
# Create a new Master # Create a new Master
# #
# Options: # Options:
@ -25,9 +26,9 @@ module Hydra #:nodoc:
def send_file(worker) def send_file(worker)
f = @files.pop f = @files.pop
if f if f
worker[:io].write(Hydra::Messages::Master::RunFile.new(:file => f)) worker[:io].write(RunFile.new(:file => f))
else else
worker[:io].write(Hydra::Messages::Master::Shutdown.new) worker[:io].write(Shutdown.new)
Thread.exit Thread.exit
end end
end end

View File

@ -7,13 +7,14 @@ module Hydra #:nodoc:
# The general convention is to have one Runner for each logical processor # The general convention is to have one Runner for each logical processor
# of a machine. # of a machine.
class Runner class Runner
include Hydra::Messages::Runner
# Boot up a runner. It takes an IO object (generally a pipe from its # Boot up a runner. It takes an IO object (generally a pipe from its
# parent) to send it messages on which files to execute. # parent) to send it messages on which files to execute.
def initialize(opts = {}) def initialize(opts = {})
@io = opts.fetch(:io) { raise "No IO Object" } @io = opts.fetch(:io) { raise "No IO Object" }
@verbose = opts.fetch(:verbose) { false } @verbose = opts.fetch(:verbose) { false }
@io.write Hydra::Messages::Runner::RequestFile.new @io.write RequestFile.new
process_messages process_messages
end end
@ -29,7 +30,7 @@ module Hydra #:nodoc:
$stdout.write " | #{message.inspect}\n" if @verbose $stdout.write " | #{message.inspect}\n" if @verbose
message.handle(self) message.handle(self)
else else
@io.write Hydra::Messages::Runner::Ping.new @io.write Ping.new
end end
rescue IOError => ex rescue IOError => ex
$stderr.write "Runner lost Worker\n" if @verbose $stderr.write "Runner lost Worker\n" if @verbose
@ -41,7 +42,7 @@ module Hydra #:nodoc:
# Run a test file and report the results # Run a test file and report the results
def run_file(file) def run_file(file)
`ruby #{file}` `ruby #{file}`
@io.write Hydra::Messages::Runner::Results.new(:output => "Finished", :file => file) @io.write Results.new(:output => "Finished", :file => file)
end end
# Stop running # Stop running

View File

@ -7,6 +7,7 @@ module Hydra #:nodoc:
# The general convention is to have one Worker per machine on a distributed # The general convention is to have one Worker per machine on a distributed
# network. # network.
class Worker class Worker
include Hydra::Messages::Worker
# Create a new worker. # Create a new worker.
# * io: The IO object to use to communicate with the master # * io: The IO object to use to communicate with the master
# * num_runners: The number of runners to launch # * 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. # When a runner wants a file, it hits this method with a message.
# Then the worker bubbles the file request up to the master. # Then the worker bubbles the file request up to the master.
def request_file(message, runner) def request_file(message, runner)
@io.write(Hydra::Messages::Worker::RequestFile.new) @io.write(RequestFile.new)
runner[:idle] = true runner[:idle] = true
end end
@ -38,7 +39,7 @@ module Hydra #:nodoc:
def delegate_file(message) def delegate_file(message)
r = idle_runner r = idle_runner
r[:idle] = false r[:idle] = false
r[:io].write(Hydra::Messages::Worker::RunFile.new(eval(message.serialize))) r[:io].write(RunFile.new(eval(message.serialize)))
end end
# When a runner finishes, it sends the results up to the worker. Then the # When a runner finishes, it sends the results up to the worker. Then the
@ -47,7 +48,7 @@ module Hydra #:nodoc:
# the master implicitly # the master implicitly
def relay_results(message, runner) def relay_results(message, runner)
runner[:idle] = true runner[:idle] = true
@io.write(Hydra::Messages::Worker::Results.new(eval(message.serialize))) @io.write(Results.new(eval(message.serialize)))
end end
# When a master issues a shutdown order, it hits this method, which causes # When a master issues a shutdown order, it hits this method, which causes
@ -60,7 +61,7 @@ module Hydra #:nodoc:
@runners.each do |r| @runners.each do |r|
$stdout.write "WORKER| Sending Shutdown to Runner\n" if @verbose $stdout.write "WORKER| Sending Shutdown to Runner\n" if @verbose
$stdout.write " | #{r.inspect}\n" if @verbose $stdout.write " | #{r.inspect}\n" if @verbose
r[:io].write(Hydra::Messages::Worker::Shutdown.new) r[:io].write(Shutdown.new)
end end
Thread.exit Thread.exit
end end
@ -101,7 +102,7 @@ module Hydra #:nodoc:
$stdout.write " | #{message.inspect}\n" if @verbose $stdout.write " | #{message.inspect}\n" if @verbose
message.handle(self) message.handle(self)
else else
@io.write Hydra::Messages::Worker::Ping.new @io.write Ping.new
end end
rescue IOError => ex rescue IOError => ex
$stderr.write "Worker lost Master\n" if @verbose $stderr.write "Worker lost Master\n" if @verbose