Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • rinda/ring.rb

Parent

Included Modules

Rinda::RingServer

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.

Public Class Methods

new(ts, port=Ring_PORT) click to toggle source

Advertises ts on the UDP broadcast address at port.

 
               # File rinda/ring.rb, line 32
def initialize(ts, port=Ring_PORT)
  @ts = ts
  @soc = UDPSocket.open
  @soc.bind('', port)
  @w_service = write_service
  @r_service = reply_service
end
            

Public Instance Methods

do_reply() click to toggle source

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

 
               # File rinda/ring.rb, line 82
def do_reply
  tuple = @ts.take([:lookup_ring, nil])
  Thread.new { tuple[1].call(@ts) rescue nil}
rescue
end
            
do_write(msg) click to toggle source

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
def do_write(msg)
  Thread.new do
    begin
      tuple, sec = Marshal.load(msg)
      @ts.write(tuple, sec)
    rescue
    end
  end
end
            
reply_service() click to toggle source

Creates a thread that notifies waiting clients from the TupleSpace.

 
               # File rinda/ring.rb, line 70
def reply_service
  Thread.new do
    loop do
      do_reply
    end
  end
end
            
write_service() click to toggle source

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

 
               # File rinda/ring.rb, line 44
def write_service
  Thread.new do
    loop do
      msg = @soc.recv(1024)
      do_write(msg)
    end
  end
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus