| Class | Rinda::RingServer |
| In: |
rinda/ring.rb
|
| Parent: | Object |
A RingServer allows a Rinda::TupleSpace to be located via UDP broadcasts. Service location uses the following steps:
- A RingServer begins listening on the broadcast UDP address.
- A RingFinger sends a UDP packet containing the DRb URI where it will listen for a reply.
- The RingServer recieves the UDP packet and connects back to the provided DRb URI with the DRb service.
Methods
Included Modules
DRbUndumped
Public Class methods
Advertises ts on the UDP broadcast address at port.
# File 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
Public Instance methods
Pulls lookup tuples out of the TupleSpace and sends their DRb object the address of the local TupleSpace.
# File rinda/ring.rb, line 82
82: def do_reply
83: tuple = @ts.take([:lookup_ring, DRbObject])
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 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 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