slyphon-zookeeper 0.2.0-java → 0.2.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/extconf.rb +1 -1
- data/ext/zookeeper_base.rb +22 -8
- data/ext/zookeeper_c.c +6 -2
- data/ext/zookeeper_lib.c +26 -2
- data/lib/zookeeper.rb +1 -0
- data/lib/zookeeper/exceptions.rb +1 -0
- data/slyphon-zookeeper.gemspec +1 -1
- metadata +4 -4
data/ext/extconf.rb
CHANGED
@@ -12,7 +12,7 @@ $CXXFLAGS = " -std=gnu++98 #{$CFLAGS}"
|
|
12
12
|
$CPPFLAGS = $ARCH_FLAG = $DLDFLAGS = ""
|
13
13
|
|
14
14
|
if ENV['DEBUG']
|
15
|
-
puts "Setting debug flags."
|
15
|
+
$stderr.puts "*** Setting debug flags. ***"
|
16
16
|
$CFLAGS << " -O0 -ggdb3 -DHAVE_DEBUG"
|
17
17
|
$EXTRA_CONF = " --enable-debug"
|
18
18
|
$CFLAGS.gsub!(/ -O[^0] /, ' ')
|
data/ext/zookeeper_base.rb
CHANGED
@@ -87,22 +87,24 @@ class ZookeeperBase < CZookeeper
|
|
87
87
|
end
|
88
88
|
|
89
89
|
if @dispatcher
|
90
|
-
|
90
|
+
unless @_closed
|
91
|
+
wake_event_loop!
|
92
|
+
end
|
91
93
|
@dispatcher.join
|
92
94
|
end
|
93
95
|
|
94
96
|
@start_stop_mutex.synchronize do
|
95
97
|
unless @_closed
|
96
98
|
close_handle
|
97
|
-
|
98
|
-
# this is set up in the C init method, but it's easier to
|
99
|
-
# do the teardown here
|
100
|
-
begin
|
101
|
-
@selectable_io.close if @selectable_io
|
102
|
-
rescue IOError
|
103
|
-
end
|
104
99
|
end
|
105
100
|
end
|
101
|
+
|
102
|
+
# this is set up in the C init method, but it's easier to
|
103
|
+
# do the teardown here
|
104
|
+
begin
|
105
|
+
@selectable_io.close if @selectable_io
|
106
|
+
rescue IOError
|
107
|
+
end
|
106
108
|
end
|
107
109
|
|
108
110
|
def set_debug_level(int)
|
@@ -126,7 +128,19 @@ class ZookeeperBase < CZookeeper
|
|
126
128
|
@start_stop_mutex.synchronize { false|@_running }
|
127
129
|
end
|
128
130
|
|
131
|
+
def state
|
132
|
+
return ZOO_CLOSED_STATE if closed?
|
133
|
+
super
|
134
|
+
end
|
135
|
+
|
129
136
|
protected
|
137
|
+
def barf_unless_running!
|
138
|
+
@start_stop_mutex.synchronize do
|
139
|
+
raise ShuttingDownException unless (@_running and not @_closed)
|
140
|
+
yield
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
130
144
|
def setup_dispatch_thread!
|
131
145
|
@dispatcher = Thread.new do
|
132
146
|
while running?
|
data/ext/zookeeper_c.c
CHANGED
@@ -472,6 +472,10 @@ static int is_running(VALUE self) {
|
|
472
472
|
return RTEST(rval);
|
473
473
|
}
|
474
474
|
|
475
|
+
static int is_closed(VALUE self) {
|
476
|
+
VALUE rval = rb_iv_get(self, "@_closed");
|
477
|
+
return RTEST(rval);
|
478
|
+
}
|
475
479
|
|
476
480
|
/* slyphon: NEED TO PROTECT THIS AGAINST SHUTDOWN */
|
477
481
|
|
@@ -484,7 +488,7 @@ static VALUE method_get_next_event(VALUE self, VALUE blocking) {
|
|
484
488
|
// we use the is_running(self) method here because it allows us to have a
|
485
489
|
// ruby-land semaphore that we can also use in the java extension
|
486
490
|
//
|
487
|
-
if (!is_running(self)) {
|
491
|
+
if (is_closed(self) || !is_running(self)) {
|
488
492
|
/* fprintf(stderr, "method_get_next_event: running is false, returning nil\n");*/
|
489
493
|
return Qnil; // this case for shutdown
|
490
494
|
}
|
@@ -517,7 +521,7 @@ static VALUE method_get_next_event(VALUE self, VALUE blocking) {
|
|
517
521
|
rb_raise(rb_eRuntimeError, "read failed: %d", errno);
|
518
522
|
}
|
519
523
|
else if (ZKRBDebugging) {
|
520
|
-
fprintf(stderr, "read %d bytes from the queue's pipe\n", bytes_read);
|
524
|
+
fprintf(stderr, "read %d bytes from the queue (%p)'s pipe\n", bytes_read, zk->queue);
|
521
525
|
}
|
522
526
|
|
523
527
|
continue;
|
data/ext/zookeeper_lib.c
CHANGED
@@ -23,6 +23,16 @@ int ZKRBDebugging;
|
|
23
23
|
|
24
24
|
pthread_mutex_t zkrb_q_mutex = PTHREAD_MUTEX_INITIALIZER;
|
25
25
|
|
26
|
+
|
27
|
+
/********************************************************************************
|
28
|
+
*
|
29
|
+
* NOTE: be *very careful* in these functions, calling *ANY* ruby interpreter
|
30
|
+
* function when you're not in an interpreter thread can hork ruby, trigger a
|
31
|
+
* [BUG], corrupt the stack, kill you dog, knock up your daughter, etc. etc.
|
32
|
+
*
|
33
|
+
*********************************************************************************
|
34
|
+
*/
|
35
|
+
|
26
36
|
/* push/pop is a misnomer, this is a queue */
|
27
37
|
void zkrb_enqueue(zkrb_queue_t *q, zkrb_event_t *elt) {
|
28
38
|
pthread_mutex_lock(&zkrb_q_mutex);
|
@@ -37,8 +47,19 @@ void zkrb_enqueue(zkrb_queue_t *q, zkrb_event_t *elt) {
|
|
37
47
|
q->tail->next = NULL;
|
38
48
|
ssize_t ret = write(q->pipe_write, "0", 1); /* Wake up Ruby listener */
|
39
49
|
pthread_mutex_unlock(&zkrb_q_mutex);
|
40
|
-
|
41
|
-
|
50
|
+
|
51
|
+
// XXX(slyphon): can't raise a ruby exception here as we may not be calling
|
52
|
+
// this from a ruby thread. Calling into the interpreter from a non-ruby
|
53
|
+
// thread is bad, mm'kay?
|
54
|
+
|
55
|
+
if (ZKRBDebugging) {
|
56
|
+
if ((ret == -1)) {
|
57
|
+
fprintf(stderr, "WARNING: write to queue (%p) pipe failed!\n", q);
|
58
|
+
}
|
59
|
+
/* else {*/
|
60
|
+
/* fprintf(stderr, "successfully enqueued event on queue (%p)\n", q);*/
|
61
|
+
/* }*/
|
62
|
+
}
|
42
63
|
}
|
43
64
|
|
44
65
|
zkrb_event_t * zkrb_peek(zkrb_queue_t *q) {
|
@@ -79,6 +100,9 @@ void zkrb_signal(zkrb_queue_t *q) {
|
|
79
100
|
|
80
101
|
zkrb_queue_t *zkrb_queue_alloc(void) {
|
81
102
|
int pfd[2];
|
103
|
+
|
104
|
+
// XXX(slyphon): close-on-exec settings?
|
105
|
+
|
82
106
|
if (pipe(pfd) == -1)
|
83
107
|
rb_raise(rb_eRuntimeError, "create of pipe failed: %d", errno);
|
84
108
|
|
data/lib/zookeeper.rb
CHANGED
data/lib/zookeeper/exceptions.rb
CHANGED
@@ -56,6 +56,7 @@ module ZookeeperExceptions
|
|
56
56
|
# these are Ruby client exceptions
|
57
57
|
class ConnectionClosed < ZookeeperException; end
|
58
58
|
class NotConnected < ZookeeperException; end
|
59
|
+
class ShuttingDownException < ZookeeperException; end
|
59
60
|
|
60
61
|
def self.by_code(code)
|
61
62
|
case code
|
data/slyphon-zookeeper.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "slyphon-zookeeper"
|
6
|
-
s.version = '0.2.
|
6
|
+
s.version = '0.2.1'
|
7
7
|
|
8
8
|
s.authors = ["Phillip Pearson", "Eric Maland", "Evan Weaver", "Brian Wickman", "Neil Conway", "Jonathan D. Simms"]
|
9
9
|
s.email = ["slyphon@gmail.com"]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slyphon-zookeeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: java
|
12
12
|
authors:
|
13
13
|
- Phillip Pearson
|
@@ -20,7 +20,7 @@ autorequire:
|
|
20
20
|
bindir: bin
|
21
21
|
cert_chain: []
|
22
22
|
|
23
|
-
date: 2011-06-
|
23
|
+
date: 2011-06-27 00:00:00 +00:00
|
24
24
|
default_executable:
|
25
25
|
dependencies:
|
26
26
|
- !ruby/object:Gem::Dependency
|