Class: ZeevexCluster::Static

Inherits:
Base
  • Object
show all
Defined in:
lib/zeevex_cluster/static.rb

Direct Known Subclasses

Unclustered

Instance Attribute Summary

Attributes inherited from Base

#nodename, #options

Instance Method Summary collapse

Methods inherited from Base

#ensure_master, #run_if_master

Methods included from Util::Logging

#logger

Constructor Details

#initialize(options = {}) ⇒ Static

Returns a new instance of Static.

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
10
11
# File 'lib/zeevex_cluster/static.rb', line 3

def initialize(options = {})
  super
  raise ArgumentError, "Must supply :master_nodename" unless @options[:master_nodename]
  if @options[:master_nodename] == :self
    @options[:master_nodename] = nodename
  end
  @member = false
  after_initialize
end

Instance Method Details

#joinObject

joining is a no-op for ol’ singleton here



16
17
18
# File 'lib/zeevex_cluster/static.rb', line 16

def join
  @member = true
end

#leaveObject

leaving, too



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

def leave
  @member = false
  true
end

#make_master!Object

Nobody can change the master



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

def make_master!
  raise ClusterActionFailed, "Can not change master" unless master?
  true
end

#masterObject

Return name of master node



62
63
64
# File 'lib/zeevex_cluster/static.rb', line 62

def master
  options[:master_nodename]
end

#master?Boolean

Are we the chosen one?

Returns:

  • (Boolean)


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

def master?
  member? && nodename == options[:master_nodename]
end

#member?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/zeevex_cluster/static.rb', line 28

def member?
  !! @member
end

#resign!Object

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

No-op for now.

Raises:



52
53
54
55
56
57
# File 'lib/zeevex_cluster/static.rb', line 52

def resign!
  raise NotMaster unless master?

  # master is currently fixed, so we can't resign
  raise ClusterPolicyViolation, "Current master cannot resign in this implementation."
end