Rinda
We started the day with a Rinda lab. It's so sweet. With just a few lines of code, you can set up a Rinda Ring Server:
require 'rinda/ring'
require 'rinda/tuplespace'
DRb.start_service
Rinda::RingServer.new Rinda::TupleSpace.new
puts "Ring server up and running"
DRb.thread.join if __FILE__ == $0
After that, a server is similarly easy to setup:
require 'rinda/ring'
require 'rinda/tuplespace'
DRb.start_service
Rinda::RingServer.new Rinda::TupleSpace.new
puts "Ring server up and running"
DRb.thread.join if __FILE__ == $0
puts "TupleSpace ready to go"
provider = RingProvider.new :TupleSpace, ts, "Class Registry"
provider.provide
puts "TupleSpace registered in the Rinda Ring"
DRb.thread.join if __FILE__ == $0
The client code is similarly trivial:
require 'rinda/ring'
require 'rinda/tuplespace'
include Rinda
DRb.start_service
puts "looking for a ring server"
finger = RingFinger.new
name_server = finger.lookup_ring_any
puts "found a ring server"
classroom_tuple = name_server.read([:name, :TupleSpace, nil, "Class Registry"])
puts "found a classroom"
classroom = classroom_tuple[2]
puts classroom
ts.write [:attendees, {}]
begin
puts "Taking the attendees list"
attendees = classroom.take([:attendees,nil])
puts "Have the attendees list"
attendees[1]['muness@gmail.com'] = {:words=>'Mundane Evolution Symbiosis'}
ensure
puts "Writing back the attendees"
classroom.write(attendees)
puts "Wrote the attendees"
end
That's it in a few dozen lines of code, you have autodiscovery of a Rinda Ring Server (think name server), through that, you can register rinda servers (think message server). In the client you discover the ring server, take/read/write to it.
Part of what Stu and Justin showed off, was a cool Rinda based Rake distributed system: a director manages requests for executions of Rake tasks on multiple projects and writes them to a tuple space. Rakers (Rinda clients) then come along, take a task tuple and executes the task described. The raker posts the result of the rake task back to a tuple space.
The really cool thing was how little code there was to do this. I am sure you could use Jini to do this sort of thing. But this is so, so easy to read/write.

1 comment:
Hey, thanks for the post about RInda auto-discovery. Unfortunately, I can't get the server code to execute all the way through. It stops at each of the thread joins. If I take them all out, it stops at the RingProvider.new(...).provide.
Any idea what's going on?
Post a Comment