Class: RGossip2::Gossiper
- Inherits:
-
Object
- Object
- RGossip2::Gossiper
- Includes:
- ContextHelper
- Defined in:
- lib/rgossip2/gossiper.rb
Overview
class Gossiper ゴシッププロトコルの送信クラス
------------
--------
| Gossiper |<>—---
| Node | ------------
| --------
| +-----------------------+
+---+| @node_list:NodeList |
+-----------------------+
Instance Method Summary collapse
-
#initialize(context, self_node, node_list) ⇒ Gossiper
constructor
A new instance of Gossiper.
- #join ⇒ Object
- #start ⇒ Object
-
#stop ⇒ Object
start.
Constructor Details
#initialize(context, self_node, node_list) ⇒ Gossiper
Returns a new instance of Gossiper.
17 18 19 20 21 |
# File 'lib/rgossip2/gossiper.rb', line 17 def initialize(context, self_node, node_list) @context = context @self_node = self_node @node_list = node_list end |
Instance Method Details
#join ⇒ Object
55 56 57 |
# File 'lib/rgossip2/gossiper.rb', line 55 def join @thread.join end |
#start ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rgossip2/gossiper.rb', line 23 def start info("Transmission was started: interval=#{@context.gossip_interval} port=#{@context.port}") @running = true # パケット送信スレッドを開始 @thread = Thread.start { begin sock = UDPSocket.open while @running begin @node_list.synchronize { gossip(sock) } rescue Exception => e handle_error(e) end sleep(@context.gossip_interval) end ensure sock.close end } end |
#stop ⇒ Object
start
48 49 50 51 52 53 |
# File 'lib/rgossip2/gossiper.rb', line 48 def stop info("Transmission was stopped") # フラグをfalseにしてスレッドを終了させる @running = false end |