class RubyRabbitmqJanus::Janus::Transactions::Handle

@author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>

This class work with janus and send a series of message

Public Class Methods

new(exclusive, session, handle = 0, instance = 1) click to toggle source

Initialize a transaction with handle

@param [Fixnum] session

Use a session identifier for created message
Calls superclass method
# File lib/rrj/janus/transactions/handle.rb, line 16
def initialize(exclusive, session, handle = 0, instance = 1)
  super(session)
  @exclusive = exclusive
  @handle = handle
  @instance = instance
end

Public Instance Methods

connect() { || ... } click to toggle source

Opening a long transaction with rabbitmq and is ending closing transaction, so delete exclusive queue

@yield Send a message to Janus

@return [Fixnum] Sender using in current transaction

# File lib/rrj/janus/transactions/handle.rb, line 29
def connect
  rabbit.transaction_short do
    choose_queue
    create_handle if @handle.eql?(0)
    yield
  end
  handle
end
detach() click to toggle source

Send a message detach

# File lib/rrj/janus/transactions/handle.rb, line 51
def detach
  options = opts.merge('instance' => @instance)
  ::Log.debug "Detach handle #{options}"
  publisher.publish(Janus::Messages::Standard.new('base::detach',
                                                  options))
end
detach_for_deleting() click to toggle source

Send a message detach and disable session for deleting in Janus Instance

# File lib/rrj/janus/transactions/handle.rb, line 60
def detach_for_deleting
  detach
  Models::JanusInstance.disable(opts['session_id'])
end
publish_message(type, options = {}) click to toggle source

Publish an message in handle

@param [String] type Request file used @param [Hash] options Replace/add element in request

@return [Janus::Responses::Standard] Response to message sending

# File lib/rrj/janus/transactions/handle.rb, line 44
def publish_message(type, options = {})
  msg = Janus::Messages::Standard.new(type, options.merge(opts))
  response = read_response(publisher.publish(msg))
  Janus::Responses::Standard.new(response)
end

Private Instance Methods

create_handle() click to toggle source
# File lib/rrj/janus/transactions/handle.rb, line 67
def create_handle
  opt = { 'session_id' => session, 'instance' => @instance }
  msg = Janus::Messages::Standard.new('base::attach', opt)
  @handle = send_a_message_exclusive { msg }
end
opts() click to toggle source
# File lib/rrj/janus/transactions/handle.rb, line 87
def opts
  { 'session_id' => session, 'handle_id' => @handle }
end
read_response_exclusive() { || ... } click to toggle source

rubocop:enable Style/ExplicitBlockArgument

# File lib/rrj/janus/transactions/handle.rb, line 81
def read_response_exclusive
  chan = rabbit.channel
  tmp_publish = Rabbit::Publisher::Exclusive.new(chan, '')
  tmp_publish.publish(yield)
end
send_a_message_exclusive() { || ... } click to toggle source

rubocop:disable Style/ExplicitBlockArgument

# File lib/rrj/janus/transactions/handle.rb, line 74
def send_a_message_exclusive
  Janus::Responses::Standard.new(read_response_exclusive do
    yield
  end).sender
end