Permalink
Browse files

DRb with Rinda

  • Loading branch information...
1 parent 7b5078f commit d63f0690c0a795e267a728ed5966a4d3c5dbc1b6 @sandro committed Feb 15, 2010
Showing with 66 additions and 0 deletions.
  1. +24 −0 lib/dispatcher.rb
  2. +42 −0 lib/worker.rb
View
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require 'drb/drb'
+require 'rinda/ring'
+require 'rinda/tuplespace'
+
+DRb.start_service
+
+ring_server = Rinda::RingFinger.primary
+#
+# service = ring_server.read([:name, nil, nil, nil])
+
+# worker = service[2]
+# worker.run("spec/1 spec/2 spec/3")
+
+services = ring_server.read_all([:name, nil, nil, nil])
+services.each do |service|
+ worker = service[2]
+ worker.run("spec/1 spec/2 spec/3")
+end
+ # p service
+ # worker = service[2]
+ # worker.run("spec/1 spec/2 spec/3")
+# end
View
@@ -0,0 +1,42 @@
+#!/usr/bin/env ruby
+
+require 'rinda/ring'
+require 'rubygems'
+require 'ringy_dingy'
+require 'ringy_dingy/ring_server'
+
+class RingyDingy::RingServer
+ # monkey patch to add timeout support
+ def self.list_services(timeout=5)
+ DRb.start_service unless DRb.primary_server
+
+ services = {}
+
+ RF.lookup_ring(timeout) do |ts|
+ services[ts.__drburi] = ts.read_all [:name, nil, DRbObject, nil]
+ end
+
+ return services
+ end
+end
+
+class Worker
+ include DRbUndumped
+ def run(specs)
+ puts "running specs #{specs.inspect}"
+ end
+end
+
+DRb.start_service
+
+if RingyDingy::RingServer.list_services(1).any?
+ RingyDingy.new(Worker.new, :SpecjourWorker).run
+ # ring_server = Rinda::RingFinger.primary
+ # p ring_server
+ # p ring_server
+ # ring_server.write([:name, :SpecjourWorker, Worker.new, "spec runner"], Rinda::SimpleRenewer.new)
+
+ DRb.thread.join
+else
+ abort "No ring services found. The master need to run 'ring_server -d' before this worker can should be started"
+end

0 comments on commit d63f069

Please sign in to comment.