Class: Karafka::Connection::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/connection/status.rb

Overview

Listener connection status representation

Constant Summary collapse

STATES =

Available states and their transitions.

{
  pending: :pending!,
  starting: :start!,
  running: :running!,
  quieting: :quiet!,
  quiet: :quieted!,
  stopping: :stop!,
  stopped: :stopped!
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeStatus

Initializes the connection status and sets it to pending



50
51
52
53
# File 'lib/karafka/connection/status.rb', line 50

def initialize
  @mutex = Mutex.new
  pending!
end

Instance Method Details

#active?Boolean

Returns listener is considered active when it has a client reference that may be active and connected to Kafka.

Returns:

  • (Boolean)

    listener is considered active when it has a client reference that may be active and connected to Kafka



86
87
88
# File 'lib/karafka/connection/status.rb', line 86

def active?
  !pending? && !stopped?
end

#reset!Object

Moves status back from stopped to pending (and only that). We should not be able to reset listeners that are not stopped



78
79
80
81
82
# File 'lib/karafka/connection/status.rb', line 78

def reset!
  return unless stopped?

  @status = :pending
end

#stop!Object

If this listener was not even running, will just move it through states until final. If it was running, will start the stopping procedures. Will do nothing if it was already stopped



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/karafka/connection/status.rb', line 58

def stop!
  if pending?
    @status = :stopping
    conductor.signal
    monitor.instrument('connection.listener.stopping', caller: self)

    stopped!
  elsif stopped?
    nil
  elsif stopping?
    nil
  else
    @status = :stopping
    conductor.signal
    monitor.instrument('connection.listener.stopping', caller: self)
  end
end