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.
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

View File

@ -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

View File

@ -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