rgossip 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -103,27 +103,40 @@ module RGossip
103
103
  @node_list.synchronize {
104
104
  @dead_list.synchronize {
105
105
  raise 'node is exist' if @node_list.any? {|i| i.address == address }
106
+
106
107
  node = Node.new(@node_list, @dead_list, address, nil, nil, self.method(:perform_callback))
107
108
  @node_list << node
108
- node.start_timer if @running
109
109
 
110
110
  @dead_list.reject! do |i|
111
111
  i.address == address
112
112
  end
113
+
114
+ node.start_timer if @running
115
+
116
+ perform_callback([:add, address, nil, nil])
113
117
  }
114
118
  }
115
119
  end
116
120
 
117
121
  def delete_node(address)
122
+ address = name2addr(address)
118
123
  raise 'cannot delete own node' if @my_node.address == address
119
124
 
120
125
  @node_list.synchronize {
121
- @node_list.reject! do |i|
122
- if i.address == address
123
- i.stop_timer
124
- true
126
+ @dead_list.synchronize {
127
+ @node_list.reject! do |i|
128
+ if i.address == address
129
+ i.stop_timer
130
+ true
131
+ end
125
132
  end
126
- end
133
+
134
+ @dead_list.reject! do |i|
135
+ i.address == address
136
+ end
137
+
138
+ perform_callback([:delete, address, nil, nil])
139
+ }
127
140
  }
128
141
  end
129
142
 
data/lib/rgossip/node.rb CHANGED
@@ -34,7 +34,7 @@ module RGossip
34
34
  @dead_list << self
35
35
  }
36
36
 
37
- @callback.call([:delete, address, timestamp, data]) if @callback
37
+ @callback.call([:delete, @address, @timestamp, @data]) if @callback
38
38
  end
39
39
  end
40
40
 
data/lib/rgossip/timer.rb CHANGED
@@ -3,59 +3,47 @@ module RGossip
3
3
  def initialize(timeout, &block)
4
4
  @timeout = timeout
5
5
  @block = block
6
- @mutex = Mutex.new
7
- @reset = false
8
6
  end
9
7
 
10
8
  def start
11
- @mutex.synchronize {
12
- if_is_thread_alive? { @thread.kill }
13
- @reset = false
9
+ @thread.kill if is_thread_alive?
10
+ @start_time = Time.now
14
11
 
15
- @thread = Thread.start {
16
- loop do
17
- sleep @timeout
18
-
19
- if @reset
20
- @reset = false
21
- retry
22
- end
12
+ @thread = Thread.start(@start_time) {|start_time|
13
+ loop do
14
+ sleep @timeout
23
15
 
16
+ if @start_time == start_time
24
17
  @block.call
25
18
  break
19
+ elsif @start_time.nil?
20
+ break
21
+ else
22
+ start_time = @start_time
26
23
  end
27
- }
24
+ end
28
25
  }
29
26
  end
30
27
 
31
28
  def reset
32
- @mutex.synchronize {
33
- if_is_thread_alive? do
34
- begin
35
- @reset = true
36
- @thread.run
37
- ensure
38
- @reset = false
39
- end
40
- end
41
- }
29
+ if is_thread_alive?
30
+ @start_time = Time.now
31
+ @thread.run
32
+ end
42
33
  rescue ThreadError
43
34
  end
44
35
 
45
36
  def stop
46
- @mutex.synchronize {
47
- if_is_thread_alive? do
48
- @thread.kill
49
- end
50
- }
37
+ if is_thread_alive?
38
+ @start_time = nil
39
+ @thread.run
40
+ end
51
41
  rescue ThreadError
52
42
  end
53
43
 
54
44
  private
55
- def if_is_thread_alive?
56
- if @thread and @thread.alive?
57
- yield
58
- end
45
+ def is_thread_alive?
46
+ @thread and @thread.alive?
59
47
  end
60
48
  end # Timer
61
49
  end # RGossip
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgossip
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 8
10
- version: 0.1.8
9
+ - 9
10
+ version: 0.1.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-23 00:00:00 +09:00
19
- default_executable:
18
+ date: 2011-05-23 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: msgpack
@@ -42,14 +41,13 @@ extra_rdoc_files: []
42
41
 
43
42
  files:
44
43
  - README
45
- - lib/rgossip/client.rb
44
+ - lib/rgossip/timer.rb
46
45
  - lib/rgossip/gossipper.rb
47
- - lib/rgossip/node.rb
48
- - lib/rgossip/nodes.rb
46
+ - lib/rgossip/client.rb
49
47
  - lib/rgossip/receiver.rb
50
- - lib/rgossip/timer.rb
48
+ - lib/rgossip/nodes.rb
49
+ - lib/rgossip/node.rb
51
50
  - lib/rgossip.rb
52
- has_rdoc: true
53
51
  homepage: https://bitbucket.org/winebarrel/rgossip
54
52
  licenses: []
55
53
 
@@ -79,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
77
  requirements: []
80
78
 
81
79
  rubyforge_project:
82
- rubygems_version: 1.4.2
80
+ rubygems_version: 1.8.1
83
81
  signing_key:
84
82
  specification_version: 3
85
83
  summary: Basic implementation of a gossip protocol. This is a porting of Java implementation. see http://code.google.com/p/gossip-protocol-java/