RingFinger is used by RingServer clients to discover the RingServer's TupleSpace. Typically, all a client needs to do is call ::primary to retrieve the remote TupleSpace, which it can then begin using.
- E
- F
- L
- N
- P
- T
[RW] | broadcast_list | The list of addresses where RingFinger will send query packets. |
[RW] | port | The port that RingFinger will send query packets to. |
[RW] | primary | Contain the first advertised TupleSpace after #lookup_ring_any is called. |
Creates a singleton RingFinger and looks for a RingServer. Returns the created RingFinger.
Creates a new RingFinger that will look for
RingServers at port
on the addresses in
broadcast_list
.
Returns the first advertised TupleSpace.
Contains all discovered TupleSpaces except for the primary.
Iterates over all discovered TupleSpaces starting with the primary.
Looks up RingServers waiting timeout
seconds. RingServers
will be given block
as a callback, which will be called with
the remote TupleSpace.
# File lib/rinda/ring.rb, line 176 def lookup_ring(timeout=5, &block) return lookup_ring_any(timeout) unless block_given? msg = Marshal.dump([[:lookup_ring, DRbObject.new(block)], timeout]) @broadcast_list.each do |it| soc = UDPSocket.open begin soc.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true) soc.send(msg, 0, it, @port) rescue nil ensure soc.close end end sleep(timeout) end
Returns the first found remote TupleSpace.
Any further recovered TupleSpaces can be found by calling
to_a
.
# File lib/rinda/ring.rb, line 198 def lookup_ring_any(timeout=5) queue = Queue.new Thread.new do self.lookup_ring(timeout) do |ts| queue.push(ts) end queue.push(nil) end @primary = queue.pop raise('RingNotFound') if @primary.nil? Thread.new do while it = queue.pop @rings.push(it) end end @primary end