Module: OnStomp::Interfaces::ConnectionEvents

Includes:
EventManager
Included in:
Connections::Base
Defined in:
lib/onstomp/interfaces/connection_events.rb

Overview

Mixin for connection events

Connection State Events (collapse)

Instance Method Summary (collapse)

Methods included from EventManager

#bind_event, #event_callbacks, included, #trigger_event

Instance Method Details

- (Object) blocked {|client, connection| ... }

Binds a callback to be invoked when a connection has been blocked on writing for more than the allowed duration, closing the connection.

Yields:

  • (client, connection)

    callback invoked when event is triggered

Yield Parameters:



41
# File 'lib/onstomp/interfaces/connection_events.rb', line 41

create_event_methods :blocked, :on

- (Object) closed {|client, connection| ... }

Note:

If connection is closed unexpectedly, #on_died is triggered first,

Binds a callback to be invoked when a connection has been closed, either through a graceful disconnect or unexpectedly. followed by this event.

Yields:

  • (client, connection)

    callback invoked when event is triggered

Yield Parameters:



51
# File 'lib/onstomp/interfaces/connection_events.rb', line 51

create_event_methods :closed, :on

- (Object) died {|client, connection| ... }

Note:

Only applies to STOMP 1.1 connections with heartbeating enabled.

Binds a callback to be invoked when a connection has been died due to insufficient data transfer.

Yields:

  • (client, connection)

    callback invoked when event is triggered

Yield Parameters:



25
# File 'lib/onstomp/interfaces/connection_events.rb', line 25

create_event_methods :died, :on

- (Object) established {|client, connection| ... }

Binds a callback to be invoked when a connection has been fully established between broker and client.

Yields:

  • (client, connection)

    callback invoked when event is triggered

Yield Parameters:



16
# File 'lib/onstomp/interfaces/connection_events.rb', line 16

create_event_methods :established, :on

- (Object) install_bindings_from_client(ev_hash)

Takes a hash of event bindings a client has stored and binds them to this connection, then triggers on_established. This allows users to add callbacks for connection events before the connection exist and have said callbacks installed once the connection is created.

Parameters:

  • callbacks ({Symbol => Array<Proc>})

    to install, keyed by event name

See Also:



68
69
70
71
72
73
# File 'lib/onstomp/interfaces/connection_events.rb', line 68

def install_bindings_from_client ev_hash
  ev_hash.each do |ev, cbs|
    cbs.each { |cb| bind_event(ev, cb) }
  end
  trigger_connection_event :established, "STOMP #{self.version} connection negotiated"
end

- (Object) on_blocked {|client, connection| ... }

Binds a callback to be invoked when a connection has been blocked on writing for more than the allowed duration, closing the connection.

Yields:

  • (client, connection)

    callback invoked when event is triggered

Yield Parameters:



41
# File 'lib/onstomp/interfaces/connection_events.rb', line 41

create_event_methods :blocked, :on

- (Object) on_closed {|client, connection| ... }

Note:

If connection is closed unexpectedly, #on_died is triggered first,

Binds a callback to be invoked when a connection has been closed, either through a graceful disconnect or unexpectedly. followed by this event.

Yields:

  • (client, connection)

    callback invoked when event is triggered

Yield Parameters:



51
# File 'lib/onstomp/interfaces/connection_events.rb', line 51

create_event_methods :closed, :on

- (Object) on_died {|client, connection| ... }

Note:

Only applies to STOMP 1.1 connections with heartbeating enabled.

Binds a callback to be invoked when a connection has been died due to insufficient data transfer.

Yields:

  • (client, connection)

    callback invoked when event is triggered

Yield Parameters:



25
# File 'lib/onstomp/interfaces/connection_events.rb', line 25

create_event_methods :died, :on

- (Object) on_established {|client, connection| ... }

Binds a callback to be invoked when a connection has been fully established between broker and client.

Yields:

  • (client, connection)

    callback invoked when event is triggered

Yield Parameters:



16
# File 'lib/onstomp/interfaces/connection_events.rb', line 16

create_event_methods :established, :on

- (Object) on_terminated {|client, connection| ... }

Binds a callback to be invoked when a connection has been terminated (eg: closed unexpectedly due to an exception)

Yields:

  • (client, connection)

    callback invoked when event is triggered

Yield Parameters:



33
# File 'lib/onstomp/interfaces/connection_events.rb', line 33

create_event_methods :terminated, :on

- (Object) terminated {|client, connection| ... }

Binds a callback to be invoked when a connection has been terminated (eg: closed unexpectedly due to an exception)

Yields:

  • (client, connection)

    callback invoked when event is triggered

Yield Parameters:



33
# File 'lib/onstomp/interfaces/connection_events.rb', line 33

create_event_methods :terminated, :on

- (Object) trigger_connection_event(event, msg = '')

Triggers a connection specific event.

Parameters:

  • event (Symbol)

    name



57
58
59
# File 'lib/onstomp/interfaces/connection_events.rb', line 57

def trigger_connection_event event, msg=''
  trigger_event :on_#{event}", self.client, self, msg
end