Class: Zookeeper::RequestRegistry

Inherits:
Object
  • Object
show all
Includes:
Constants, Logger
Defined in:
lib/zookeeper/request_registry.rb

Constant Summary

Constants included from Constants

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

Methods included from Constants

#event_by_value, #state_by_value

Constructor Details

#initialize(watcher, opts = {}) ⇒ RequestRegistry

Returns a new instance of RequestRegistry.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :chroot_path (String) — default: nil

    if given, will be used to correct a discrepancy between the C and Java clients when using a chrooted connection. If given, the chroot path will be stripped from the string returned by a ‘create`. It should be an absolute path.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/zookeeper/request_registry.rb', line 12

def initialize(watcher, opts={})
  @mutex = Monitor.new

  @default_watcher  = watcher

  @current_req_id   = 0
  @watcher_reqs     = {}
  @completion_reqs  = {}

  @chroot_path = opts[:chroot_path]
end

Instance Method Details

#clear_watchers!Object



57
58
59
# File 'lib/zookeeper/request_registry.rb', line 57

def clear_watchers!
  @mutex.synchronize { @watcher_reqs.clear }
end

#default_watcherObject



24
25
26
# File 'lib/zookeeper/request_registry.rb', line 24

def default_watcher
  @mutex.synchronize { @default_watcher }
end

#default_watcher=(blk) ⇒ Object



28
29
30
# File 'lib/zookeeper/request_registry.rb', line 28

def default_watcher=(blk)
  @mutex.synchronize { @default_watcher = blk }
end

#get_context_for(hash) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/zookeeper/request_registry.rb', line 43

def get_context_for(hash)
  return nil unless hash

  is_session_event  = (hash[:type] == ZOO_SESSION_EVENT)

  req_id  = hash.fetch(:req_id)

  if hash.has_key?(:rc)
    get_completion(req_id, :keep => is_session_event)
  else
    get_watcher(req_id, :keep => is_session_event)
  end
end

#setup_call(meth_name, opts) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/zookeeper/request_registry.rb', line 32

def setup_call(meth_name, opts)
  req_id = nil
  @mutex.synchronize {
    req_id = @current_req_id
    @current_req_id += 1
    setup_completion(req_id, meth_name, opts) if opts[:callback]
    setup_watcher(req_id, opts)               if opts[:watcher]
  }
  req_id
end

#strip_chroot_from(path) ⇒ Object

if we’re chrooted, this method will strip the chroot prefix from path



62
63
64
65
# File 'lib/zookeeper/request_registry.rb', line 62

def strip_chroot_from(path)
  return path unless (chrooted? and path and path.start_with?(@chroot_path))
  path[@chroot_path.length..-1]
end