zk_client 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -0
- data/lib/zk_client.rb +1 -0
- data/lib/zk_client/version.rb +1 -1
- data/lib/zk_client/zk_cache.rb +62 -0
- data/lib/zk_client/zk_client.rb +9 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1c859b8f21362947850809c2db753179ef70c24
|
4
|
+
data.tar.gz: 217071637b49b2242ec9e532c5e6ac5cb136d8f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc68da86514f25705dbe51dcbb1a72d6cb0d745f8369d60550cee97b3dd7a28c7b1e66ed60e1451f7775f7051436ff6878aef5e837598248cc14d0a306bde895
|
7
|
+
data.tar.gz: 223b748065bcdc6b10e51e843d6c9a568a090935afed1a7359aa1a5d2ddd271154556e4161d64274dbe99f6deb3ef3218bf8be5174425a6c4245644702fe0d53
|
data/README.md
CHANGED
@@ -144,6 +144,24 @@ ZkClient.read_node('/mynode')
|
|
144
144
|
#=> {:req_id=>9, :rc=>-101, :data=>nil, :stat=>#<Zookeeper::Stat:0x00000002803f70 @exists=false>}
|
145
145
|
```
|
146
146
|
|
147
|
+
##### Getting a node's children
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
require 'zk_client'
|
151
|
+
|
152
|
+
# If the root node has children:
|
153
|
+
ZkClient.children('/')
|
154
|
+
#=> ['firstchild', 'secondchild']
|
155
|
+
|
156
|
+
# If the root node has no children:
|
157
|
+
ZkClient.children('/')
|
158
|
+
#=> []
|
159
|
+
|
160
|
+
# If the node you call children on doesn't exist:
|
161
|
+
ZkClient.children('/doesnotexist')
|
162
|
+
#=> nil
|
163
|
+
```
|
164
|
+
|
147
165
|
##### Close connection to ZK
|
148
166
|
|
149
167
|
```ruby
|
@@ -158,6 +176,20 @@ ZkClient.client.connected?
|
|
158
176
|
|
159
177
|
```
|
160
178
|
|
179
|
+
##### Reopen a closed connection or close the existing connection and create a new connection
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
require 'zk_client'
|
183
|
+
|
184
|
+
ZkClient.close
|
185
|
+
#=> nil
|
186
|
+
ZkClient.reopen
|
187
|
+
#=> #<Zookeeper::Client: .....
|
188
|
+
ZkClient.client.connected?
|
189
|
+
#=> true
|
190
|
+
|
191
|
+
```
|
192
|
+
|
161
193
|
##### Access the underlying Zookeeper.new instance
|
162
194
|
```ruby
|
163
195
|
require 'zk_client'
|
data/lib/zk_client.rb
CHANGED
data/lib/zk_client/version.rb
CHANGED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module ZkCache
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def cache(key, value)
|
8
|
+
_cache[key] = value
|
9
|
+
end
|
10
|
+
|
11
|
+
def read(key)
|
12
|
+
path = _process_path(key)
|
13
|
+
_cache[path]
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_cache
|
17
|
+
_load_cache(ZkClient.root_path)
|
18
|
+
self.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def destroy_cache
|
22
|
+
@@cache = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
_cache.to_json
|
27
|
+
end
|
28
|
+
|
29
|
+
def root_path
|
30
|
+
ZkClient.root_path
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def _cache
|
36
|
+
@@cache ||= {}
|
37
|
+
end
|
38
|
+
|
39
|
+
def _process_path(path)
|
40
|
+
path = "/#{path}" unless path.start_with?('/') # We want leading slash
|
41
|
+
path = path[0...-1] if path[-1] == '/' # Remove trailing slash
|
42
|
+
path = "#{root_path}#{path}" unless path.start_with?(root_path)
|
43
|
+
|
44
|
+
path
|
45
|
+
end
|
46
|
+
|
47
|
+
def _load_cache(path)
|
48
|
+
val = ZkClient.read(path)
|
49
|
+
cache(path, val)
|
50
|
+
|
51
|
+
children = ZkClient.children(path)
|
52
|
+
if children && children.any?
|
53
|
+
children.each do |child|
|
54
|
+
_load_cache("#{path}/#{child}")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
data/lib/zk_client/zk_client.rb
CHANGED
@@ -89,7 +89,7 @@ module ZkClient
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def uri=(uri)
|
92
|
-
parsed_uri = URI(uri)
|
92
|
+
parsed_uri = URI(schemeify(uri))
|
93
93
|
|
94
94
|
@@host = parsed_uri.host
|
95
95
|
@@port = parsed_uri.port
|
@@ -118,5 +118,13 @@ module ZkClient
|
|
118
118
|
path
|
119
119
|
end
|
120
120
|
|
121
|
+
def schemeify(uri)
|
122
|
+
if (uri =~ /^http(s)?:\/\/(.)+/) == 0
|
123
|
+
uri
|
124
|
+
else
|
125
|
+
"http://#{uri}"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
121
129
|
end # End class methods
|
122
130
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zk_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Thomas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zookeeper
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- bin/setup
|
99
99
|
- lib/zk_client.rb
|
100
100
|
- lib/zk_client/version.rb
|
101
|
+
- lib/zk_client/zk_cache.rb
|
101
102
|
- lib/zk_client/zk_client.rb
|
102
103
|
- zk_client.gemspec
|
103
104
|
homepage: https://git.autodesk.com/EIS-EA-MOJO/zk_client
|