Class: ZeevexCluster::Base

Inherits:
Object
  • Object
show all
Includes:
Hookem, Util::Logging
Defined in:
lib/zeevex_cluster/base.rb

Direct Known Subclasses

Election, Static

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Logging

#logger

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/zeevex_cluster/base.rb', line 11

def initialize(options = {})
  @options = {:nodename => Socket.gethostname,
              :autojoin => true}.merge(options)
  @logger  = @options[:logger]

  _initialize_hook_module

  if @options[:hooks]
    add_hooks @options[:hooks]
  end
end

Instance Attribute Details

#nodenameObject

Return this node’s name



85
86
87
# File 'lib/zeevex_cluster/base.rb', line 85

def nodename
  @nodename
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/zeevex_cluster/base.rb', line 9

def options
  @options
end

Instance Method Details

#ensure_master(&block) ⇒ Object

Make this node the master if not already the master if provided a block, run that IFF we are the master



50
51
52
53
54
55
# File 'lib/zeevex_cluster/base.rb', line 50

def ensure_master(&block)
  make_master! unless master?
  if block
    run_if_master &block
  end
end

#joinObject

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/zeevex_cluster/base.rb', line 23

def join
  raise NotImplementedError
end

#leaveObject

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/zeevex_cluster/base.rb', line 27

def leave
  raise NotImplementedError
end

#make_master!Object

Make this node the master, returning true if successful.

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/zeevex_cluster/base.rb', line 42

def make_master!
  raise NotImplementedError
end

#masterObject

Return name of master node

Raises:

  • (NotImplementedError)


78
79
80
# File 'lib/zeevex_cluster/base.rb', line 78

def master
  raise NotImplementedError
end

#master?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/zeevex_cluster/base.rb', line 31

def master?
  raise NotImplementedError
end

#member?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/zeevex_cluster/base.rb', line 35

def member?
  raise NotImplementedError
end

#resign!Object

Resign from mastership; returns false if this is the only node.

Raises:

  • (NotImplementedError)


71
72
73
# File 'lib/zeevex_cluster/base.rb', line 71

def resign!
  raise NotImplementedError
end

#run_if_master(&block) ⇒ Object

Run the code block only if this node is the master



60
61
62
63
64
65
66
# File 'lib/zeevex_cluster/base.rb', line 60

def run_if_master(&block)
  if master?
    block.call
  else
    false
  end
end