Class | Rinda::RingServer |
In: |
lib/rinda/ring.rb
|
Parent: | Object |
A RingServer allows a Rinda::TupleSpace to be located via UDP broadcasts. Service location uses the following steps:
Advertises ts on the UDP broadcast address at port.
# File lib/rinda/ring.rb, line 32 32: def initialize(ts, port=Ring_PORT) 33: @ts = ts 34: @soc = UDPSocket.open 35: @soc.bind('', port) 36: @w_service = write_service 37: @r_service = reply_service 38: end
Pulls lookup tuples out of the TupleSpace and sends their DRb object the address of the local TupleSpace.
# File lib/rinda/ring.rb, line 82 82: def do_reply 83: tuple = @ts.take([:lookup_ring, nil]) 84: Thread.new { tuple[1].call(@ts) rescue nil} 85: rescue 86: end
Extracts the response URI from msg and adds it to TupleSpace where it will be picked up by reply_service for notification.
# File lib/rinda/ring.rb, line 57 57: def do_write(msg) 58: Thread.new do 59: begin 60: tuple, sec = Marshal.load(msg) 61: @ts.write(tuple, sec) 62: rescue 63: end 64: end 65: end
Creates a thread that notifies waiting clients from the TupleSpace.
# File lib/rinda/ring.rb, line 70 70: def reply_service 71: Thread.new do 72: loop do 73: do_reply 74: end 75: end 76: end