Class: SolidObjects::LeaseRenewer
- Inherits:
-
Object
- Object
- SolidObjects::LeaseRenewer
- Defined in:
- lib/solid_objects/lease_renewer.rb,
sig/generated/lib/solid_objects/lease_renewer.rbs
Instance Attribute Summary collapse
-
#activation ⇒ Object
readonly
Returns the value of attribute activation.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#mutex ⇒ Object
readonly
Returns the value of attribute mutex.
-
#process_registry ⇒ Object
readonly
Returns the value of attribute process_registry.
Instance Method Summary collapse
- #around { ... } ⇒ Object
-
#initialize(activation:, process_registry:) ⇒ LeaseRenewer
constructor
A new instance of LeaseRenewer.
- #start ⇒ void
- #stop ⇒ void
- #wait_for_interval ⇒ Boolean
Constructor Details
#initialize(activation:, process_registry:) ⇒ LeaseRenewer
Returns a new instance of LeaseRenewer.
13 14 15 16 17 18 19 20 |
# File 'lib/solid_objects/lease_renewer.rb', line 13 def initialize(activation:, process_registry:) @activation = activation @process_registry = process_registry @mutex = Thread::Mutex.new @condition = Thread::ConditionVariable.new @stopped = false @thread = nil end |
Instance Attribute Details
#activation ⇒ Object (readonly)
Returns the value of attribute activation.
32 33 34 |
# File 'lib/solid_objects/lease_renewer.rb', line 32 def activation @activation end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
32 33 34 |
# File 'lib/solid_objects/lease_renewer.rb', line 32 def condition @condition end |
#mutex ⇒ Object (readonly)
Returns the value of attribute mutex.
32 33 34 |
# File 'lib/solid_objects/lease_renewer.rb', line 32 def mutex @mutex end |
#process_registry ⇒ Object (readonly)
Returns the value of attribute process_registry.
32 33 34 |
# File 'lib/solid_objects/lease_renewer.rb', line 32 def process_registry @process_registry end |
Instance Method Details
#around { ... } ⇒ Object
23 24 25 26 27 28 |
# File 'lib/solid_objects/lease_renewer.rb', line 23 def around start yield ensure stop end |
#start ⇒ void
This method returns an undefined value.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/solid_objects/lease_renewer.rb', line 35 def start @thread = Thread.new do loop do break if wait_for_interval activation.renew_lease process_registry.heartbeat rescue LostActivation break end end end |
#stop ⇒ void
This method returns an undefined value.
62 63 64 65 66 67 68 |
# File 'lib/solid_objects/lease_renewer.rb', line 62 def stop mutex.synchronize do @stopped = true condition.broadcast end @thread&.join end |
#wait_for_interval ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/solid_objects/lease_renewer.rb', line 49 def wait_for_interval mutex.synchronize do unless @stopped condition.wait( mutex, SolidObjects.configuration.lease_renewal_interval ) end @stopped end end |