Class: Stomper::ReceiptManager

Inherits:
Object
  • Object
show all
Defined in:
lib/stomper/receipt_manager.rb

Overview

Manages receipt handling for a Connection

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ ReceiptManager

Creates a new receipt handler for the supplied connection

Parameters:



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/stomper/receipt_manager.rb', line 7

def initialize(connection)
  @mon = ::Monitor.new
  @callbacks = {}
  connection.before_disconnect do |d, con|
    @close_on = d[:receipt] if d[:receipt]
  end
  connection.on_receipt do |r, con|
    dispatch(r)
    connection.close if r[:'receipt-id'] == @close_on
  end
end

Instance Method Details

#add(r_id, callback) ⇒ self

Adds a callback handler for a RECEIPT frame that matches the supplied receipt ID.

Parameters:

  • r_id (String)

    ID of the receipt to match

  • callback (Proc)

    Proc to invoke when a matching RECEIPT frame is received from the broker.

Returns:

  • (self)


25
26
27
28
# File 'lib/stomper/receipt_manager.rb', line 25

def add(r_id, callback)
  @mon.synchronize { @callbacks[r_id] = callback }
  self
end

#clearObject

Remove all receipt handlers.



31
32
33
# File 'lib/stomper/receipt_manager.rb', line 31

def clear
  @mon.synchronize { @callbacks.clear }
end