Class: Bunny::HeartbeatSender
- Inherits:
-
Object
- Object
- Bunny::HeartbeatSender
- Defined in:
- lib/bunny/heartbeat_sender.rb
Overview
Periodically sends heartbeats, keeping track of the last publishing activity.
Instance Method Summary collapse
-
#initialize(transport, logger) ⇒ HeartbeatSender
constructor
API.
- #signal_activity! ⇒ Object
- #start(period = 30) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(transport, logger) ⇒ HeartbeatSender
API
17 18 19 20 21 22 23 |
# File 'lib/bunny/heartbeat_sender.rb', line 17 def initialize(transport, logger) @transport = transport @logger = logger @mutex = Monitor.new @last_activity_time = Bunny::Timestamp.monotonic end |
Instance Method Details
#signal_activity! ⇒ Object
42 43 44 |
# File 'lib/bunny/heartbeat_sender.rb', line 42 def signal_activity! @last_activity_time = Bunny::Timestamp.monotonic end |
#start(period = 30) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bunny/heartbeat_sender.rb', line 25 def start(period = 30) @mutex.synchronize do # calculate interval as half the given period plus # some compensation for Ruby's implementation inaccuracy # (we cannot get at the nanos level the Java client uses, and # our approach is simplistic). MK. @interval = [(period / 2) - 1, 0.4].max @thread = Thread.new(&method(:run)) @thread.report_on_exception = false if @thread.respond_to?(:report_on_exception) end end |
#stop ⇒ Object
38 39 40 |
# File 'lib/bunny/heartbeat_sender.rb', line 38 def stop @mutex.synchronize { @thread.exit } end |