Class: Zookeeper
- Inherits:
-
ZookeeperBase
- Object
- ZookeeperBase
- Zookeeper
- Defined in:
- lib/zookeeper.rb
Direct Known Subclasses
Constant Summary collapse
- @@logger =
Logger.new($stderr).tap { |l| l.level = Logger::ERROR }
Constants inherited from ZookeeperBase
ZookeeperBase::KILL_TOKEN, ZookeeperBase::ZKRB_GLOBAL_CB_REQ, ZookeeperBase::ZOO_LOG_LEVEL_DEBUG, ZookeeperBase::ZOO_LOG_LEVEL_ERROR, ZookeeperBase::ZOO_LOG_LEVEL_INFO, ZookeeperBase::ZOO_LOG_LEVEL_WARN
Constants included from ZookeeperACLs
ZookeeperACLs::ZOO_ANYONE_ID_UNSAFE, ZookeeperACLs::ZOO_AUTH_IDS, ZookeeperACLs::ZOO_CREATOR_ALL_ACL, ZookeeperACLs::ZOO_OPEN_ACL_UNSAFE, ZookeeperACLs::ZOO_PERM_ADMIN, ZookeeperACLs::ZOO_PERM_ALL, ZookeeperACLs::ZOO_PERM_CREATE, ZookeeperACLs::ZOO_PERM_DELETE, ZookeeperACLs::ZOO_PERM_READ, ZookeeperACLs::ZOO_PERM_WRITE, ZookeeperACLs::ZOO_READ_ACL_UNSAFE
Constants included from ZookeeperExceptions
ZookeeperExceptions::ZAPIERROR, ZookeeperExceptions::ZAUTHFAILED, ZookeeperExceptions::ZBADARGUMENTS, ZookeeperExceptions::ZBADVERSION, ZookeeperExceptions::ZCLOSING, ZookeeperExceptions::ZCONNECTIONLOSS, ZookeeperExceptions::ZDATAINCONSISTENCY, ZookeeperExceptions::ZINVALIDACL, ZookeeperExceptions::ZINVALIDCALLBACK, ZookeeperExceptions::ZINVALIDSTATE, ZookeeperExceptions::ZMARSHALLINGERROR, ZookeeperExceptions::ZNOAUTH, ZookeeperExceptions::ZNOCHILDRENFOREPHEMERALS, ZookeeperExceptions::ZNODEEXISTS, ZookeeperExceptions::ZNONODE, ZookeeperExceptions::ZNOTEMPTY, ZookeeperExceptions::ZNOTHING, ZookeeperExceptions::ZOK, ZookeeperExceptions::ZOPERATIONTIMEOUT, ZookeeperExceptions::ZRUNTIMEINCONSISTENCY, ZookeeperExceptions::ZSESSIONEXPIRED, ZookeeperExceptions::ZSESSIONMOVED, ZookeeperExceptions::ZSYSTEMERROR, ZookeeperExceptions::ZUNIMPLEMENTED
Constants included from ZookeeperConstants
ZookeeperConstants::EVENT_TYPE_NAMES, ZookeeperConstants::STATE_NAMES, ZookeeperConstants::ZOO_ASSOCIATING_STATE, ZookeeperConstants::ZOO_AUTH_FAILED_STATE, ZookeeperConstants::ZOO_CHANGED_EVENT, ZookeeperConstants::ZOO_CHILD_EVENT, ZookeeperConstants::ZOO_CLOSED_STATE, ZookeeperConstants::ZOO_CONNECTED_STATE, ZookeeperConstants::ZOO_CONNECTING_STATE, ZookeeperConstants::ZOO_CREATED_EVENT, ZookeeperConstants::ZOO_DELETED_EVENT, ZookeeperConstants::ZOO_EPHEMERAL, ZookeeperConstants::ZOO_EXPIRED_SESSION_STATE, ZookeeperConstants::ZOO_LOG_LEVEL_DEBUG, ZookeeperConstants::ZOO_LOG_LEVEL_ERROR, ZookeeperConstants::ZOO_LOG_LEVEL_INFO, ZookeeperConstants::ZOO_LOG_LEVEL_WARN, ZookeeperConstants::ZOO_NOTWATCHING_EVENT, ZookeeperConstants::ZOO_SEQUENCE, ZookeeperConstants::ZOO_SESSION_EVENT
Constants included from ZookeeperCommon
ZookeeperCommon::ZKRB_GLOBAL_CB_REQ
Instance Attribute Summary
Attributes inherited from ZookeeperBase
Class Method Summary collapse
-
.debug_level= ⇒ Object
for expert use only.
- .get_debug_level ⇒ Object (also: debug_level)
- .logger ⇒ Object
- .logger=(logger) ⇒ Object
-
.set_debug_level(val) ⇒ Object
for expert use only.
- .set_zkrb_debug_level(level) ⇒ Object
Instance Method Summary collapse
- #associating? ⇒ Boolean
-
#close ⇒ Object
close this client and any underyling connections.
-
#closed? ⇒ Boolean
has the underlying connection been closed?.
- #connected? ⇒ Boolean
- #connecting? ⇒ Boolean
- #create(options = {}) ⇒ Object
- #delete(options = {}) ⇒ Object
-
#event_dispatch_thread? ⇒ Boolean
There are some operations that are dangerous in the context of the event dispatch thread (because they would block further event delivery).
- #get(options = {}) ⇒ Object
- #get_acl(options = {}) ⇒ Object
- #get_children(options = {}) ⇒ Object
-
#initialize(host, timeout = 10, watcher = nil) ⇒ Zookeeper
constructor
A new instance of Zookeeper.
- #reopen(timeout = 10, watcher = nil) ⇒ Object
-
#running? ⇒ Boolean
is the event delivery system running?.
-
#session_id ⇒ Object
return the session id of the current connection as an Fixnum.
-
#session_passwd ⇒ Object
Return the passwd portion of this connection’s credentials as a String.
- #set(options = {}) ⇒ Object
- #set_acl(options = {}) ⇒ Object
-
#set_debug_level(val) ⇒ Object
DEPRECATED: use the class-level method instead.
- #stat(options = {}) ⇒ Object
- #state ⇒ Object
-
#sync(options = {}) ⇒ Object
this method is only asynchronous.
-
#wake_event_loop! ⇒ Object
wake up the event loop, used when shutting down.
Methods inherited from ZookeeperBase
#set_default_global_watcher, synchronized_delegation, threadsafe_inquisitor
Methods included from ZookeeperConstants
#event_by_value, #state_by_value
Constructor Details
#initialize(host, timeout = 10, watcher = nil) ⇒ Zookeeper
Returns a new instance of Zookeeper.
42 43 44 |
# File 'lib/zookeeper.rb', line 42 def initialize(host, timeout=10, watcher=nil) super end |
Class Method Details
.debug_level= ⇒ Object
for expert use only. set the underlying debug level for the C layer, has no effect in java
219 220 221 222 223 |
# File 'lib/zookeeper.rb', line 219 def self.set_debug_level(val) if defined?(::CZookeeper) CZookeeper.set_debug_level(val.to_i) end end |
.get_debug_level ⇒ Object Also known as: debug_level
211 212 213 214 215 |
# File 'lib/zookeeper.rb', line 211 def self.get_debug_level if defined?(::CZookeeper) CZookeeper.get_debug_level end end |
.logger ⇒ Object
29 30 31 |
# File 'lib/zookeeper.rb', line 29 def self.logger @@logger end |
.logger=(logger) ⇒ Object
33 34 35 |
# File 'lib/zookeeper.rb', line 33 def self.logger=(logger) @@logger = logger end |
.set_debug_level(val) ⇒ Object
for expert use only. set the underlying debug level for the C layer, has no effect in java
204 205 206 207 208 |
# File 'lib/zookeeper.rb', line 204 def self.set_debug_level(val) if defined?(::CZookeeper) CZookeeper.set_debug_level(val.to_i) end end |
.set_zkrb_debug_level(level) ⇒ Object
644 645 646 647 648 649 |
# File 'ext/zookeeper_c.c', line 644
static VALUE klass_method_zkrb_set_debug_level(VALUE klass, VALUE level) {
Check_Type(level, T_FIXNUM);
ZKRBDebugging = (FIX2INT(level) == ZOO_LOG_LEVEL_DEBUG);
zoo_set_debug_level(FIX2INT(level));
return Qnil;
}
|
Instance Method Details
#associating? ⇒ Boolean
186 187 188 |
# File 'lib/zookeeper.rb', line 186 def associating? super end |
#close ⇒ Object
close this client and any underyling connections
170 171 172 |
# File 'lib/zookeeper.rb', line 170 def close super end |
#closed? ⇒ Boolean
has the underlying connection been closed?
231 232 233 |
# File 'lib/zookeeper.rb', line 231 def closed? super end |
#connected? ⇒ Boolean
178 179 180 |
# File 'lib/zookeeper.rb', line 178 def connected? super end |
#connecting? ⇒ Boolean
182 183 184 |
# File 'lib/zookeeper.rb', line 182 def connecting? super end |
#create(options = {}) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/zookeeper.rb', line 96 def create( = {}) assert_open assert_supported_keys(, [:path, :data, :acl, :ephemeral, :sequence, :callback, :callback_context]) assert_required_keys(, [:path]) assert_valid_data_size!([:data]) flags = 0 flags |= ZOO_EPHEMERAL if [:ephemeral] flags |= ZOO_SEQUENCE if [:sequence] [:acl] ||= ZOO_OPEN_ACL_UNSAFE req_id = setup_call(:create, ) rc, newpath = super(req_id, [:path], [:data], [:callback], [:acl], flags) rv = { :req_id => req_id, :rc => rc } [:callback] ? rv : rv.merge(:path => newpath) end |
#delete(options = {}) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/zookeeper.rb', line 115 def delete( = {}) assert_open assert_supported_keys(, [:path, :version, :callback, :callback_context]) assert_required_keys(, [:path]) [:version] ||= -1 req_id = setup_call(:delete, ) rc = super(req_id, [:path], [:version], [:callback]) { :req_id => req_id, :rc => rc } end |
#event_dispatch_thread? ⇒ Boolean
There are some operations that are dangerous in the context of the event dispatch thread (because they would block further event delivery). This method allows clients to know if they’re currently executing in the context of an event.
196 197 198 |
# File 'lib/zookeeper.rb', line 196 def event_dispatch_thread? super end |
#get(options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/zookeeper.rb', line 46 def get( = {}) assert_open assert_supported_keys(, [:path, :watcher, :watcher_context, :callback, :callback_context]) assert_required_keys(, [:path]) req_id = setup_call(:get, ) rc, value, stat = super(req_id, [:path], [:callback], [:watcher]) rv = { :req_id => req_id, :rc => rc } [:callback] ? rv : rv.merge(:data => value, :stat => Stat.new(stat)) end |
#get_acl(options = {}) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/zookeeper.rb', line 157 def get_acl( = {}) assert_open assert_supported_keys(, [:path, :callback, :callback_context]) assert_required_keys(, [:path]) req_id = setup_call(:get_acl, ) rc, acls, stat = super(req_id, [:path], [:callback]) rv = { :req_id => req_id, :rc => rc } [:callback] ? rv : rv.merge(:acl => acls, :stat => Stat.new(stat)) end |
#get_children(options = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/zookeeper.rb', line 72 def get_children( = {}) assert_open assert_supported_keys(, [:path, :callback, :callback_context, :watcher, :watcher_context]) assert_required_keys(, [:path]) req_id = setup_call(:get_children, ) rc, children, stat = super(req_id, [:path], [:callback], [:watcher]) rv = { :req_id => req_id, :rc => rc } [:callback] ? rv : rv.merge(:children => children, :stat => Stat.new(stat)) end |
#reopen(timeout = 10, watcher = nil) ⇒ Object
37 38 39 40 |
# File 'lib/zookeeper.rb', line 37 def reopen(timeout=10, watcher=nil) warn "WARN: ZookeeperBase#reopen watcher argument is now ignored" if watcher super end |
#running? ⇒ Boolean
is the event delivery system running?
236 237 238 |
# File 'lib/zookeeper.rb', line 236 def running? super end |
#session_id ⇒ Object
return the session id of the current connection as an Fixnum
241 242 243 |
# File 'lib/zookeeper.rb', line 241 def session_id super end |
#session_passwd ⇒ Object
Return the passwd portion of this connection’s credentials as a String
246 247 248 |
# File 'lib/zookeeper.rb', line 246 def session_passwd super end |
#set(options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/zookeeper.rb', line 58 def set( = {}) assert_open assert_supported_keys(, [:path, :data, :version, :callback, :callback_context]) assert_required_keys(, [:path]) assert_valid_data_size!([:data]) [:version] ||= -1 req_id = setup_call(:set, ) rc, stat = super(req_id, [:path], [:data], [:callback], [:version]) rv = { :req_id => req_id, :rc => rc } [:callback] ? rv : rv.merge(:stat => Stat.new(stat)) end |
#set_acl(options = {}) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/zookeeper.rb', line 145 def set_acl( = {}) assert_open assert_supported_keys(, [:path, :acl, :version, :callback, :callback_context]) assert_required_keys(, [:path, :acl]) [:version] ||= -1 req_id = setup_call(:set_acl, ) rc = super(req_id, [:path], [:acl], [:callback], [:version]) { :req_id => req_id, :rc => rc } end |
#set_debug_level(val) ⇒ Object
DEPRECATED: use the class-level method instead
226 227 228 |
# File 'lib/zookeeper.rb', line 226 def set_debug_level(val) super end |
#stat(options = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/zookeeper.rb', line 84 def stat( = {}) assert_open assert_supported_keys(, [:path, :callback, :callback_context, :watcher, :watcher_context]) assert_required_keys(, [:path]) req_id = setup_call(:stat, ) rc, stat = exists(req_id, [:path], [:callback], [:watcher]) rv = { :req_id => req_id, :rc => rc } [:callback] ? rv : rv.merge(:stat => Stat.new(stat)) end |
#state ⇒ Object
174 175 176 |
# File 'lib/zookeeper.rb', line 174 def state super end |
#sync(options = {}) ⇒ Object
There is a discrepancy between the zkc and java versions. zkc takes a string_callback_t, java takes a VoidCallback. You should most likely use the ZookeeperCallbacks::VoidCallback and not rely on the string value.
this method is only asynchronous
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/zookeeper.rb', line 133 def sync( = {}) assert_open assert_supported_keys(, [:path, :callback, :callback_context]) assert_required_keys(, [:path, :callback]) req_id = setup_call(:sync, ) rc = super(req_id, [:path]) # we don't pass options[:callback] here as this method is *always* async { :req_id => req_id, :rc => rc } end |
#wake_event_loop! ⇒ Object
wake up the event loop, used when shutting down
253 254 255 |
# File 'lib/zookeeper.rb', line 253 def wake_event_loop! super end |