Module: Zookeeper::ClientMethods

Includes:
ACLs, Constants, Logger
Defined in:
lib/zookeeper/client_methods.rb

Constant Summary

Constants included from Constants

Zookeeper::Constants::CONNECTED_EVENT_VALUES, Zookeeper::Constants::EVENT_TYPE_NAMES, Zookeeper::Constants::STATE_NAMES, Zookeeper::Constants::ZAPIERROR, Zookeeper::Constants::ZAUTHFAILED, Zookeeper::Constants::ZBADARGUMENTS, Zookeeper::Constants::ZBADVERSION, Zookeeper::Constants::ZCLOSING, Zookeeper::Constants::ZCONNECTIONLOSS, Zookeeper::Constants::ZDATAINCONSISTENCY, Zookeeper::Constants::ZINVALIDACL, Zookeeper::Constants::ZINVALIDCALLBACK, Zookeeper::Constants::ZINVALIDSTATE, Zookeeper::Constants::ZKRB_ASYNC_CONTN_ID, Zookeeper::Constants::ZKRB_GLOBAL_CB_REQ, Zookeeper::Constants::ZMARSHALLINGERROR, Zookeeper::Constants::ZNOAUTH, Zookeeper::Constants::ZNOCHILDRENFOREPHEMERALS, Zookeeper::Constants::ZNODEEXISTS, Zookeeper::Constants::ZNONODE, Zookeeper::Constants::ZNOTEMPTY, Zookeeper::Constants::ZNOTHING, Zookeeper::Constants::ZOK, Zookeeper::Constants::ZOO_ASSOCIATING_STATE, Zookeeper::Constants::ZOO_AUTH_FAILED_STATE, Zookeeper::Constants::ZOO_CHANGED_EVENT, Zookeeper::Constants::ZOO_CHILD_EVENT, Zookeeper::Constants::ZOO_CLOSED_STATE, Zookeeper::Constants::ZOO_CONNECTED_STATE, Zookeeper::Constants::ZOO_CONNECTING_STATE, Zookeeper::Constants::ZOO_CREATED_EVENT, Zookeeper::Constants::ZOO_DELETED_EVENT, Zookeeper::Constants::ZOO_EPHEMERAL, Zookeeper::Constants::ZOO_EXPIRED_SESSION_STATE, Zookeeper::Constants::ZOO_LOG_LEVEL_DEBUG, Zookeeper::Constants::ZOO_LOG_LEVEL_ERROR, Zookeeper::Constants::ZOO_LOG_LEVEL_INFO, Zookeeper::Constants::ZOO_LOG_LEVEL_WARN, Zookeeper::Constants::ZOO_NOTWATCHING_EVENT, Zookeeper::Constants::ZOO_SEQUENCE, Zookeeper::Constants::ZOO_SESSION_EVENT, Zookeeper::Constants::ZOPERATIONTIMEOUT, Zookeeper::Constants::ZRUNTIMEINCONSISTENCY, Zookeeper::Constants::ZSESSIONEXPIRED, Zookeeper::Constants::ZSESSIONMOVED, Zookeeper::Constants::ZSYSTEMERROR, Zookeeper::Constants::ZUNIMPLEMENTED

Constants included from ACLs::Constants

ACLs::Constants::ZOO_ANYONE_ID_UNSAFE, ACLs::Constants::ZOO_AUTH_IDS, ACLs::Constants::ZOO_CREATOR_ALL_ACL, ACLs::Constants::ZOO_OPEN_ACL_UNSAFE, ACLs::Constants::ZOO_PERM_ADMIN, ACLs::Constants::ZOO_PERM_ALL, ACLs::Constants::ZOO_PERM_CREATE, ACLs::Constants::ZOO_PERM_DELETE, ACLs::Constants::ZOO_PERM_READ, ACLs::Constants::ZOO_PERM_WRITE, ACLs::Constants::ZOO_READ_ACL_UNSAFE

Instance Method Summary collapse

Methods included from Logger

included, set_default

Methods included from Constants

#event_by_value, #state_by_value

Instance Method Details

#associating?Boolean


156
157
158
# File 'lib/zookeeper/client_methods.rb', line 156

def associating?
  super
end

#closeObject

close this client and any underyling connections


140
141
142
# File 'lib/zookeeper/client_methods.rb', line 140

def close
  super
end

#closed?Boolean

has the underlying connection been closed?


176
177
178
# File 'lib/zookeeper/client_methods.rb', line 176

def closed?
  super
end

#connected?Boolean


148
149
150
# File 'lib/zookeeper/client_methods.rb', line 148

def connected?
  super
end

#connecting?Boolean


152
153
154
# File 'lib/zookeeper/client_methods.rb', line 152

def connecting?
  super
end

#create(options = {}) ⇒ Object


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/zookeeper/client_methods.rb', line 66

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


85
86
87
88
89
90
91
92
93
94
95
# File 'lib/zookeeper/client_methods.rb', line 85

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.


166
167
168
# File 'lib/zookeeper/client_methods.rb', line 166

def event_dispatch_thread?
  super
end

#get(options = {}) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/zookeeper/client_methods.rb', line 16

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


127
128
129
130
131
132
133
134
135
136
137
# File 'lib/zookeeper/client_methods.rb', line 127

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


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/zookeeper/client_methods.rb', line 42

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

#initialize(host, timeout = 10, watcher = nil) ⇒ Object


12
13
14
# File 'lib/zookeeper/client_methods.rb', line 12

def initialize(host, timeout=10, watcher=nil)
  super
end

#pause_before_fork_in_parentObject

stop all underlying threads in preparation for a fork()


196
197
198
# File 'lib/zookeeper/client_methods.rb', line 196

def pause_before_fork_in_parent
  super
end

#reopen(timeout = 10, watcher = nil) ⇒ Object


7
8
9
10
# File 'lib/zookeeper/client_methods.rb', line 7

def reopen(timeout=10, watcher=nil)
  warn "WARN: ZookeeperBase#reopen watcher argument is now ignored" if watcher
  super
end

#resume_after_fork_in_parentObject

re-start all underlying threads after performing a fork()


201
202
203
# File 'lib/zookeeper/client_methods.rb', line 201

def resume_after_fork_in_parent
  super
end

#running?Boolean

is the event delivery system running?


181
182
183
# File 'lib/zookeeper/client_methods.rb', line 181

def running?
  super
end

#session_idObject

return the session id of the current connection as an Fixnum


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

def session_id
  super
end

#session_passwdObject

Return the passwd portion of this connection's credentials as a String


191
192
193
# File 'lib/zookeeper/client_methods.rb', line 191

def session_passwd
  super
end

#set(options = {}) ⇒ Object


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/zookeeper/client_methods.rb', line 28

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


115
116
117
118
119
120
121
122
123
124
125
# File 'lib/zookeeper/client_methods.rb', line 115

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


171
172
173
# File 'lib/zookeeper/client_methods.rb', line 171

def set_debug_level(val)
  super
end

#stat(options = {}) ⇒ Object


54
55
56
57
58
59
60
61
62
63
64
# File 'lib/zookeeper/client_methods.rb', line 54

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


144
145
146
# File 'lib/zookeeper/client_methods.rb', line 144

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 Zookeeper::Callbacks::VoidCallback and not rely on the string value.

this method is only asynchronous


103
104
105
106
107
108
109
110
111
112
113
# File 'lib/zookeeper/client_methods.rb', line 103

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