Class: RGossip2::Receiver
- Inherits:
-
Object
- Object
- RGossip2::Receiver
- Includes:
- ContextHelper
- Defined in:
- lib/rgossip2/receiver.rb
Overview
class Receiver ゴシッププロトコルの受信クラス
------------
--------
| Receiver |<>—---
| Node | ------------
| --------
| +-----------------------+
+---+| @node_list:NodeList |
| +-----------------------+
| +-----------------------+
+---+| @dead_list:NodeList |
+-----------------------+
Instance Method Summary collapse
-
#initialize(context, self_node, node_list, dead_list) ⇒ Receiver
constructor
A new instance of Receiver.
- #join ⇒ Object
- #start ⇒ Object
-
#stop ⇒ Object
start.
Constructor Details
#initialize(context, self_node, node_list, dead_list) ⇒ Receiver
Returns a new instance of Receiver.
26 27 28 29 30 31 |
# File 'lib/rgossip2/receiver.rb', line 26 def initialize(context, self_node, node_list, dead_list) @context = context @self_node = self_node @node_list = node_list @dead_list = dead_list end |
Instance Method Details
#join ⇒ Object
60 61 62 |
# File 'lib/rgossip2/receiver.rb', line 60 def join @thread.join end |
#start ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rgossip2/receiver.rb', line 33 def start info("Reception is started: port=#{@context.port}") @running = true # パケット受信スレッドを開始 @thread = Thread.start { begin sock = UDPSocket.open sock.bind(@self_node.address, @context.port) while @running receive(sock) end ensure sock.close end } end |
#stop ⇒ Object
start
53 54 55 56 57 58 |
# File 'lib/rgossip2/receiver.rb', line 53 def stop info("Reception is stopped") # フラグをfalseにしてスレッドを終了させる @running = false end |