zk-eventmachine 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.dev_extras/rvmrc +1 -1
- data/.gitignore +1 -0
- data/Gemfile +1 -1
- data/README.markdown +86 -2
- data/lib/z_k/z_k_event_machine/version.rb +1 -1
- data/zk-eventmachine.gemspec +1 -1
- metadata +7 -7
data/.dev_extras/rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm 1.9.2
|
1
|
+
rvm 1.9.2@zk-em
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -1,8 +1,92 @@
|
|
1
|
-
##
|
1
|
+
## ZKEventMachine
|
2
2
|
|
3
|
-
[ZK][] client implementation for [EventMachine][]
|
3
|
+
ZKEventMachine is a [ZK][] client implementation for [EventMachine][] for interacting with the Apache [ZooKeeper][] server. It provides the core functionality of [ZK][], but in a single-threaded context with a callback-based API. It is tested on [JRuby][], and [MRI][] versions 1.8.7 and 1.9.2. [Rubinius][] 1.2.x _should_ work, but support should be considered experimental at this point (if you find a bug, please [report it][], and I'll do my best to fix it).
|
4
4
|
|
5
|
+
### Quickstart
|
6
|
+
|
7
|
+
Installation via rubygems is recommended, as there are a few dependencies.
|
8
|
+
|
9
|
+
$ gem install zk-eventmachine
|
10
|
+
|
11
|
+
This will install [ZK][] and [slyphon-zookeeper][] _(as a side note, for experimentation in irb, it's probably easier to use [ZK][] due to its synchronous nature)_.
|
12
|
+
|
13
|
+
### Connecting
|
14
|
+
|
15
|
+
Connections are easy to set up, and take the same host string argument that the ZK and Zookeeper use.
|
16
|
+
|
17
|
+
# a connection to a single server:
|
18
|
+
|
19
|
+
zkem = ZK::ZKEventMachine::Client.new("localhost:2181")
|
20
|
+
|
21
|
+
zkem.connect do
|
22
|
+
# the client is connected when this block is called
|
23
|
+
end
|
24
|
+
|
25
|
+
_Note: at the moment, the [chroot-style][] syntax is iffy and needs some attention._
|
26
|
+
|
27
|
+
Closing a connection should be done in the same style, by passing a block to the _close_ method.
|
28
|
+
|
29
|
+
zkem.close do
|
30
|
+
# connection is closed when this block is called
|
31
|
+
end
|
32
|
+
|
33
|
+
Due to the way that the underlying [slyphon-zookeeper][] code is written, it is important that you not stop the reactor until the `on_close` callback has fired (especially when using `epoll` on linux). Strange things may happen if you do not wait for the connection to be closed!
|
34
|
+
|
35
|
+
|
36
|
+
### Callbacks
|
37
|
+
|
38
|
+
ZKEventMachine was written so that every call can handle two callback styles. The first is node-js style:
|
39
|
+
|
40
|
+
zkem.get('/') do |exception,value,stat|
|
41
|
+
end
|
42
|
+
|
43
|
+
In this style, the first value returned to the block is an Exception object if an error occured, or nil if the operation was successful. The rest of the arguments are the same as they would be returned from the synchronous API.
|
44
|
+
|
45
|
+
The second style uses EventMachine::Deferrable (with a few slight modifications), and allows you to add callbacks and errbacks (in something approximating Twisted Python style).
|
46
|
+
|
47
|
+
d = zkem.get('/')
|
48
|
+
|
49
|
+
d.callback do |value,stat|
|
50
|
+
# success
|
51
|
+
end
|
52
|
+
|
53
|
+
d.errback do |exc|
|
54
|
+
# failure
|
55
|
+
end
|
56
|
+
|
57
|
+
The callback/errbacks return self, so you can chain calls:
|
58
|
+
|
59
|
+
zkem.get('/').callback do |value,stat|
|
60
|
+
|
61
|
+
end.errback do |exc|
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
Also provided is an `ensure_that` method that will add the given block to both callback and errback chains:
|
66
|
+
|
67
|
+
# the goalposts |*| below are so that the block can take any number of
|
68
|
+
# args, and ignore them
|
69
|
+
|
70
|
+
zkem.get('/').ensure_that do |*|
|
71
|
+
# clean up
|
72
|
+
end
|
73
|
+
|
74
|
+
### Example Usage
|
75
|
+
|
76
|
+
### Contributing
|
77
|
+
|
78
|
+
### Credits
|
79
|
+
|
80
|
+
ZKEventMachine is developed and maintained by Jonathan Simms and Topper Bowers. The HP Development Corp. has graciously open sourced this project under the MIT License, and special thanks go to [Snapfish][] who allowed us to develop this project.
|
5
81
|
|
6
82
|
[ZK]: https://github.com/slyphon/zk
|
7
83
|
[EventMachine]: https://github.com/eventmachine/eventmachine
|
84
|
+
[ZooKeeper]: http://zookeeper.apache.org/
|
85
|
+
[slyphon-zookeeper]: https://github.com/slyphon/zookeeper
|
86
|
+
[JRuby]: http://jruby.org
|
87
|
+
[MRI]: http://www.ruby-lang.org/
|
88
|
+
[Rubinius]: http://rubini.us
|
89
|
+
[report it]: https://github.com/slyphon/zk-eventmachine/issues
|
90
|
+
[chroot-style]: http://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#ch_zkSessions
|
91
|
+
[Snapfish]: http://www.snapfish.com
|
8
92
|
|
data/zk-eventmachine.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{ZK client for EventMachine-based (async) applications}
|
13
13
|
s.description = s.description
|
14
14
|
|
15
|
-
s.add_dependency('zk', '~> 0.8.
|
15
|
+
s.add_dependency('zk', '~> 0.8.5')
|
16
16
|
|
17
17
|
# zk depends on slyphon-zookeeper, but we need at least this version
|
18
18
|
s.add_dependency('slyphon-zookeeper', '~> 0.2.4')
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zk-eventmachine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonathan D. Simms
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-08-05 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 53
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 8
|
33
|
-
-
|
34
|
-
version: 0.8.
|
33
|
+
- 5
|
34
|
+
version: 0.8.5
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|