Class: Fraggle::Block::Client
- Inherits:
-
Object
- Object
- Fraggle::Block::Client
show all
- Includes:
- Request::Verb
- Defined in:
- lib/fraggle/block/client.rb
Defined Under Namespace
Classes: NoMoreAddrs
Constant Summary
collapse
- MaxInt64 =
1<<63 - 1
Request::Verb::DEL, Request::Verb::GET, Request::Verb::GETDIR, Request::Verb::NOP, Request::Verb::REV, Request::Verb::SET, Request::Verb::STAT, Request::Verb::WAIT, Request::Verb::WALK
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(addrs = []) ⇒ Client
Returns a new instance of Client.
15
16
17
18
|
# File 'lib/fraggle/block/client.rb', line 15
def initialize(addrs = [])
@addrs = addrs
connect
end
|
Instance Attribute Details
#addrs ⇒ Object
Returns the value of attribute addrs.
12
13
14
|
# File 'lib/fraggle/block/client.rb', line 12
def addrs
@addrs
end
|
#connection ⇒ Object
Returns the value of attribute connection.
13
14
15
|
# File 'lib/fraggle/block/client.rb', line 13
def connection
@connection
end
|
Instance Method Details
#connect ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/fraggle/block/client.rb', line 49
def connect
begin
host, port = @addrs.shift.split(":")
@connection = Connection.new(host, port)
find_all_of_the_nodes
rescue => e
retry if @addrs.any?
raise(NoMoreAddrs)
end
end
|
#del(rev, path) ⇒ Object
32
33
34
|
# File 'lib/fraggle/block/client.rb', line 32
def del(rev, path)
send(:verb => DEL, :rev => rev, :path => path)
end
|
#disconnect ⇒ Object
40
41
42
|
# File 'lib/fraggle/block/client.rb', line 40
def disconnect
@connection.disconnect
end
|
#find_all_of_the_nodes ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/fraggle/block/client.rb', line 60
def find_all_of_the_nodes
r = rev.rev
i = 0
loop do
res = walk(r, "/ctl/node/*/addr", i)
if res.ok?
i += 1
@addrs << res.value if !(@addrs.include?(res.value))
else
break
end
end
end
|
#get(rev, path) ⇒ Object
24
25
26
|
# File 'lib/fraggle/block/client.rb', line 24
def get(rev, path)
send(:verb => GET, :rev => rev, :path => path)
end
|
#reconnect ⇒ Object
44
45
46
47
|
# File 'lib/fraggle/block/client.rb', line 44
def reconnect
disconnect
connect
end
|
#rev ⇒ Object
20
21
22
|
# File 'lib/fraggle/block/client.rb', line 20
def rev
send(:verb => REV)
end
|
#set(rev, path, value) ⇒ Object
28
29
30
|
# File 'lib/fraggle/block/client.rb', line 28
def set(rev, path, value)
send(:verb => SET, :rev => rev, :path => path, :value => value)
end
|
#walk(rev, path, offset) ⇒ Object
36
37
38
|
# File 'lib/fraggle/block/client.rb', line 36
def walk(rev, path, offset)
send(:verb => WALK, :rev => rev, :path => path, :offset => offset)
end
|