corosync 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ebdf0a21a91d835cd04ebbdccba82d69b791636
4
- data.tar.gz: bfbc00cbe277b8bdf5fb7fc8f7e7f7286accd97b
3
+ metadata.gz: ec6cba2dc8f6d3d85accfe0821274b1bc3268e2a
4
+ data.tar.gz: 05257c44ede07405190a84caaf509be8216095d6
5
5
  SHA512:
6
- metadata.gz: 09db7ddafba097fde8bd040d98e667cb6f8b291020804d5c503334432c883c0792360547b66b9caa48204ee2e85131d96dafcbe8390cd12ce984245ea522d15b
7
- data.tar.gz: 65a2cc445d24f1c7f3ac033cc485ba2457ba5e3460c237c30b30e06a3f17dc61f684990c18eaa65cd174360addc5e9456a9089efe0841a7abcd612988966881c
6
+ metadata.gz: 16c7e8a4d0ac77525d5ba950d9f04b025d0424c07b39ba613ec70843f5ce80acf2eab56bc1762923fc5b0a22ad29710314553e8841322890338118755c12eebf
7
+ data.tar.gz: e818f76f4e96fa0bf648a62767c3ca7208646b36d319d4ae81c58d578a4a62a6c5fac6a08a22ed573e2994ba635c812a4b944f9b9749f75dd0382258a697bffe
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  .yardoc
2
+ *.gem
data/README.md CHANGED
@@ -23,6 +23,7 @@ Currently the only supported service is CPG. It is fully functional, though it m
23
23
 
24
24
  ### CPG
25
25
 
26
+ require 'corosync/cpg'
26
27
  cpg = Corosync::CPG.new('mygroup')
27
28
  cpg.on_message do |message, membership|
28
29
  puts "Received #{message}"
@@ -20,7 +20,7 @@ class Corosync::CPG::Member
20
20
  member = args.first
21
21
 
22
22
  member = Corosync::CpgAddress.new(member) if member.is_a?(FFI::Pointer)
23
- if member.is_a?(Corosync::CpgAddress) then
23
+ if member.is_a?(Corosync::CpgAddress) or member.is_a?(Corosync::CpgIterationDescriptionT) then
24
24
  @nodeid = member[:nodeid]
25
25
  @pid = member[:pid]
26
26
  else
data/lib/corosync/cpg.rb CHANGED
@@ -12,7 +12,7 @@ require 'corosync/cpg/member'
12
12
  # This is all done through callbacks. You define a block of code to execute, and whenever a message is received, it is passed to that block.
13
13
  # After registering the callbacks, you call {#dispatch} to check for any pending messages, upon which the appropriate callbacks will be executed.
14
14
  #
15
- # The simplest usage of this library is to call `Corosync::CPG.new('groupname')`. This will connect to CPG and join the specified group. Note though that upon joining a group, the library automatically calls {#dispatch} once on it's own. This is so that it can get the initial confchg message and obtain a group membership list. As such you will not have been able to establish a callback yet. The solution to this is to create the CPG object without joining, register your callbacks, and then call {#join}.
15
+ # The simplest usage of this library is to call `Corosync::CPG.new('groupname')`. This will connect to CPG and join the specified group.
16
16
  #
17
17
  # == Threading notice
18
18
  # With MRI Ruby 1.9.3 and older, you cannot call {#dispatch} from within a thread. Attempting to do so will result in a segfault.
@@ -22,6 +22,7 @@ require 'corosync/cpg/member'
22
22
  # ----
23
23
  #
24
24
  # @example
25
+ # require 'corosync/cpg'
25
26
  # cpg = Corosync::CPG.new('mygroup')
26
27
  # cpg.on_message do |message, member|
27
28
  # puts "Received #{message}"
@@ -38,10 +39,6 @@ class Corosync::CPG
38
39
  # @return [IO]
39
40
  attr_reader :fd
40
41
 
41
- # Members currently in the group.
42
- # @return [Corosync::CPG::MemberList]
43
- attr_reader :members
44
-
45
42
  # Name of the currently joined group
46
43
  # @return [String]
47
44
  attr_reader :group
@@ -66,7 +63,6 @@ class Corosync::CPG
66
63
  @group = nil
67
64
  @fd = nil
68
65
  @handle = nil
69
- @members = Corosync::CPG::MemberList.new
70
66
 
71
67
  join group if group
72
68
  end
@@ -103,14 +99,12 @@ class Corosync::CPG
103
99
  @fd = nil
104
100
  @model = nil
105
101
  @handle = nil
106
- @members = Corosync::CPG::MemberList.new
107
102
 
108
103
  true
109
104
  end
110
105
  alias_method :close, :finalize
111
106
 
112
107
  # Join the specified closed process group.
113
- # Note that the library will automatically make a call to {#dispatch} upon join. This is so that it can obtain a group membership list. If you wish to receive the initial join message, you must register the callback with {#on_confchg} before calling {#join}.
114
108
  # @param name [String] Name of the group. Maximum length of 128 characters.
115
109
  # @return [void]
116
110
  def join(name)
@@ -124,8 +118,6 @@ class Corosync::CPG
124
118
  raise StandardError, "Received #{cs_error.to_s.upcase} attempting to join group"
125
119
  end
126
120
 
127
- dispatch
128
-
129
121
  @group = name
130
122
 
131
123
  self
@@ -146,7 +138,6 @@ class Corosync::CPG
146
138
  end
147
139
 
148
140
  @group = nil
149
- @members = Corosync::CPG::MemberList.new
150
141
  end
151
142
 
152
143
  # Checks for a single pending events and triggers the appropriate callback if found.
@@ -199,8 +190,6 @@ class Corosync::CPG
199
190
  member_list << (member_list_p + i * Corosync::CpgAddress.size)
200
191
  end
201
192
 
202
- @members = member_list.dup.freeze
203
-
204
193
  return if !@callback_confchg # no point in continuing otherwise
205
194
 
206
195
  left_list = Corosync::CPG::MemberList.new
@@ -247,6 +236,40 @@ class Corosync::CPG
247
236
  nodeid_p.read_uint
248
237
  end
249
238
 
239
+ # Gets a list of members currently in the group
240
+ # @return [Corosync::CPG::MemberList]
241
+ def members
242
+ members = Corosync::CPG::MemberList.new
243
+
244
+ cpg_name = Corosync::CpgName.new
245
+ cpg_name[:value] = @group
246
+ cpg_name[:length] = @group.size
247
+
248
+ iteration_handle_ptr = FFI::MemoryPointer.new(Corosync.find_type(:cpg_iteration_handle_t))
249
+ cs_error = Corosync.cpg_iteration_initialize(@handle, Corosync::CPG_ITERATION_ONE_GROUP, cpg_name, iteration_handle_ptr)
250
+ if cs_error != :ok then
251
+ raise StandardError, "Received #{cs_error.to_s.upcase} attempting to initialize member iteration"
252
+ end
253
+ iteration_handle = iteration_handle_ptr.read_uint64
254
+
255
+ begin
256
+ iteration_description = Corosync::CpgIterationDescriptionT.new
257
+ while (cs_error = Corosync.cpg_iteration_next(iteration_handle, iteration_description.pointer)) == :ok do
258
+ members << Corosync::CPG::Member.new(iteration_description)
259
+ end
260
+ if cs_error != :err_no_sections then
261
+ raise StandardError, "Received #{cs_error.to_s.upcase} attempting to iterate group members"
262
+ end
263
+ ensure
264
+ cs_error = Corosync.cpg_iteration_finalize(iteration_handle)
265
+ if cs_error != :ok then
266
+ raise StandardError, "Received #{cs_error.to_s.upcase} attempting to finalize member iteration"
267
+ end
268
+ end
269
+
270
+ members
271
+ end
272
+
250
273
  # Returns the {Corosync::CPG::Member member} object describing ourself.
251
274
  # @return [Corosync::CPG::Member]
252
275
  def member
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Corosync
2
- GEM_VERSION = '0.0.2'
2
+ GEM_VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corosync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Hemmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-05 00:00:00.000000000 Z
11
+ date: 2013-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi