Class: ZeevexCluster::Base
- Inherits:
-
Object
- Object
- ZeevexCluster::Base
- Includes:
- Hookem, Util::Logging
- Defined in:
- lib/zeevex_cluster/base.rb
Instance Attribute Summary collapse
-
#nodename ⇒ Object
Return this node’s name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#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.
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #join ⇒ Object
- #leave ⇒ Object
-
#make_master! ⇒ Object
Make this node the master, returning true if successful.
-
#master ⇒ Object
Return name of master node.
- #master? ⇒ Boolean
- #member? ⇒ Boolean
-
#resign! ⇒ Object
Resign from mastership; returns false if this is the only node.
-
#run_if_master(&block) ⇒ Object
Run the code block only if this node is the master.
Methods included from Util::Logging
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 = {:nodename => Socket.gethostname, :autojoin => true}.merge() @logger = @options[:logger] _initialize_hook_module if @options[:hooks] add_hooks @options[:hooks] end end |
Instance Attribute Details
#nodename ⇒ Object
Return this node’s name
85 86 87 |
# File 'lib/zeevex_cluster/base.rb', line 85 def nodename @nodename end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/zeevex_cluster/base.rb', line 9 def @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 |
#join ⇒ Object
23 24 25 |
# File 'lib/zeevex_cluster/base.rb', line 23 def join raise NotImplementedError end |
#leave ⇒ Object
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.
42 43 44 |
# File 'lib/zeevex_cluster/base.rb', line 42 def make_master! raise NotImplementedError end |
#master ⇒ Object
Return name of master node
78 79 80 |
# File 'lib/zeevex_cluster/base.rb', line 78 def master raise NotImplementedError end |
#master? ⇒ Boolean
31 32 33 |
# File 'lib/zeevex_cluster/base.rb', line 31 def master? raise NotImplementedError end |
#member? ⇒ Boolean
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.
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 |