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>})


125
126
127
# File 'lib/onstomp/interfaces/client_events.rb', line 125

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:



152
153
154
155
# File 'lib/onstomp/interfaces/client_events.rb', line 152

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:



168
169
170
171
# File 'lib/onstomp/interfaces/client_events.rb', line 168

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:



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

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:



160
161
162
163
# File 'lib/onstomp/interfaces/client_events.rb', line 160

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)


135
136
137
138
139
# File 'lib/onstomp/interfaces/client_events.rb', line 135

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