Class: RGossip::Node
- Inherits:
-
Object
- Object
- RGossip::Node
- Defined in:
- lib/rgossip/node.rb
Constant Summary collapse
- @@lifetime =
10
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#data ⇒ Object
Returns the value of attribute data.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(node_list, dead_list, address, data, timestamp, callback = nil) ⇒ Node
constructor
A new instance of Node.
- #reset_timer ⇒ Object
- #start_timer ⇒ Object
- #to_a ⇒ Object
- #update_timestamp ⇒ Object
Constructor Details
#initialize(node_list, dead_list, address, data, timestamp, callback = nil) ⇒ Node
Returns a new instance of Node.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rgossip/node.rb', line 12 def initialize(node_list, dead_list, address, data, , callback = nil) @node_list = node_list @dead_list = dead_list @address = address @data = data @timestamp = || "" @callback = callback @timer = Timer.new(@@lifetime) do RGossip.log("Timeout Node: address=#{@address}") @node_list.synchronize { @node_list.reject! do |i| i.address == @address end } @dead_list.synchronize { @dead_list << self } @callback.call([:delete, address, , data]) if @callback end end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
3 4 5 |
# File 'lib/rgossip/node.rb', line 3 def address @address end |
#callback ⇒ Object
Returns the value of attribute callback.
6 7 8 |
# File 'lib/rgossip/node.rb', line 6 def callback @callback end |
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/rgossip/node.rb', line 5 def data @data end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
4 5 6 |
# File 'lib/rgossip/node.rb', line 4 def @timestamp end |
Class Method Details
.lifetime ⇒ Object
9 |
# File 'lib/rgossip/node.rb', line 9 def self.lifetime; @@lifetime; end |
.lifetime=(v) ⇒ Object
10 |
# File 'lib/rgossip/node.rb', line 10 def self.lifetime=(v); @@lifetime = v; end |
Instance Method Details
#reset_timer ⇒ Object
52 53 54 55 56 |
# File 'lib/rgossip/node.rb', line 52 def reset_timer RGossip.log("Reset Timer: address=#{@address} lifetime=#{@@lifetime}") @timer.reset end |
#start_timer ⇒ Object
46 47 48 49 50 |
# File 'lib/rgossip/node.rb', line 46 def start_timer RGossip.log("Start Timer: address=#{@address} lifetime=#{@@lifetime}") @timer.start end |
#to_a ⇒ Object
42 43 44 |
# File 'lib/rgossip/node.rb', line 42 def to_a [@address, @timestamp, @data] end |
#update_timestamp ⇒ Object
37 38 39 40 |
# File 'lib/rgossip/node.rb', line 37 def now = Time.now @timestamp = "#{now.tv_sec}#{now.tv_usec}" end |