Skip to content

Instantly share code, notes, and snippets.

@seki
Created June 30, 2009 17:17
Show Gist options
  • Save seki/138276 to your computer and use it in GitHub Desktop.
Save seki/138276 to your computer and use it in GitHub Desktop.
require 'thread'
require 'drb/drb'
require 'rinda/rinda'
class Agent
def initialize(name, url, desc)
@tuple = [name, url, desc]
@inbox = Queue.new
@renewer = Rinda::SimpleRenewer.new(15)
end
def pop
@inbox.pop
end
def hello(name, url, desc)
@inbox.push([name, url, desc])
return @tuple
end
def meet(who)
tuple = who.hello(*@tuple)
@inbox.push(tuple)
end
def enter(place)
place.write([:agent, @tuple[0], self], @renewer)
end
def broadcast(place)
place.read_all([:agent, String, DRbObject]).each do |k, name, ro|
next if name == @tuple[0]
ro.meet(self) rescue nil
end
end
end
DRb.start_service
place = DRbObject.new_with_uri(ARGV.shift)
name = 'your_nick'
url = 'http://your_page'
desc = 'your comment'
agent = Agent.new(name, url, desc)
agent.enter(place)
agent.broadcast(place)
while true
p agent.pop
end
require 'rinda/tuplespace'
ts = Rinda::TupleSpace.new(15)
DRb.start_service('druby://:56788', ts)
while true
puts
puts DRb.uri
ts.read_all([nil, nil, nil]).each do |t|
p [t[0], t[1], t[2].__drburi]
end
sleep 10
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment