class Lagomorph::Session
Constants
- CONNECTION_PARAM_KEYS
Attributes
connection[R]
Public Class Methods
connect(connection_params)
click to toggle source
# File lib/lagomorph/session.rb, line 16 def self.connect(connection_params) new(connection_params).tap(&:open_connection) end
new(connection_params)
click to toggle source
# File lib/lagomorph/session.rb, line 21 def initialize(connection_params) @connection_params = connection_params.select { |key,_| CONNECTION_PARAM_KEYS.include?(key) } @mutex = Monitor.new end
Public Instance Methods
close_connection()
click to toggle source
# File lib/lagomorph/session.rb, line 38 def close_connection return if @connection.nil? || @connection.closed? @mutex.synchronize do @connection.close end end
create_channel(prefetch = nil)
click to toggle source
# File lib/lagomorph/session.rb, line 45 def create_channel(prefetch = nil) @mutex.synchronize do channel = @connection.create_channel if Lagomorph.using_bunny? channel.prefetch(prefetch) else channel.prefetch = prefetch end channel end end
open_connection()
click to toggle source
# File lib/lagomorph/session.rb, line 28 def open_connection @mutex.synchronize do @connection ||= if Lagomorph.using_bunny? ::Bunny.new(@connection_params).tap(&:start) else ::MarchHare.connect(@connection_params) end end end