Module: OnStomp::Interfaces::ClientEvents

Includes:
EventManager
Included in:
Client
Defined in:
lib/onstomp/interfaces/client_events.rb

Overview

Mixin for client events There are a few special event methods that will be passed on to the client's connection, they are:

  • on_connection_established => OnStomp::Interfaces::ConnectionEvents#on_established
  • on_connection_died => OnStomp::Interfaces::ConnectionEvents#on_died
  • on_connection_terminated => OnStomp::Interfaces::ConnectionEvents#on_terminated
  • on_connection_closed => OnStomp::Interfaces::ConnectionEvents#on_closed

Instance Method Summary collapse

Methods included from EventManager

#bind_event, #event_callbacks, included, #trigger_event

Instance Method Details

#pending_connection_events{Symbol => Array<Proc>}

Returns a hash of event bindings that should be set on a connection, but were set on the client because the connection does not exist yet.

Returns:

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


144
145
146
# File 'lib/onstomp/interfaces/client_events.rb', line 144

def pending_connection_events
  @pending_connection_events ||= Hash.new { |h,k| h[k] = [] }
end

#trigger_after_receiving(f) ⇒ Object

Triggers the :after_receiving event and the on prefixed frame specific event (eg: :on_message)

Parameters:



171
172
173
174
# File 'lib/onstomp/interfaces/client_events.rb', line 171

def trigger_after_receiving f
  trigger_event :after_receiving, f, self
  trigger_frame_event f, :on, :broker
end

#trigger_after_transmitting(f) ⇒ Object

Triggers the :after_transmitting event and the on prefixed frame specific event (eg: :on_send).

Parameters:



187
188
189
190
# File 'lib/onstomp/interfaces/client_events.rb', line 187

def trigger_after_transmitting f
  trigger_event :after_transmitting, f, self
  trigger_frame_event f, :on, :client
end

#trigger_before_receiving(f) ⇒ Object

Triggers the :before_receiving event and the before prefixed frame specific event (eg: :before_error).

Parameters:



163
164
165
166
# File 'lib/onstomp/interfaces/client_events.rb', line 163

def trigger_before_receiving f
  trigger_event :before_receiving, f, self
  trigger_frame_event f, :before, :broker
end

#trigger_before_transmitting(f) ⇒ Object

Triggers the :before_transmitting event and the before prefixed frame specific event (eg: :before_disconnect).

Parameters:



179
180
181
182
# File 'lib/onstomp/interfaces/client_events.rb', line 179

def trigger_before_transmitting f
  trigger_event :before_transmitting, f, self
  trigger_frame_event f, :before, :client
end

#trigger_frame_event(f, pref, origin) ⇒ Object

Triggers an event named by the supplied frame, prefixed with the supplied prefix. If the supplied frame is a 'heart-beat', origin will be used to dispatch appropriate heart-beat event (client_beat or broker_beat)

Parameters:

  • f (OnStomp::Components::Frame)

    the frame trigger this event

  • pref (:on, :before, etc)

    the prefix for the event name

  • origin (:client, :broker)


154
155
156
157
158
# File 'lib/onstomp/interfaces/client_events.rb', line 154

def trigger_frame_event f, pref, origin
  e = f.command ? :"#{pref}_#{f.command.downcase}" :
    :"#{pref}_#{origin}_beat"
  trigger_event e, f, self
end