zookeeper-ng 1.5.2.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.ctags_paths +1 -0
  3. data/.dotfiles/ruby-gemset +1 -0
  4. data/.dotfiles/ruby-version +1 -0
  5. data/.dotfiles/rvmrc +2 -0
  6. data/.github/workflows/build.yml +57 -0
  7. data/.gitignore +19 -0
  8. data/.gitmodules +3 -0
  9. data/CHANGELOG +408 -0
  10. data/Gemfile +30 -0
  11. data/Guardfile +8 -0
  12. data/LICENSE +23 -0
  13. data/Manifest +29 -0
  14. data/README.markdown +62 -0
  15. data/Rakefile +121 -0
  16. data/cause-abort.rb +117 -0
  17. data/ext/.gitignore +6 -0
  18. data/ext/Rakefile +41 -0
  19. data/ext/c_zookeeper.rb +398 -0
  20. data/ext/common.h +17 -0
  21. data/ext/dbg.h +53 -0
  22. data/ext/depend +5 -0
  23. data/ext/event_lib.c +740 -0
  24. data/ext/event_lib.h +175 -0
  25. data/ext/extconf.rb +103 -0
  26. data/ext/generate_gvl_code.rb +321 -0
  27. data/ext/patches/zkc-3.3.5-network.patch +24 -0
  28. data/ext/patches/zkc-3.4.5-buffer-overflow.patch +11 -0
  29. data/ext/patches/zkc-3.4.5-config.patch +5454 -0
  30. data/ext/patches/zkc-3.4.5-fetch-and-add.patch +16 -0
  31. data/ext/patches/zkc-3.4.5-logging.patch +41 -0
  32. data/ext/patches/zkc-3.4.5-out-of-order-ping.patch +163 -0
  33. data/ext/patches/zkc-3.4.5-yosemite-htonl-fix.patch +102 -0
  34. data/ext/zkc-3.4.5.tar.gz +0 -0
  35. data/ext/zkrb.c +1080 -0
  36. data/ext/zkrb_wrapper.c +775 -0
  37. data/ext/zkrb_wrapper.h +350 -0
  38. data/ext/zkrb_wrapper_compat.c +15 -0
  39. data/ext/zkrb_wrapper_compat.h +11 -0
  40. data/ext/zookeeper_base.rb +256 -0
  41. data/java/java_base.rb +501 -0
  42. data/lib/zookeeper/acls.rb +44 -0
  43. data/lib/zookeeper/callbacks.rb +108 -0
  44. data/lib/zookeeper/client.rb +30 -0
  45. data/lib/zookeeper/client_methods.rb +282 -0
  46. data/lib/zookeeper/common/queue_with_pipe.rb +110 -0
  47. data/lib/zookeeper/common.rb +122 -0
  48. data/lib/zookeeper/compatibility.rb +138 -0
  49. data/lib/zookeeper/constants.rb +97 -0
  50. data/lib/zookeeper/continuation.rb +223 -0
  51. data/lib/zookeeper/core_ext.rb +58 -0
  52. data/lib/zookeeper/em_client.rb +55 -0
  53. data/lib/zookeeper/exceptions.rb +135 -0
  54. data/lib/zookeeper/forked.rb +19 -0
  55. data/lib/zookeeper/latch.rb +34 -0
  56. data/lib/zookeeper/logger/forwarding_logger.rb +84 -0
  57. data/lib/zookeeper/logger.rb +39 -0
  58. data/lib/zookeeper/monitor.rb +19 -0
  59. data/lib/zookeeper/rake_tasks.rb +165 -0
  60. data/lib/zookeeper/request_registry.rb +153 -0
  61. data/lib/zookeeper/stat.rb +21 -0
  62. data/lib/zookeeper/version.rb +4 -0
  63. data/lib/zookeeper.rb +115 -0
  64. data/notes.txt +14 -0
  65. data/scripts/upgrade-1.0-sed-alike.rb +46 -0
  66. data/spec/c_zookeeper_spec.rb +51 -0
  67. data/spec/chrooted_connection_spec.rb +83 -0
  68. data/spec/compatibilty_spec.rb +8 -0
  69. data/spec/default_watcher_spec.rb +41 -0
  70. data/spec/em_spec.rb +51 -0
  71. data/spec/ext/zookeeper_base_spec.rb +19 -0
  72. data/spec/forked_connection_spec.rb +122 -0
  73. data/spec/latch_spec.rb +24 -0
  74. data/spec/log4j.properties +17 -0
  75. data/spec/shared/all_success_return_values.rb +10 -0
  76. data/spec/shared/connection_examples.rb +1081 -0
  77. data/spec/spec_helper.rb +61 -0
  78. data/spec/support/00_logging.rb +38 -0
  79. data/spec/support/10_spawn_zookeeper.rb +20 -0
  80. data/spec/support/progress_formatter.rb +15 -0
  81. data/spec/support/zookeeper_spec_helpers.rb +96 -0
  82. data/spec/zookeeper_spec.rb +24 -0
  83. data/zookeeper.gemspec +46 -0
  84. data/zoomonkey/duplicates +3 -0
  85. data/zoomonkey/zoomonkey.rb +194 -0
  86. metadata +185 -0
@@ -0,0 +1,350 @@
1
+ #ifndef ZKRB_WRAPPER_H
2
+ #define ZKRB_WRAPPER_H
3
+ #if 0
4
+
5
+ AUTOGENERATED BY generate_gvl_code.rb
6
+
7
+ #endif
8
+
9
+ #include "ruby.h"
10
+ #include "zookeeper/zookeeper.h"
11
+ #include "zkrb_wrapper_compat.h"
12
+ #include "dbg.h"
13
+
14
+ #define ZKRB_FAIL -1
15
+
16
+ typedef struct {
17
+ zhandle_t *zh;
18
+ int rc;
19
+ } zkrb_zoo_recv_timeout_args_t;
20
+
21
+ typedef struct {
22
+ zhandle_t *zh;
23
+ int rc;
24
+ } zkrb_zoo_state_args_t;
25
+
26
+ typedef struct {
27
+ zhandle_t *zh;
28
+ const char *path;
29
+ const char *value;
30
+ int valuelen;
31
+ const struct ACL_vector *acl;
32
+ int flags;
33
+ string_completion_t completion;
34
+ const void *data;
35
+ int rc;
36
+ } zkrb_zoo_acreate_args_t;
37
+
38
+ typedef struct {
39
+ zhandle_t *zh;
40
+ const char *path;
41
+ int version;
42
+ void_completion_t completion;
43
+ const void *data;
44
+ int rc;
45
+ } zkrb_zoo_adelete_args_t;
46
+
47
+ typedef struct {
48
+ zhandle_t *zh;
49
+ const char *path;
50
+ int watch;
51
+ stat_completion_t completion;
52
+ const void *data;
53
+ int rc;
54
+ } zkrb_zoo_aexists_args_t;
55
+
56
+ typedef struct {
57
+ zhandle_t *zh;
58
+ const char *path;
59
+ watcher_fn watcher;
60
+ void* watcherCtx;
61
+ stat_completion_t completion;
62
+ const void *data;
63
+ int rc;
64
+ } zkrb_zoo_awexists_args_t;
65
+
66
+ typedef struct {
67
+ zhandle_t *zh;
68
+ const char *path;
69
+ int watch;
70
+ data_completion_t completion;
71
+ const void *data;
72
+ int rc;
73
+ } zkrb_zoo_aget_args_t;
74
+
75
+ typedef struct {
76
+ zhandle_t *zh;
77
+ const char *path;
78
+ watcher_fn watcher;
79
+ void* watcherCtx;
80
+ data_completion_t completion;
81
+ const void *data;
82
+ int rc;
83
+ } zkrb_zoo_awget_args_t;
84
+
85
+ typedef struct {
86
+ zhandle_t *zh;
87
+ const char *path;
88
+ const char *buffer;
89
+ int buflen;
90
+ int version;
91
+ stat_completion_t completion;
92
+ const void *data;
93
+ int rc;
94
+ } zkrb_zoo_aset_args_t;
95
+
96
+ typedef struct {
97
+ zhandle_t *zh;
98
+ const char *path;
99
+ int watch;
100
+ strings_completion_t completion;
101
+ const void *data;
102
+ int rc;
103
+ } zkrb_zoo_aget_children_args_t;
104
+
105
+ typedef struct {
106
+ zhandle_t *zh;
107
+ const char *path;
108
+ watcher_fn watcher;
109
+ void* watcherCtx;
110
+ strings_completion_t completion;
111
+ const void *data;
112
+ int rc;
113
+ } zkrb_zoo_awget_children_args_t;
114
+
115
+ typedef struct {
116
+ zhandle_t *zh;
117
+ const char *path;
118
+ int watch;
119
+ strings_stat_completion_t completion;
120
+ const void *data;
121
+ int rc;
122
+ } zkrb_zoo_aget_children2_args_t;
123
+
124
+ typedef struct {
125
+ zhandle_t *zh;
126
+ const char *path;
127
+ watcher_fn watcher;
128
+ void* watcherCtx;
129
+ strings_stat_completion_t completion;
130
+ const void *data;
131
+ int rc;
132
+ } zkrb_zoo_awget_children2_args_t;
133
+
134
+ typedef struct {
135
+ zhandle_t *zh;
136
+ const char *path;
137
+ string_completion_t completion;
138
+ const void *data;
139
+ int rc;
140
+ } zkrb_zoo_async_args_t;
141
+
142
+ typedef struct {
143
+ zhandle_t *zh;
144
+ const char *path;
145
+ acl_completion_t completion;
146
+ const void *data;
147
+ int rc;
148
+ } zkrb_zoo_aget_acl_args_t;
149
+
150
+ typedef struct {
151
+ zhandle_t *zh;
152
+ const char *path;
153
+ int version;
154
+ struct ACL_vector *acl;
155
+ void_completion_t completion;
156
+ const void *data;
157
+ int rc;
158
+ } zkrb_zoo_aset_acl_args_t;
159
+
160
+ typedef struct {
161
+ zhandle_t *zh;
162
+ int count;
163
+ const zoo_op_t *ops;
164
+ zoo_op_result_t *results;
165
+ void_completion_t completion;
166
+ const void *data;
167
+ int rc;
168
+ } zkrb_zoo_amulti_args_t;
169
+
170
+ typedef struct {
171
+ zhandle_t *zh;
172
+ const char* scheme;
173
+ const char* cert;
174
+ int certLen;
175
+ void_completion_t completion;
176
+ const void *data;
177
+ int rc;
178
+ } zkrb_zoo_add_auth_args_t;
179
+
180
+ typedef struct {
181
+ zhandle_t *zh;
182
+ const char *path;
183
+ const char *value;
184
+ int valuelen;
185
+ const struct ACL_vector *acl;
186
+ int flags;
187
+ char *path_buffer;
188
+ int path_buffer_len;
189
+ int rc;
190
+ } zkrb_zoo_create_args_t;
191
+
192
+ typedef struct {
193
+ zhandle_t *zh;
194
+ const char *path;
195
+ int version;
196
+ int rc;
197
+ } zkrb_zoo_delete_args_t;
198
+
199
+ typedef struct {
200
+ zhandle_t *zh;
201
+ const char *path;
202
+ int watch;
203
+ struct Stat *stat;
204
+ int rc;
205
+ } zkrb_zoo_exists_args_t;
206
+
207
+ typedef struct {
208
+ zhandle_t *zh;
209
+ const char *path;
210
+ watcher_fn watcher;
211
+ void* watcherCtx;
212
+ struct Stat *stat;
213
+ int rc;
214
+ } zkrb_zoo_wexists_args_t;
215
+
216
+ typedef struct {
217
+ zhandle_t *zh;
218
+ const char *path;
219
+ int watch;
220
+ char *buffer;
221
+ int* buffer_len;
222
+ struct Stat *stat;
223
+ int rc;
224
+ } zkrb_zoo_get_args_t;
225
+
226
+ typedef struct {
227
+ zhandle_t *zh;
228
+ const char *path;
229
+ watcher_fn watcher;
230
+ void* watcherCtx;
231
+ char *buffer;
232
+ int* buffer_len;
233
+ struct Stat *stat;
234
+ int rc;
235
+ } zkrb_zoo_wget_args_t;
236
+
237
+ typedef struct {
238
+ zhandle_t *zh;
239
+ const char *path;
240
+ const char *buffer;
241
+ int buflen;
242
+ int version;
243
+ int rc;
244
+ } zkrb_zoo_set_args_t;
245
+
246
+ typedef struct {
247
+ zhandle_t *zh;
248
+ const char *path;
249
+ const char *buffer;
250
+ int buflen;
251
+ int version;
252
+ struct Stat *stat;
253
+ int rc;
254
+ } zkrb_zoo_set2_args_t;
255
+
256
+ typedef struct {
257
+ zhandle_t *zh;
258
+ const char *path;
259
+ int watch;
260
+ struct String_vector *strings;
261
+ int rc;
262
+ } zkrb_zoo_get_children_args_t;
263
+
264
+ typedef struct {
265
+ zhandle_t *zh;
266
+ const char *path;
267
+ watcher_fn watcher;
268
+ void* watcherCtx;
269
+ struct String_vector *strings;
270
+ int rc;
271
+ } zkrb_zoo_wget_children_args_t;
272
+
273
+ typedef struct {
274
+ zhandle_t *zh;
275
+ const char *path;
276
+ int watch;
277
+ struct String_vector *strings;
278
+ struct Stat *stat;
279
+ int rc;
280
+ } zkrb_zoo_get_children2_args_t;
281
+
282
+ typedef struct {
283
+ zhandle_t *zh;
284
+ const char *path;
285
+ watcher_fn watcher;
286
+ void* watcherCtx;
287
+ struct String_vector *strings;
288
+ struct Stat *stat;
289
+ int rc;
290
+ } zkrb_zoo_wget_children2_args_t;
291
+
292
+ typedef struct {
293
+ zhandle_t *zh;
294
+ const char *path;
295
+ struct ACL_vector *acl;
296
+ struct Stat *stat;
297
+ int rc;
298
+ } zkrb_zoo_get_acl_args_t;
299
+
300
+ typedef struct {
301
+ zhandle_t *zh;
302
+ const char *path;
303
+ int version;
304
+ const struct ACL_vector *acl;
305
+ int rc;
306
+ } zkrb_zoo_set_acl_args_t;
307
+
308
+ typedef struct {
309
+ zhandle_t *zh;
310
+ int count;
311
+ const zoo_op_t *ops;
312
+ zoo_op_result_t *results;
313
+ int rc;
314
+ } zkrb_zoo_multi_args_t;
315
+
316
+ int zkrb_call_zoo_recv_timeout(zhandle_t *zh);
317
+ int zkrb_call_zoo_state(zhandle_t *zh);
318
+ int zkrb_call_zoo_acreate(zhandle_t *zh, const char *path, const char *value, int valuelen, const struct ACL_vector *acl, int flags, string_completion_t completion, const void *data);
319
+ int zkrb_call_zoo_adelete(zhandle_t *zh, const char *path, int version, void_completion_t completion, const void *data);
320
+ int zkrb_call_zoo_aexists(zhandle_t *zh, const char *path, int watch, stat_completion_t completion, const void *data);
321
+ int zkrb_call_zoo_awexists(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, stat_completion_t completion, const void *data);
322
+ int zkrb_call_zoo_aget(zhandle_t *zh, const char *path, int watch, data_completion_t completion, const void *data);
323
+ int zkrb_call_zoo_awget(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, data_completion_t completion, const void *data);
324
+ int zkrb_call_zoo_aset(zhandle_t *zh, const char *path, const char *buffer, int buflen, int version, stat_completion_t completion, const void *data);
325
+ int zkrb_call_zoo_aget_children(zhandle_t *zh, const char *path, int watch, strings_completion_t completion, const void *data);
326
+ int zkrb_call_zoo_awget_children(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, strings_completion_t completion, const void *data);
327
+ int zkrb_call_zoo_aget_children2(zhandle_t *zh, const char *path, int watch, strings_stat_completion_t completion, const void *data);
328
+ int zkrb_call_zoo_awget_children2(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, strings_stat_completion_t completion, const void *data);
329
+ int zkrb_call_zoo_async(zhandle_t *zh, const char *path, string_completion_t completion, const void *data);
330
+ int zkrb_call_zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion, const void *data);
331
+ int zkrb_call_zoo_aset_acl(zhandle_t *zh, const char *path, int version, struct ACL_vector *acl, void_completion_t completion, const void *data);
332
+ int zkrb_call_zoo_amulti(zhandle_t *zh, int count, const zoo_op_t *ops, zoo_op_result_t *results, void_completion_t completion, const void *data);
333
+ int zkrb_call_zoo_add_auth(zhandle_t *zh, const char* scheme, const char* cert, int certLen, void_completion_t completion, const void *data);
334
+ int zkrb_call_zoo_create(zhandle_t *zh, const char *path, const char *value, int valuelen, const struct ACL_vector *acl, int flags, char *path_buffer, int path_buffer_len);
335
+ int zkrb_call_zoo_delete(zhandle_t *zh, const char *path, int version);
336
+ int zkrb_call_zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat);
337
+ int zkrb_call_zoo_wexists(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, struct Stat *stat);
338
+ int zkrb_call_zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer, int* buffer_len, struct Stat *stat);
339
+ int zkrb_call_zoo_wget(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, char *buffer, int* buffer_len, struct Stat *stat);
340
+ int zkrb_call_zoo_set(zhandle_t *zh, const char *path, const char *buffer, int buflen, int version);
341
+ int zkrb_call_zoo_set2(zhandle_t *zh, const char *path, const char *buffer, int buflen, int version, struct Stat *stat);
342
+ int zkrb_call_zoo_get_children(zhandle_t *zh, const char *path, int watch, struct String_vector *strings);
343
+ int zkrb_call_zoo_wget_children(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, struct String_vector *strings);
344
+ int zkrb_call_zoo_get_children2(zhandle_t *zh, const char *path, int watch, struct String_vector *strings, struct Stat *stat);
345
+ int zkrb_call_zoo_wget_children2(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, struct String_vector *strings, struct Stat *stat);
346
+ int zkrb_call_zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl, struct Stat *stat);
347
+ int zkrb_call_zoo_set_acl(zhandle_t *zh, const char *path, int version, const struct ACL_vector *acl);
348
+ int zkrb_call_zoo_multi(zhandle_t *zh, int count, const zoo_op_t *ops, zoo_op_result_t *results);
349
+
350
+ #endif /* ZKRB_WRAPPER_H */
@@ -0,0 +1,15 @@
1
+ #include "ruby.h"
2
+ #include "zkrb_wrapper_compat.h"
3
+
4
+
5
+ VALUE zkrb_thread_blocking_region(zkrb_blocking_function_t *func, void *data1) {
6
+
7
+ #ifdef HAVE_RB_THREAD_BLOCKING_REGION
8
+ return rb_thread_blocking_region((rb_blocking_function_t *)func, data1, RUBY_UBF_IO, 0);
9
+ #else
10
+ return func(data1);
11
+ #endif
12
+
13
+ }
14
+
15
+ // vim:sts=2:sw=2:et
@@ -0,0 +1,11 @@
1
+ #ifndef ZKRB_WRAPPER_COMPAT_H
2
+ #define ZKRB_WRAPPER_COMPAT_H
3
+
4
+ typedef VALUE zkrb_blocking_function_t(void *);
5
+ typedef void zkrb_unblock_function_t(void *);
6
+
7
+ // delegates to rb_thread_blocking_region on 1.9.x, always uses UBF_IO
8
+ VALUE zkrb_thread_blocking_region(zkrb_blocking_function_t *func, void *data1);
9
+
10
+
11
+ #endif /* ZKRB_WRAPPER_COMPAT_H */
@@ -0,0 +1,256 @@
1
+ require 'forwardable'
2
+
3
+ Zookeeper.require_root 'ext/c_zookeeper'
4
+
5
+ # The low-level wrapper-specific methods for the C lib
6
+ # subclassed by the top-level Zookeeper class
7
+ module Zookeeper
8
+ class ZookeeperBase
9
+ extend Forwardable
10
+ include Forked
11
+ include Common # XXX: clean this up, no need to include *everything*
12
+ include Callbacks
13
+ include Constants
14
+ include Exceptions
15
+ include ACLs
16
+ include Logger
17
+
18
+ attr_accessor :original_pid
19
+
20
+ # @private
21
+ class ClientShutdownException < StandardError; end
22
+
23
+ # debug levels
24
+ ZOO_LOG_LEVEL_ERROR = 1
25
+ ZOO_LOG_LEVEL_WARN = 2
26
+ ZOO_LOG_LEVEL_INFO = 3
27
+ ZOO_LOG_LEVEL_DEBUG = 4
28
+
29
+ def_delegators :czk, :get_children, :exists, :delete, :get, :set,
30
+ :set_acl, :get_acl, :client_id, :sync, :add_auth, :wait_until_connected,
31
+ :connected_host
32
+
33
+ def self.threadsafe_inquisitor(*syms)
34
+ syms.each do |sym|
35
+ class_eval(<<-EOM, __FILE__, __LINE__+1)
36
+ def #{sym}
37
+ c = @mutex.synchronize { @czk }
38
+ false|(c && c.#{sym})
39
+ end
40
+ EOM
41
+ end
42
+ end
43
+
44
+ threadsafe_inquisitor :connected?, :connecting?, :associating?, :running?,
45
+ :shutting_down?
46
+
47
+ attr_reader :event_queue
48
+
49
+ # this method may be called in either the fork case, or from the constructor
50
+ # to set up this state initially (so all of this is in one location). we rely
51
+ # on the forked? method to determine which it is
52
+ def reopen_after_fork!
53
+ logger.debug { "#{self.class}##{__method__} fork detected!" } if forked?
54
+
55
+ @mutex = Monitor.new
56
+ @dispatch_shutdown_cond = @mutex.new_cond
57
+ @event_queue = QueueWithPipe.new
58
+
59
+ @dispatcher = nil if @dispatcher and not @dispatcher.alive?
60
+
61
+ update_pid! # from Forked
62
+ end
63
+ private :reopen_after_fork!
64
+
65
+ def reopen(timeout = 10, watcher=nil, opts = {})
66
+ raise "You cannot set the watcher to a different value this way anymore!" if watcher
67
+
68
+ reopen_after_fork! if forked?
69
+
70
+ @mutex.synchronize do
71
+ @czk.close if @czk
72
+ @czk = CZookeeper.new(@host, @event_queue, opts)
73
+
74
+ # flushes all outstanding watcher reqs.
75
+ @req_registry.clear_watchers!
76
+
77
+ @czk.wait_until_connected(timeout)
78
+ end
79
+
80
+ setup_dispatch_thread!
81
+ state
82
+ end
83
+
84
+ def initialize(host, timeout = 10, watcher=nil, opts = {})
85
+ # approximate the java behavior of raising java.lang.IllegalArgumentException if the host
86
+ # argument ends with '/'
87
+ raise ArgumentError, "Host argument #{host.inspect} may not end with /" if host.end_with?('/')
88
+
89
+ @host = host.dup
90
+
91
+ watcher ||= get_default_global_watcher
92
+
93
+ @req_registry = RequestRegistry.new(watcher, :chroot_path => chroot_path)
94
+
95
+ @dispatcher = @czk = nil
96
+
97
+ update_pid!
98
+ reopen_after_fork!
99
+
100
+ yield self if block_given?
101
+
102
+ reopen(timeout, nil, opts)
103
+ end
104
+
105
+ # if either of these happen, the user will need to renegotiate a connection via reopen
106
+ def assert_open
107
+ @mutex.synchronize do
108
+ raise Exceptions::NotConnected if !@czk or @czk.closed?
109
+ if forked?
110
+ raise InheritedConnectionError, <<-EOS.gsub(/(?:^|\n)\s*/, ' ').strip
111
+ You tried to use a connection inherited from another process
112
+ (original pid: #{original_pid}, your pid: #{Process.pid})
113
+ You need to call reopen() after forking
114
+ EOS
115
+ end
116
+ end
117
+ end
118
+
119
+ # do not lock, do not mutex, just close the underlying handle this is
120
+ # potentially dangerous and should only be called after a fork() to close
121
+ # this instance
122
+ def close!
123
+ inst, @czk = @czk, nil
124
+ inst && inst.close
125
+ end
126
+
127
+ # close the connection normally, stops the dispatch thread and closes the
128
+ # underlying connection cleanly
129
+ def close
130
+ sd_thread = nil
131
+
132
+ @mutex.synchronize do
133
+ return unless @czk
134
+ inst, @czk = @czk, nil
135
+
136
+ sd_thread = Thread.new(inst) do |_inst|
137
+ stop_dispatch_thread!
138
+ _inst.close
139
+ end
140
+ end
141
+
142
+ # if we're on the event dispatch thread for some stupid reason, then don't join
143
+ unless event_dispatch_thread?
144
+ # hard-coded 30 second delay, don't hang forever
145
+ if sd_thread.join(30) != sd_thread
146
+ logger.error { "timed out waiting for shutdown thread to exit" }
147
+ end
148
+ end
149
+
150
+ nil
151
+ end
152
+
153
+ # the C lib doesn't strip the chroot path off of returned path values, which
154
+ # is pretty damn annoying. this is used to clean things up.
155
+ def create(*args)
156
+ # since we don't care about the inputs, just glob args
157
+ rc, new_path = czk.create(*args)
158
+ [rc, @req_registry.strip_chroot_from(new_path)]
159
+ end
160
+
161
+ def set_debug_level(int)
162
+ warn "DEPRECATION WARNING: #{self.class.name}#set_debug_level, it has moved to the class level and will be removed in a future release"
163
+ self.class.set_debug_level(int)
164
+ end
165
+
166
+ # set the watcher object/proc that will receive all global events (such as session/state events)
167
+ def set_default_global_watcher
168
+ raise "NO! YOU CANNOT HAZ set_default_global_watcher"
169
+ end
170
+
171
+ def state
172
+ return ZOO_CLOSED_STATE if closed?
173
+ czk.state
174
+ end
175
+
176
+ def session_id
177
+ @mutex.synchronize do
178
+ cid = client_id and cid.session_id
179
+ end
180
+ end
181
+
182
+ def session_passwd
183
+ @mutex.synchronize do
184
+ cid = client_id and cid.passwd
185
+ end
186
+ end
187
+
188
+ # we are closed if there is no @czk instance or @czk.closed?
189
+ def closed?
190
+ czk.closed?
191
+ rescue Exceptions::NotConnected
192
+ true
193
+ end
194
+
195
+ def pause_before_fork_in_parent
196
+ @mutex.synchronize do
197
+ logger.debug { "ZookeeperBase#pause_before_fork_in_parent" }
198
+
199
+ # XXX: add anal-retentive state checking
200
+ raise "EXPLODERATE! @czk was nil!" unless @czk
201
+
202
+ @czk.pause_before_fork_in_parent
203
+ stop_dispatch_thread!
204
+ end
205
+ end
206
+
207
+ def resume_after_fork_in_parent
208
+ @mutex.synchronize do
209
+ logger.debug { "ZookeeperBase#resume_after_fork_in_parent" }
210
+
211
+ raise "EXPLODERATE! @czk was nil!" unless @czk
212
+
213
+ event_queue.open
214
+ setup_dispatch_thread!
215
+ @czk.resume_after_fork_in_parent
216
+ end
217
+ end
218
+
219
+ protected
220
+ def czk
221
+ rval = @mutex.synchronize { @czk }
222
+ raise Exceptions::NotConnected, "underlying connection was nil" unless rval
223
+ rval
224
+ end
225
+
226
+ # if we're chrooted, this method will strip the chroot prefix from +path+
227
+ def strip_chroot_from(path)
228
+ return path unless (chrooted? and path and path.start_with?(chroot_path))
229
+ path[chroot_path.length..-1]
230
+ end
231
+
232
+ def get_default_global_watcher
233
+ Proc.new { |args|
234
+ logger.debug { "Ruby ZK Global CB called type=#{event_by_value(args[:type])} state=#{state_by_value(args[:state])}" }
235
+ true
236
+ }
237
+ end
238
+
239
+ def chrooted?
240
+ !chroot_path.empty?
241
+ end
242
+
243
+ def chroot_path
244
+ if @chroot_path.nil?
245
+ @chroot_path =
246
+ if idx = @host.index('/')
247
+ @host.slice(idx, @host.length)
248
+ else
249
+ ''
250
+ end
251
+ end
252
+
253
+ @chroot_path
254
+ end
255
+ end
256
+ end