Module: OnStomp::Connections::Heartbeating

Included in:
Stomp_1_1
Defined in:
lib/onstomp/connections/heartbeating.rb

Overview

Mixin for connections to include heartbeating functionality.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- ([Fixnum, Fixnum]) heartbeating (readonly)

A pair of integers indicating the maximum number of milliseconds the client and broker can go without transmitting data respectively. If either value is 0, the respective heartbeating is not enabled.

Returns:

  • ([Fixnum, Fixnum])


9
10
11
# File 'lib/onstomp/connections/heartbeating.rb', line 9

def heartbeating
  @heartbeating
end

Instance Method Details

- (true, false) broker_pulse?

Returns true if broker-side heartbeating is disabled, or Base#duration_since_received has not exceeded #heartbeat_broker_limit

Returns:

  • (true, false)


65
66
67
# File 'lib/onstomp/connections/heartbeating.rb', line 65

def broker_pulse?
  heartbeat_broker_limit == 0 || duration_since_received <= heartbeat_broker_limit
end

- (true, false) client_pulse?

Returns true if client-side heartbeating is disabled, or Base#duration_since_transmitted has not exceeded #heartbeat_client_limit

Returns:

  • (true, false)


58
59
60
# File 'lib/onstomp/connections/heartbeating.rb', line 58

def client_pulse?
  heartbeat_client_limit == 0 || duration_since_transmitted <= heartbeat_client_limit
end

- (Object) configure_heartbeating(client_beats, broker_beats)

Configures heartbeating strategy by taking the maximum timeout for clients and brokers. If either pair contains a zero, the respective beating is disabled.

Parameters:

  • client_beats ([Fixnum, Fixnum])
  • broker_beats ([Fixnum, Fixnum])


16
17
18
19
20
21
# File 'lib/onstomp/connections/heartbeating.rb', line 16

def configure_heartbeating client_beats, broker_beats
  c_x, c_y = client_beats
  s_x, s_y = broker_beats
  @heartbeating = [ (c_x == 0||s_y == 0 ? 0 : [c_x,s_y].max), 
    (c_y == 0||s_x == 0 ? 0 : [c_y,s_x].max) ]
end

- (Fixnum) heartbeat_broker_limit

Maximum number of milliseconds allowed between bytes being sent from the broker, or 0 if there is no limit. This method will add a 10% margin of error to the timeout determined from heartbeat negotiation to allow a little slack before a connection is deemed dead.

Returns:

  • (Fixnum)


48
49
50
51
52
53
# File 'lib/onstomp/connections/heartbeating.rb', line 48

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

- (Fixnum) heartbeat_client_limit

Maximum number of milliseconds allowed between bytes being sent by the client, or 0 if there is no limit. This method will add a 10% margin of error to the timeout determined from heartbeat negotiation to allow a little slack before a connection is deemed dead.

Returns:

  • (Fixnum)


36
37
38
39
40
41
# File 'lib/onstomp/connections/heartbeating.rb', line 36

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

- (true, false) pulse?

Returns true if both the client and broker are transmitting data in accordance with the heartbeating strategy. If this method returns false, the connection is effectively dead and should be closed

Returns:

  • (true, false)


27
28
29
# File 'lib/onstomp/connections/heartbeating.rb', line 27

def pulse?
  client_pulse? && broker_pulse?
end