Module: Stomper::Extensions::Heartbeat::V1_1

Defined in:
lib/stomper/extensions/heartbeat.rb

Overview

Stomp Protocol 1.1 extensions to the heart-beating interface

Instance Method Summary collapse

Instance Method Details

#alive?true, false

Stomp 1.1 connections are alive if they are Connection#connected? and are meeting their negotiated heart-beating obligations.

Returns:

  • (true, false)

See Also:



47
48
49
# File 'lib/stomper/extensions/heartbeat.rb', line 47

def alive?
  connected? && client_alive? && broker_alive?
end

#beatObject

Send a heartbeat to the broker



39
40
41
# File 'lib/stomper/extensions/heartbeat.rb', line 39

def beat
  transmit ::Stomper::Frame.new
end

#broker_alive?true, false

Returns true if the broker is alive. Broker is alive if broker heartbeating is disabled, or the number of milliseconds that have passed since last receiving is less than or equal to broker limit

Returns:

  • (true, false)

See Also:



90
91
92
93
# File 'lib/stomper/extensions/heartbeat.rb', line 90

def broker_alive?
  @connecting || heartbeat_broker_limit == 0 ||
    duration_since_received <= heartbeat_broker_limit
end

#client_alive?true, false

Returns true if the client is alive. Client is alive if client heartbeating is disabled, or the number of milliseconds that have passed since last transmission is less than or equal to client limit

Returns:

  • (true, false)

See Also:



77
78
79
80
81
82
# File 'lib/stomper/extensions/heartbeat.rb', line 77

def client_alive?
  # Consider some benchmarking to determine if this is faster than
  # re-writing the method after its first invocation.
  @connecting || heartbeat_client_limit == 0 ||
    duration_since_transmitted <= heartbeat_client_limit
end

#heartbeat_broker_limitFixnum

Maximum number of milliseconds that can pass between frames / heartbeats received before we consider the broker to be dead.

Returns:

  • (Fixnum)


64
65
66
67
68
69
# File 'lib/stomper/extensions/heartbeat.rb', line 64

def heartbeat_broker_limit
  unless defined?(@heartbeat_broker_limit)
    @heartbeat_broker_limit = heartbeating[1] > 0 ? (1.1 * heartbeating[1]) : 0
  end
  @heartbeat_broker_limit
end

#heartbeat_client_limitFixnum

Maximum number of milliseconds that can pass between frame / heartbeat transmissions before we consider the client to be dead.

Returns:

  • (Fixnum)


54
55
56
57
58
59
# File 'lib/stomper/extensions/heartbeat.rb', line 54

def heartbeat_client_limit
  unless defined?(@heartbeat_client_limit)
    @heartbeat_client_limit = heartbeating[0] > 0 ? (1.1 * heartbeating[0]) : 0
  end
  @heartbeat_client_limit
end