Module: ZK::Event

Includes:
Zookeeper::Constants
Defined in:
lib/zk/event.rb

Overview

Provides most of the functionality ZK uses around events. Base class is actually Zookeeper::Callbacks::WatcherCallback, but this module is mixed in and provides a lot of useful syntactic sugar.

Instance Method Summary collapse

Instance Method Details

#associating?Boolean Also known as: state_associating?

Is this event notifying us we're in the associating state?

Returns:

  • (Boolean)


73
74
75
# File 'lib/zk/event.rb', line 73

def associating?
  @state == ZOO_ASSOCIATING_STATE
end

#auth_failed?Boolean Also known as: state_auth_failed?

Is this event notifying us we're in the auth_failed state?

Returns:

  • (Boolean)


85
86
87
# File 'lib/zk/event.rb', line 85

def auth_failed?
  @state == ZOO_AUTH_FAILED_STATE
end

#client_invalid?Boolean

according to the programmer's guide

once a ZooKeeper object is closed or receives a fatal event (SESSION_EXPIRED and AUTH_FAILED), the ZooKeeper object becomes invalid.

this will return true for either of those cases

Returns:

  • (Boolean)


172
173
174
# File 'lib/zk/event.rb', line 172

def client_invalid?
  (@state == ZOO_EXPIRED_SESSION_STATE) || (@state == ZOO_AUTH_FAILED_STATE)
end

#connected?Boolean Also known as: state_connected?

Is this event notifying us we're in the connected state?

Returns:

  • (Boolean)


79
80
81
# File 'lib/zk/event.rb', line 79

def connected?
  @state == ZOO_CONNECTED_STATE
end

#connecting?Boolean Also known as: state_connecting?

Is this event notifying us we're in the connecting state?

Returns:

  • (Boolean)


67
68
69
# File 'lib/zk/event.rb', line 67

def connecting?
  @state == ZOO_CONNECTING_STATE
end

#event_nameObject

return this event's type name as a string "ZOO_*_EVENT", used for debugging



140
141
142
# File 'lib/zk/event.rb', line 140

def event_name
  (name = EVENT_TYPE_NAMES[@type]) ? "ZOO_#{name.to_s.upcase}_EVENT" : ''
end

#expired_session?Boolean Also known as: state_expired_session?

Is this event notifying us we're in the expired_session state?

Returns:

  • (Boolean)


91
92
93
# File 'lib/zk/event.rb', line 91

def expired_session?
  @state == ZOO_EXPIRED_SESSION_STATE
end

#node_changed?Boolean Also known as: changed?

Has a node changed?

Returns:

  • (Boolean)


114
115
116
# File 'lib/zk/event.rb', line 114

def node_changed?
  @type == ZOO_CHANGED_EVENT
end

#node_child?Boolean Also known as: child?

Has a node's list of children changed?

Returns:

  • (Boolean)


120
121
122
# File 'lib/zk/event.rb', line 120

def node_child?
  @type == ZOO_CHILD_EVENT
end

#node_created?Boolean Also known as: created?

Has a node been created?

Returns:

  • (Boolean)


102
103
104
# File 'lib/zk/event.rb', line 102

def node_created?
  @type == ZOO_CREATED_EVENT
end

#node_deleted?Boolean Also known as: deleted?

Has a node been deleted?

Returns:

  • (Boolean)


108
109
110
# File 'lib/zk/event.rb', line 108

def node_deleted?
  @type == ZOO_DELETED_EVENT
end

#node_event?Boolean Also known as: node?

has this watcher been called because of a change to a zookeeper node? node_event? and session_event? are mutually exclusive.

Returns:

  • (Boolean)


159
160
161
# File 'lib/zk/event.rb', line 159

def node_event?
  path and not path.empty?
end

#node_notwatching?Boolean Also known as: node_not_watching?

I have never seen this event delivered. here for completeness.

Returns:

  • (Boolean)


134
135
136
# File 'lib/zk/event.rb', line 134

def node_notwatching?
  @type == ZOO_NOTWATCHING_EVENT
end

#node_session?Boolean

Deprecated.

This was an artifact of the way these methods were created originally, will be removed because it's kinda dumb. use #session_event?

Is this a session-related event?

Returns:

  • (Boolean)


129
130
131
# File 'lib/zk/event.rb', line 129

def node_session?
  @type == ZOO_SESSION_EVENT
end

#pathString?

The path this event is in reference to.

Returns:

  • (String, nil)

    This value will be nil if session_event? is false, otherwise a String containing the path this event was triggered in reference to



61
62
63
64
# File 'lib/zk/event.rb', line 61

def path
  # no-op, the functionality is provided by the class this is mixed into.
  # here only for documentation purposes
end

#session_event?Boolean Also known as: state_event?, session?

has this watcher been called because of a change in connection state?

Returns:

  • (Boolean)


151
152
153
# File 'lib/zk/event.rb', line 151

def session_event?
  @type == ZOO_SESSION_EVENT
end

#stateFixnum

The numeric constant (one of ZOO_*_STATE) that ZooKeeper sets to indicate the session state this event is notifying us of. Users are encouraged to use the '?' methods below, instead of this value.

Returns:

  • (Fixnum)


52
53
54
55
# File 'lib/zk/event.rb', line 52

def state
  # no-op, the functionality is provided by the class this is mixed into.
  # here only for documentation purposes
end

#state_nameObject

return this event's state name as a string "ZOO_*_STATE", used for debugging



97
98
99
# File 'lib/zk/event.rb', line 97

def state_name
  (name = STATE_NAMES[@state]) ? "ZOO_#{name.to_s.upcase}_STATE" : ''
end

#typeFixnum

The numeric constant (one of ZOO_*_EVENT) that ZooKeeper sets to indicate the type of event this is. Users are advised to use the '?' methods below instead of using this value.

Returns:

  • (Fixnum)


42
43
44
45
# File 'lib/zk/event.rb', line 42

def type
  # no-op, the functionality is provided by the class this is mixed into.
  # here only for documentation purposes
end