Class: ZK::Group::Member

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/zk-group/member.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zk, group, path) ⇒ Member

Returns a new instance of Member.



17
18
19
20
21
22
23
# File 'lib/zk-group/member.rb', line 17

def initialize(zk, group, path)
  @zk = zk
  @group = group
  @path = path
  @name = File.basename(@path)
  @mutex = Mutex.new
end

Instance Attribute Details

#groupGroup (readonly)

Returns the group instance this member belongs to.

Returns:

  • (Group)

    the group instance this member belongs to



9
10
11
# File 'lib/zk-group/member.rb', line 9

def group
  @group
end

#nameString (readonly)

Returns the relative path of this member under ‘group.path`.

Returns:

  • (String)

    the relative path of this member under ‘group.path`



12
13
14
# File 'lib/zk-group/member.rb', line 12

def name
  @name
end

#pathString (readonly)

Returns the absolute path of this member.

Returns:

  • (String)

    the absolute path of this member



15
16
17
# File 'lib/zk-group/member.rb', line 15

def path
  @path
end

#zkObject (readonly)

Returns the value of attribute zk.



6
7
8
# File 'lib/zk-group/member.rb', line 6

def zk
  @zk
end

Instance Method Details

#active?Boolean

probably poor choice of name, but does this member still an active membership to its group (i.e. is its path still good).

This will return false after leave is called.

Returns:

  • (Boolean)


29
30
31
# File 'lib/zk-group/member.rb', line 29

def active?
  zk.exists?(path)
end

#dataObject



41
42
43
# File 'lib/zk-group/member.rb', line 41

def data
  @data ||= zk.get(path).first
end

#data=(data) ⇒ Object



45
46
47
48
49
# File 'lib/zk-group/member.rb', line 45

def data=(data)
  @data = data
  zk.set(path, data)
  data
end

#leaveObject

Leave the group this membership is associated with. In the basic implementation, this is not meant to kick another member out of the group.



37
38
39
# File 'lib/zk-group/member.rb', line 37

def leave
  zk.delete(path)
end