Class: KubeMQ::Transport::ReconnectManager Private
- Inherits:
-
Object
- Object
- KubeMQ::Transport::ReconnectManager
- Defined in:
- lib/kubemq/transport/reconnect_manager.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Manages automatic reconnection with exponential backoff and jitter.
Spawns a background thread that repeatedly invokes the reconnect procedure until the connection succeeds or the maximum number of attempts is reached. Backoff delay is computed as:
delay = min(base_interval * multiplier^(attempt-1), max_delay) +/- jitter
Instance Attribute Summary collapse
-
#attempt ⇒ Integer
readonly
private
Current reconnect attempt counter (0 before first attempt).
Instance Method Summary collapse
-
#initialize(policy:, state_machine:, reconnect_proc:, on_reconnected: nil) ⇒ ReconnectManager
constructor
private
A new instance of ReconnectManager.
-
#start ⇒ void
private
Starts the background reconnect loop.
-
#stop ⇒ void
private
Signals the reconnect loop to stop and waits up to 5 seconds for the background thread to finish.
Constructor Details
#initialize(policy:, state_machine:, reconnect_proc:, on_reconnected: nil) ⇒ ReconnectManager
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ReconnectManager.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kubemq/transport/reconnect_manager.rb', line 25 def initialize(policy:, state_machine:, reconnect_proc:, on_reconnected: nil) @policy = policy @state_machine = state_machine @reconnect_proc = reconnect_proc @on_reconnected = on_reconnected @attempt = 0 @mutex = Mutex.new @thread = nil @stop_flag = false end |
Instance Attribute Details
#attempt ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns current reconnect attempt counter (0 before first attempt).
19 20 21 |
# File 'lib/kubemq/transport/reconnect_manager.rb', line 19 def attempt @attempt end |
Instance Method Details
#start ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Starts the background reconnect loop. No-op if already running.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/kubemq/transport/reconnect_manager.rb', line 39 def start @mutex.synchronize do return if @thread&.alive? @stop_flag = false @attempt = 0 @thread = Thread.new { reconnect_loop } @thread.name = 'kubemq-reconnect' @thread.abort_on_exception = false end end |
#stop ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Signals the reconnect loop to stop and waits up to 5 seconds for the background thread to finish.
55 56 57 58 |
# File 'lib/kubemq/transport/reconnect_manager.rb', line 55 def stop @mutex.synchronize { @stop_flag = true } @thread&.join(5) end |