fraggle 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/fraggle.rb CHANGED
@@ -4,8 +4,22 @@ require 'uri'
4
4
  module Fraggle
5
5
 
6
6
  def self.connect(uri, *args)
7
- uri = URI(uri)
8
- c = EM.connect(uri.host, uri.port, Client, uri, *args)
7
+ params = uri.gsub(/^doozer:\?/, '').split("&")
8
+ addrs = []
9
+
10
+ params.each do |param|
11
+ k, v = param.split("=")
12
+ if k == "ca" && v =~ /^[\d.]+:\d+$/
13
+ addrs << v
14
+ end
15
+ end
16
+
17
+ if addrs.empty?
18
+ fail "The URI (#{uri}) does not contain valid addresses"
19
+ end
20
+
21
+ host, port = addrs.first.split(":")
22
+ c = EM.connect(host, port, Client, addrs, *args)
9
23
  Snap.new(0, c)
10
24
  end
11
25
 
@@ -3,6 +3,7 @@ require 'fraggle/meta'
3
3
  require 'fraggle/protocol'
4
4
  require 'fraggle/request'
5
5
  require 'fraggle/response'
6
+ require 'set'
6
7
  require 'uri'
7
8
 
8
9
  module Fraggle
@@ -18,12 +19,9 @@ module Fraggle
18
19
  MaxTag = (1<<32)
19
20
 
20
21
 
21
- def initialize(uri)
22
- # Simplied for now. Later we'll take a real uri
23
- # and disect it to init the addrs list
24
- uri = URI(uri.to_s)
25
-
26
- @addr = [uri.host, uri.port] * ":"
22
+ def initialize(addrs)
23
+ @addr = addrs.shift
24
+ @init = addrs
27
25
  @addrs = {}
28
26
  @shun = {}
29
27
  @cbx = {}
@@ -259,8 +257,8 @@ module Fraggle
259
257
  end
260
258
 
261
259
  waw = Proc.new do |e|
262
- if e.value == ""
263
- addr = @addrs.delete(e.path)
260
+ if e.value != ""
261
+ addr = @addrs.delete(e.value)
264
262
  if addr
265
263
  error "noticed #{addr} is gone; removing"
266
264
  end
@@ -283,8 +281,15 @@ module Fraggle
283
281
  end
284
282
  end
285
283
 
286
- watch "/doozer/slot/*", &waw
287
- walk 0, "/doozer/slot/*", &waw
284
+ watch("/doozer/slot/*", &waw)
285
+
286
+ w = walk(0, "/doozer/slot/*", &waw)
287
+ w.done do
288
+ # We have the best known addrs; We can clear the initial
289
+ # ones given at inception.
290
+ debug "addrs list complete; clearing init addrs"
291
+ @init.clear
292
+ end
288
293
  end
289
294
 
290
295
  # What happens when a connection is closed for any reason.
@@ -300,7 +305,14 @@ module Fraggle
300
305
  # has been complete, we'll start the timer again.
301
306
  EM.cancel_timer(@timer)
302
307
 
303
- _, @addr = @addrs.shift rescue nil
308
+ # Attempt to use an addr given to us by a Doozer
309
+ _, @addr = @addrs.shift
310
+
311
+ if ! @addr
312
+ # As a last resort, try one of the addresses given
313
+ # at inception.
314
+ @addr = @init.shift
315
+ end
304
316
 
305
317
  if ! @addr
306
318
  # We are all out of addresses to try
@@ -8,7 +8,7 @@ class FraggleClientTest < Test::Unit::TestCase
8
8
  attr_reader :c, :blk
9
9
 
10
10
  def setup
11
- @c = TestClient.new("doozer://127.0.0.1:8046")
11
+ @c = TestClient.new("doozer:?ca=127.0.0.1:8046")
12
12
  @blk = Blk.new
13
13
  end
14
14
 
@@ -82,7 +82,7 @@ class FraggleProtocolTest < Test::Unit::TestCase
82
82
 
83
83
  def initialize
84
84
  @data = ""
85
- super("doozer://127.0.0.1:8046")
85
+ super("doozer:?ca=127.0.0.1:8046")
86
86
  end
87
87
 
88
88
  def send_data(data)
@@ -7,7 +7,7 @@ class FraggleSnapTest < Test::Unit::TestCase
7
7
  attr_reader :c, :blk
8
8
 
9
9
  def setup
10
- cl = TestClient.new("doozer://127.0.0.1:8046")
10
+ cl = TestClient.new("doozer:?ca=127.0.0.1:8046")
11
11
  @c = Fraggle::Snap.new(1, cl)
12
12
  @blk = Blk.new
13
13
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 2
9
- version: 0.2.2
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Blake Mizerany