Permalink
Browse files

Update to work with the latest doozerd

  • Loading branch information...
1 parent 09cc5e0 commit a08476f9e854243af9f87ae0efb1b3597f799971 @philwhln philwhln committed Apr 4, 2012
Showing with 35 additions and 22 deletions.
  1. +6 −0 README.md
  2. +22 −5 lib/fraggle/block/client.rb
  3. +6 −9 lib/fraggle/block/connection.rb
  4. +1 −8 lib/fraggle/block/response.rb
View
@@ -24,3 +24,9 @@ A synchronous Ruby client for [Doozer](https://github.com/ha/doozer).
=> nil
See [examples](https://github.com/dylanegan/fraggle-block/tree/master/examples) for more.
+
+
+# Generate ProtoBuf code
+
+BEEFCAKE_NAMESPACE=Fraggle::Block protoc --beefcake_out lib/fraggle/block/ -I . msg.proto
+
@@ -12,6 +12,9 @@ class OutOfNodes < StandardError; end
def initialize(addrs = [])
@addrs = addrs
+ if not @addrs or @addrs.length == 0
+ raise "No doozer servers to connect to"
+ end
connect
end
@@ -40,9 +43,22 @@ def del(path, rev)
send(request).first
end
- def walk(path, rev = nil)
- request = Request.new(:path => path, :rev => rev, :verb => WALK)
- send(request)
+ def walk(path, rev = nil, offset = 0)
+ all_responses = []
+ done = false
+ while not done
+ request = Request.new(:path => path, :rev => rev, :verb => WALK, :offset => offset)
+ responses = send(request)
+ responses.each do |response|
+ if response.err_code == Response::Err::RANGE
+ done = true
+ break
+ end
+ all_responses.push response
+ offset += 1
+ end
+ end
+ return all_responses
end
def disconnect
@@ -57,7 +73,7 @@ def reconnect
def connect
begin
host, port = @addrs.shift.split(':')
- @connection = connection_to(host, port)
+ @connection = connection_to(host, port.to_i)
find_all_of_the_nodes
rescue => e
retry if @addrs.any?
@@ -70,7 +86,8 @@ def connection_to(host, port)
end
def find_all_of_the_nodes
- walk('/ctl/node/*/addr').each do |node|
+ response = rev()
+ walk('/ctl/node/*/addr', response.rev).each do |node|
@addrs << node.value unless @addrs.include? node.value
end
end
@@ -25,7 +25,7 @@ def connect
begin
sock.connect_nonblock(Socket.pack_sockaddr_in(@port, addr[0][3]))
rescue Errno::EINPROGRESS
- resp = IO.select([sock],nil, nil, timeout.to_i)
+ resp = IO.select(nil, [sock], nil, timeout.to_i)
if resp.nil?
raise Errno::ECONNREFUSED
end
@@ -50,14 +50,11 @@ def send(req)
def read
responses = []
- loop do
- head = @sock.read(4)
- length = head.unpack("N")[0]
- data = @sock.read(length)
- response = Response.decode(data)
- responses << response if response.valid?
- break if response.done?
- end
+ head = @sock.read(4)
+ length = head.unpack("N")[0]
+ data = @sock.read(length)
+ response = Response.decode(data)
+ responses << response if response.valid?
responses
end
end
@@ -1,15 +1,8 @@
module Fraggle
module Block
class Response
- VALID = 1
- DONE = 2
-
def valid?
- (flags & VALID) > 0
- end
-
- def done?
- (flags & DONE) > 0
+ true
end
end
end

0 comments on commit a08476f

Please sign in to comment.