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:

  1. A RingServer begins listening on the broadcast UDP address.
  2. A RingFinger sends a UDP packet containing the DRb URI where it will listen for a reply.
  3. The RingServer receives 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.

[Source]

    # 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

Public Instance methods

Pulls lookup tuples out of the TupleSpace and sends their DRb object the address of the local TupleSpace.

[Source]

    # 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.

[Source]

    # 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.

[Source]

    # 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

Creates a thread that picks up UDP packets and passes them to do_write for decoding.

[Source]

    # File lib/rinda/ring.rb, line 44
44:     def write_service
45:       Thread.new do
46:         loop do
47:           msg = @soc.recv(1024)
48:           do_write(msg)
49:         end
50:       end
51:     end

[Validate]