Skip to content

Instantly share code, notes, and snippets.

@8th-Light-Blog
Created June 28, 2011 14:12
Show Gist options
  • Save 8th-Light-Blog/1051212 to your computer and use it in GitHub Desktop.
Save 8th-Light-Blog/1051212 to your computer and use it in GitHub Desktop.
Blog Title: Rinda 101
Author: Jim Suchy
Date: February 11th, 2008
require "rinda/tuplespace"
port = 4000
ts = Rinda::TupleSpace.new
DRb.start_service("druby://:#{port}", ts)
puts "Rinda listening on #{DRb.uri}..."
DRb.thread.join
require "rinda/rinda"
include Rinda
port = 4000
ts = DRbObject.new(nil, "druby://:#{port}")
while message = gets
begin
args = message.split(" ")
method = args.shift.to_sym
topic = args.shift.to_sym
message = args.shift
message = nil if message == "nil"
tuple = [topic, message]
puts ts.send(method, tuple)
rescue Exception => e
puts e.message
end
end
write message hello
Rinda::TupleEntry:0x4f998
write message world
Rinda::TupleEntry:0x4cfa4
read message nil
message
hello
take message nil
message
hello
take message nil
message
world
ts.write([:message, "hello"]) => Rinda::TupleEntry:0x4f998
ts.write([:message, "world"]) => Rinda::TupleEntry:0x4cfa4
ts.read([:message, nil]) => "hello"
ts.take([:message, nil]) => "hello"
ts.take([:message, nil]) => "world"
1) [:message]
2) [:message, "hello"]
3) [:message, "hello", "world"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment