require 'drb/drb' require 'rinda/rinda' require 'monitor' class RemoteNQueen class Stream include MonitorMixin def initialize(block) super() @block = block end def push(x) synchronize do @block.call(x) end end end def initialize(tuplespace) super() @ts = tuplespace end def expand(size, &block) key = "#{DRb.uri}:#{id}" stream = Stream.new(block) size.times do |row| @ts.write([:nqueen, key, size, [], row, DRbObject.new(stream)]) end size.times do |row| @ts.take([:nqueen_done, key]) end end end if __FILE__ == $0 DRb.start_service ts_uri = ARGV.shift || raise ts = DRbObject.new(nil, ts_uri) rq = RemoteNQueen.new(ts) rq.expand((ARGV.shift || '5').to_i) do |x| puts x.join(" ") end end