Class: RGossip::Receiver

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

Constant Summary collapse

@@timeout =
3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(my_node, node_list, dead_list, callback = nil) ⇒ Receiver

Returns a new instance of Receiver.



9
10
11
12
13
14
# File 'lib/rgossip/receiver.rb', line 9

def initialize(my_node, node_list, dead_list, callback = nil)
  @my_node = my_node
  @node_list = node_list
  @dead_list = dead_list
  @callback = callback
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



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

def callback
  @callback
end

Class Method Details

.timeoutObject



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

def self.timeout; @@timeout; end

.timeout=(v) ⇒ Object



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

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

Instance Method Details

#joinObject



40
41
42
# File 'lib/rgossip/receiver.rb', line 40

def join
  @thread.join
end

#startObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rgossip/receiver.rb', line 16

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

  @thread = Thread.start {
    begin
      sock = UDPSocket.open
      sock.bind(@my_node.address, RGossip.port)

      while @running
        receive(sock)
      end
    ensure
      sock.close
    end
  }
end

#stopObject



34
35
36
37
38
# File 'lib/rgossip/receiver.rb', line 34

def stop
  RGossip.log("Stop Receiver")

  @running = false
end