Class: SolidObjects::LeaseRenewer

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_objects/lease_renewer.rb,
sig/generated/lib/solid_objects/lease_renewer.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(activation:, process_registry:) ⇒ LeaseRenewer

Returns a new instance of LeaseRenewer.

RBS:

  • (activation: Activation, process_registry: ProcessRegistry) -> void

Parameters:



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

#activationObject (readonly)

Returns the value of attribute activation.

Returns:

  • (Object)


32
33
34
# File 'lib/solid_objects/lease_renewer.rb', line 32

def activation
  @activation
end

#conditionObject (readonly)

Returns the value of attribute condition.

Returns:

  • (Object)


32
33
34
# File 'lib/solid_objects/lease_renewer.rb', line 32

def condition
  @condition
end

#mutexObject (readonly)

Returns the value of attribute mutex.

Returns:

  • (Object)


32
33
34
# File 'lib/solid_objects/lease_renewer.rb', line 32

def mutex
  @mutex
end

#process_registryObject (readonly)

Returns the value of attribute process_registry.

Returns:

  • (Object)


32
33
34
# File 'lib/solid_objects/lease_renewer.rb', line 32

def process_registry
  @process_registry
end

Instance Method Details

#around { ... } ⇒ Object

RBS:

  • () { () -> untyped } -> untyped

Yields:

Yield Returns:

  • (Object)

Returns:

  • (Object)


23
24
25
26
27
28
# File 'lib/solid_objects/lease_renewer.rb', line 23

def around
  start
  yield
ensure
  stop
end

#startvoid

This method returns an undefined value.

RBS:

  • () -> void



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

#stopvoid

This method returns an undefined value.

RBS:

  • () -> void



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_intervalBoolean

RBS:

  • () -> bool

Returns:

  • (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