Rinda::RingFinger (Class)

In: rinda/ring.rb
Parent: Object

Methods

each   finger   lookup_ring   lookup_ring_any   new   primary   to_a   to_a  

Attributes

broadcast_list  [RW] 
port  [RW] 
primary  [RW] 

Public Class methods

[Source]

# File rinda/ring.rb, line 57
    def self.finger
      unless @@finger 
        @@finger = self.new
        @@finger.lookup_ring_any
      end
      @@finger
    end

[Source]

# File rinda/ring.rb, line 74
    def initialize(broadcast_list=@@broadcast_list, port=Ring_PORT)
      @broadcast_list = broadcast_list || ['localhost']
      @port = port
      @primary = nil
      @rings = []
    end

[Source]

# File rinda/ring.rb, line 65
    def self.primary
      finger.primary
    end

[Source]

# File rinda/ring.rb, line 69
    def self.to_a
      finger.to_a
    end

Public Instance methods

[Source]

# File rinda/ring.rb, line 86
    def each
      lookup_ring_any unless @primary
      return unless @primary
      yield(@primary)
      @rings.each { |x| yield(x) }
    end

[Source]

# File rinda/ring.rb, line 93
    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

[Source]

# File rinda/ring.rb, line 111
    def lookup_ring_any(timeout=5)
      queue = Queue.new

      th = Thread.new do
        self.lookup_ring(timeout) do |ts|
          queue.push(ts)
        end
        queue.push(nil)
        while it = queue.pop
          @rings.push(it)
        end
      end
      
      @primary = queue.pop
      raise('RingNotFound') if @primary.nil?
      @primary
    end

[Source]

# File rinda/ring.rb, line 82
    def to_a
      @rings
    end

[Validate]