Class: Zookeeper

Inherits:
ZookeeperBase show all
Defined in:
lib/zookeeper.rb

Direct Known Subclasses

ZookeeperEM::Client

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

#event_queue

Class Method Summary collapse

Instance Method Summary collapse

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_levelObject 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

.loggerObject



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

Returns:

  • (Boolean)


186
187
188
# File 'lib/zookeeper.rb', line 186

def associating?
  super
end

#closeObject

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?

Returns:

  • (Boolean)


231
232
233
# File 'lib/zookeeper.rb', line 231

def closed?
  super
end

#connected?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/zookeeper.rb', line 178

def connected?
  super
end

#connecting?Boolean

Returns:

  • (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(options = {})
  assert_open
  assert_supported_keys(options, [:path, :data, :acl, :ephemeral, :sequence, :callback, :callback_context])
  assert_required_keys(options, [:path])
  assert_valid_data_size!(options[:data])

  flags = 0
  flags |= ZOO_EPHEMERAL if options[:ephemeral]
  flags |= ZOO_SEQUENCE if options[:sequence]

  options[:acl] ||= ZOO_OPEN_ACL_UNSAFE

  req_id = setup_call(:create, options)
  rc, newpath = super(req_id, options[:path], options[:data], options[:callback], options[:acl], flags)

  rv = { :req_id => req_id, :rc => rc }
  options[: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(options = {})
  assert_open
  assert_supported_keys(options, [:path, :version, :callback, :callback_context])
  assert_required_keys(options, [:path])
  options[:version] ||= -1

  req_id = setup_call(:delete, options)
  rc = super(req_id, options[:path], options[:version], options[: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.

Returns:

  • (Boolean)


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(options = {})
  assert_open
  assert_supported_keys(options, [:path, :watcher, :watcher_context, :callback, :callback_context])
  assert_required_keys(options, [:path])

  req_id = setup_call(:get, options)
  rc, value, stat = super(req_id, options[:path], options[:callback], options[:watcher])

  rv = { :req_id => req_id, :rc => rc }
  options[: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(options = {})
  assert_open
  assert_supported_keys(options, [:path, :callback, :callback_context])
  assert_required_keys(options, [:path])

  req_id = setup_call(:get_acl, options)
  rc, acls, stat = super(req_id, options[:path], options[:callback])

  rv = { :req_id => req_id, :rc => rc }
  options[: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(options = {})
  assert_open
  assert_supported_keys(options, [:path, :callback, :callback_context, :watcher, :watcher_context])
  assert_required_keys(options, [:path])

  req_id = setup_call(:get_children, options)
  rc, children, stat = super(req_id, options[:path], options[:callback], options[:watcher])

  rv = { :req_id => req_id, :rc => rc }
  options[: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?

Returns:

  • (Boolean)


236
237
238
# File 'lib/zookeeper.rb', line 236

def running?
  super
end

#session_idObject

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_passwdObject

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(options = {})
  assert_open
  assert_supported_keys(options, [:path, :data, :version, :callback, :callback_context])
  assert_required_keys(options, [:path])
  assert_valid_data_size!(options[:data])
  options[:version] ||= -1

  req_id = setup_call(:set, options)
  rc, stat = super(req_id, options[:path], options[:data], options[:callback], options[:version])

  rv = { :req_id => req_id, :rc => rc }
  options[: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(options = {})
  assert_open
  assert_supported_keys(options, [:path, :acl, :version, :callback, :callback_context])
  assert_required_keys(options, [:path, :acl])
  options[:version] ||= -1

  req_id = setup_call(:set_acl, options)
  rc = super(req_id, options[:path], options[:acl], options[:callback], options[: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(options = {})
  assert_open
  assert_supported_keys(options, [:path, :callback, :callback_context, :watcher, :watcher_context])
  assert_required_keys(options, [:path])

  req_id = setup_call(:stat, options)
  rc, stat = exists(req_id, options[:path], options[:callback], options[:watcher])

  rv = { :req_id => req_id, :rc => rc }
  options[:callback] ? rv : rv.merge(:stat => Stat.new(stat))
end

#stateObject



174
175
176
# File 'lib/zookeeper.rb', line 174

def state
  super
end

#sync(options = {}) ⇒ Object

Note:

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(options = {})
  assert_open
  assert_supported_keys(options, [:path, :callback, :callback_context])
  assert_required_keys(options, [:path, :callback])

  req_id = setup_call(:sync, options)

  rc = super(req_id, options[: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