Class: RGossip::Gossiper

Inherits:
Object
  • Object
show all
Defined in:
lib/rgossip/gossipper.rb

Constant Summary collapse

@@interval =
0.1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(my_node, node_list) ⇒ Gossiper

Returns a new instance of Gossiper.



7
8
9
10
# File 'lib/rgossip/gossipper.rb', line 7

def initialize(my_node, node_list)
  @my_node = my_node
  @node_list = node_list
end

Class Method Details

.intervalObject



4
# File 'lib/rgossip/gossipper.rb', line 4

def self.interval; @@interval; end

.interval=(v) ⇒ Object



5
# File 'lib/rgossip/gossipper.rb', line 5

def self.interval=(v); @@interval = v; end

Instance Method Details

#joinObject



42
43
44
# File 'lib/rgossip/gossipper.rb', line 42

def join
  @thread.join
end

#startObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rgossip/gossipper.rb', line 12

def start
  RGossip.log("Start Gossiper: interval=#{@@interval}")
  @running = true

  @thread = Thread.start {
    begin
      sock = UDPSocket.open

      while @running
        begin
          @node_list.synchronize { gossip(sock) }
        rescue Exception => e
          raise e unless RGossip.error_handler
          RGossip.error_handler.call(e)
        end

        sleep(@@interval)
      end
    ensure
      sock.close
    end
  }
end

#stopObject



36
37
38
39
40
# File 'lib/rgossip/gossipper.rb', line 36

def stop
  RGossip.log("Stop Gossiper")

  @running = false
end