Class: Elected::Senado
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logging
#debug, #debug_var, #error, included, #info, #warn
Constructor Details
#initialize(key = nil, timeout = nil) ⇒ Senado
11
12
13
14
15
|
# File 'lib/elected/senado.rb', line 11
def initialize(key = nil, timeout = nil)
@key = key
@timeout = timeout
@stats = Stats.new :elected, :rejected, :missing, :released
end
|
Instance Attribute Details
17
18
19
|
# File 'lib/elected/senado.rb', line 17
def key
@key || Elected.key
end
|
Returns the value of attribute stats.
9
10
11
|
# File 'lib/elected/senado.rb', line 9
def stats
@stats
end
|
In ms (milliseconds), defaults to 5 seconds
22
23
24
|
# File 'lib/elected/senado.rb', line 22
def timeout
@timeout || Elected.timeout
end
|
Instance Method Details
26
27
28
|
# File 'lib/elected/senado.rb', line 26
def leader
mutex.synchronize { get_leader || set_leader }
end
|
#leader? ⇒ Boolean
30
31
32
|
# File 'lib/elected/senado.rb', line 30
def leader?
!!leader
end
|
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/elected/senado.rb', line 34
def release
return false unless @leader
if @leader.current?
Elected.electorado.unlock @leader.info
@stats.increment :released
end
@leader = false
end
|
#to_s ⇒ Object
Also known as:
inspect
45
46
47
|
# File 'lib/elected/senado.rb', line 45
def to_s
%{#<#{self.class.name} key=#{key.inspect} timeout=#{timeout} leader?=#{leader?}>}
end
|