Module: Stomper::Extensions::Events

Included in:
Connection
Defined in:
lib/stomper/extensions/events.rb

Overview

Module for event based extensions.

Constant Summary collapse

ALIASED_EVENTS =

A mapping of event names that are just aliases for other event names.

{
  :on_stomp => :on_connect,
  :before_stomp => :before_connect,
  :on_connection_disconnected => :on_connection_closed
}

Instance Method Summary collapse

Instance Method Details

#after_receiving(&block) ⇒ self

Register a callback to be fired after receiving any frame. Like the #before_transmitting event, any changes made to the frame will be passed along to all remaining #after_receiving callbacks. Furhter, changing the command attribute of the frame will change the frame-specific event that is triggered.

Returns:

  • (self)


177
# File 'lib/stomper/extensions/events.rb', line 177

def after_receiving(&block); bind_callback(:after_receiving, block); end

#after_transmitting(&block) ⇒ self

Register a callback to be fired after transmitting any frame. Changes made to the frame object will be passed along to all remaining #after_transmitting callbacks. Furhter, changing the command attribute of the frame will change the frame-specific event that is triggered.

Returns:

  • (self)


163
# File 'lib/stomper/extensions/events.rb', line 163

def after_transmitting(&block); bind_callback(:after_transmitting, block); end

#before_abort(&block) ⇒ self

Register a callback to be fired before an ABORT frame is sent to the broker.

Returns:

  • (self)


17
# File 'lib/stomper/extensions/events.rb', line 17

def before_abort(&block); bind_callback(:before_abort, block); end

#before_ack(&block) ⇒ self

Register a callback to be fired before an ACK frame is sent to the broker.

Returns:

  • (self)


24
# File 'lib/stomper/extensions/events.rb', line 24

def before_ack(&block); bind_callback(:before_ack, block); end

#before_begin(&block) ⇒ self

Register a callback to be fired before a BEGIN frame is sent to the broker.

Returns:

  • (self)


31
# File 'lib/stomper/extensions/events.rb', line 31

def before_begin(&block); bind_callback(:before_begin, block); end

#before_client_beat(&block) ⇒ self

Register a callback to be fired before a heartbeat frame is sent to the broker.

Returns:

  • (self)


105
# File 'lib/stomper/extensions/events.rb', line 105

def before_client_beat(&block); bind_callback(:before_client_beat, block); end

#before_commit(&block) ⇒ self

Register a callback to be fired before a COMMIT frame is sent to the broker.

Returns:

  • (self)


38
# File 'lib/stomper/extensions/events.rb', line 38

def before_commit(&block); bind_callback(:before_commit, block); end

#before_connect(&block) ⇒ self Also known as: before_stomp

Register a callback to be fired before a CONNECT frame is sent to the broker.

Returns:

  • (self)


45
# File 'lib/stomper/extensions/events.rb', line 45

def before_connect(&block); bind_callback(:before_connect, block); end

#before_disconnect(&block) ⇒ self

Register a callback to be fired before a DISCONNECT frame is sent to the broker.

Returns:

  • (self)


58
# File 'lib/stomper/extensions/events.rb', line 58

def before_disconnect(&block); bind_callback(:before_disconnect, block); end

#before_nack(&block) ⇒ self

Register a callback to be fired before a NACK frame is sent to the broker.

Returns:

  • (self)


73
# File 'lib/stomper/extensions/events.rb', line 73

def before_nack(&block); bind_callback(:before_nack, block); end

#before_receiving(&block) ⇒ self

Register a callback to be fired before receiving any frame. As a frame has not yet been received, callbacks invoked on this event will have to work with very limited information.

Returns:

  • (self)


169
# File 'lib/stomper/extensions/events.rb', line 169

def before_receiving(&block); bind_callback(:before_receiving, block); end

#before_send(&block) ⇒ self

Register a callback to be fired before a SEND frame is sent to the broker.

Returns:

  • (self)


84
# File 'lib/stomper/extensions/events.rb', line 84

def before_send(&block); bind_callback(:before_send, block); end

#before_subscribe(&block) ⇒ self

Register a callback to be fired before a SUBSCRIBE frame is sent to the broker.

Returns:

  • (self)


91
# File 'lib/stomper/extensions/events.rb', line 91

def before_subscribe(&block); bind_callback(:before_subscribe, block); end

#before_transmitting(&block) ⇒ self

Register a callback to be fired before transmitting any frame. If the supplied block makes any changes to the frame argument, those changes will be sent to the remaining #before_transmitting callbacks, and ultimately will be passed on to the broker. This provides a convenient way to modify frames before transmission without having to subclass or otherwise extend the Connection class. Furhter, changing the command attribute of the frame will change the frame-specific event that is triggered.

Returns:

  • (self)


155
# File 'lib/stomper/extensions/events.rb', line 155

def before_transmitting(&block); bind_callback(:before_transmitting, block); end

#before_unsubscribe(&block) ⇒ self

Register a callback to be fired before an UNSUBSCRIBE frame is sent to the broker.

Returns:

  • (self)


98
# File 'lib/stomper/extensions/events.rb', line 98

def before_unsubscribe(&block); bind_callback(:before_unsubscribe, block); end

#bind_callback(event_name, cb_proc) ⇒ self

Binds a Proc to be invoked when the given event_name is triggered.

Parameters:

  • event_name (Symbol)
  • cb_proc (Proc)

Returns:

  • (self)


183
184
185
186
187
188
# File 'lib/stomper/extensions/events.rb', line 183

def bind_callback(event_name, cb_proc)
  @event_callbacks ||= {}
  @event_callbacks[event_name] ||= []
  @event_callbacks[event_name] << cb_proc
  self
end

#on_abort(&block) ⇒ self

Register a callback to be fired when an ABORT frame is sent to the broker.

Returns:

  • (self)


14
# File 'lib/stomper/extensions/events.rb', line 14

def on_abort(&block); bind_callback(:on_abort, block); end

#on_ack(&block) ⇒ self

Register a callback to be fired when an ACK frame is sent to the broker.

Returns:

  • (self)


21
# File 'lib/stomper/extensions/events.rb', line 21

def on_ack(&block); bind_callback(:on_ack, block); end

#on_begin(&block) ⇒ self

Register a callback to be fired when a BEGIN frame is sent to the broker.

Returns:

  • (self)


28
# File 'lib/stomper/extensions/events.rb', line 28

def on_begin(&block); bind_callback(:on_begin, block); end

#on_broker_beat(&block) ⇒ self

Register a callback to be fired when a heartbeat is received from the broker.

Returns:

  • (self)


110
# File 'lib/stomper/extensions/events.rb', line 110

def on_broker_beat(&block); bind_callback(:on_broker_beat, block); end

#on_client_beat(&block) ⇒ self

Register a callback to be fired when a heartbeat is sent to the broker.

Returns:

  • (self)


102
# File 'lib/stomper/extensions/events.rb', line 102

def on_client_beat(&block); bind_callback(:on_client_beat, block); end

#on_commit(&block) ⇒ self

Register a callback to be fired when a COMMIT frame is sent to the broker.

Returns:

  • (self)


35
# File 'lib/stomper/extensions/events.rb', line 35

def on_commit(&block); bind_callback(:on_commit, block); end

#on_connect(&block) ⇒ self Also known as: on_stomp

Register a callback to be fired when a CONNECT frame is sent to the broker.

Returns:

  • (self)


42
# File 'lib/stomper/extensions/events.rb', line 42

def on_connect(&block); bind_callback(:on_connect, block); end

#on_connected(&block) ⇒ self

Register a callback to be fired when a CONNECTED frame is received from the broker.

Returns:

  • (self)


51
# File 'lib/stomper/extensions/events.rb', line 51

def on_connected(&block); bind_callback(:on_connected, block); end

#on_connection_closed(&block) ⇒ self Also known as: on_connection_disconnected

Register a callback to be fired when a connection to the broker has been closed. This event will be triggered by Connection#disconnect as well as any IO exception that shuts the connection down. In the event that the socket closes unexpectedly, #on_connection_terminated will be triggered before this event.

Returns:

  • (self)

See Also:



127
# File 'lib/stomper/extensions/events.rb', line 127

def on_connection_closed(&block); bind_callback(:on_connection_closed, block); end

#on_connection_died(&block) ⇒ self

Note:

This event is not triggered the moment heartbeat death occurs.

Register a callback to be fired when a connection to the broker has died as per the negotiated heartbeat strategy. This event is triggered through Connection#transmit and Connection#receive when heartbeat death has been detected. You should not expect this event to trigger at the precise moment the heartbeat strategy failed.

Returns:

  • (self)


137
# File 'lib/stomper/extensions/events.rb', line 137

def on_connection_died(&block); bind_callback(:on_connection_died, block); end

#on_connection_established(&block) ⇒ self

Register a callback to be fired when a connection to the broker has been fully established. The connection is fully established once the client has sent a CONNECT frame, the broker has replied with CONNECTED and protocol versions and heartbeat strategies have been negotiated (if applicable.)

Returns:

  • (self)


118
# File 'lib/stomper/extensions/events.rb', line 118

def on_connection_established(&block); bind_callback(:on_connection_established, block); end

#on_connection_terminated(&block) ⇒ self

Register a callback to be fired when a connection to the broker has been unexpectedly terminated. This event will NOT be triggered by Connection#disconnect.

Returns:

  • (self)

See Also:



144
# File 'lib/stomper/extensions/events.rb', line 144

def on_connection_terminated(&block); bind_callback(:on_connection_terminated, block); end

#on_disconnect(&block) ⇒ self

Register a callback to be fired when a DISCONNECT frame is sent to the broker.

Returns:

  • (self)


55
# File 'lib/stomper/extensions/events.rb', line 55

def on_disconnect(&block); bind_callback(:on_disconnect, block); end

#on_error(&block) ⇒ self

Register a callback to be fired when an ERROR frame is received from the broker.

Returns:

  • (self)


62
# File 'lib/stomper/extensions/events.rb', line 62

def on_error(&block); bind_callback(:on_error, block); end

#on_message(&block) ⇒ self

Register a callback to be fired when a MESSAGE frame is received from the broker.

Returns:

  • (self)


66
# File 'lib/stomper/extensions/events.rb', line 66

def on_message(&block); bind_callback(:on_message, block); end

#on_nack(&block) ⇒ self

Register a callback to be fired when a NACK frame is sent to the broker.

Returns:

  • (self)


70
# File 'lib/stomper/extensions/events.rb', line 70

def on_nack(&block); bind_callback(:on_nack, block); end

#on_receipt(&block) ⇒ self

Register a callback to be fired when a RECEIPT frame is received from the broker.

Returns:

  • (self)


77
# File 'lib/stomper/extensions/events.rb', line 77

def on_receipt(&block); bind_callback(:on_receipt, block); end

#on_send(&block) ⇒ self

Register a callback to be fired when a SEND frame is sent to the broker.

Returns:

  • (self)


81
# File 'lib/stomper/extensions/events.rb', line 81

def on_send(&block); bind_callback(:on_send, block); end

#on_subscribe(&block) ⇒ self

Register a callback to be fired when a SUBSCRIBE frame is sent to the broker.

Returns:

  • (self)


88
# File 'lib/stomper/extensions/events.rb', line 88

def on_subscribe(&block); bind_callback(:on_subscribe, block); end

#on_unsubscribe(&block) ⇒ self

Register a callback to be fired when an UNSUBSCRIBE frame is sent to the broker.

Returns:

  • (self)


95
# File 'lib/stomper/extensions/events.rb', line 95

def on_unsubscribe(&block); bind_callback(:on_unsubscribe, block); end