Class: Karafka::Connection::Status
- Inherits:
-
Object
- Object
- Karafka::Connection::Status
- 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
-
#active? ⇒ Boolean
Listener is considered active when it has a client reference that may be active and connected to Kafka.
-
#initialize ⇒ Status
constructor
A new instance of Status.
-
#reset! ⇒ Object
Moves status back from stopped to pending (and only that).
-
#stop! ⇒ Object
If this listener was not even running, will just move it through states until final.
Constructor Details
#initialize ⇒ Status
Returns a new instance of Status.
46 47 48 49 |
# File 'lib/karafka/connection/status.rb', line 46 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.
82 83 84 |
# File 'lib/karafka/connection/status.rb', line 82 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
74 75 76 77 78 |
# File 'lib/karafka/connection/status.rb', line 74 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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/karafka/connection/status.rb', line 54 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 |