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



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

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



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

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



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

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



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

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