Class: RubyRabbitmqJanus::Janus::Transactions::Handle

Inherits:
Transaction
  • Object
show all
Defined in:
lib/rrj/janus/transactions/handle.rb

Overview

This class work with janus and send a series of message

Author:

Instance Method Summary collapse

Constructor Details

#initialize(exclusive, session, handle = 0, instance = 1) ⇒ Handle

Initialize a transaction with handle

Parameters:

  • session (Fixnum)

    Use a session identifier for created message



16
17
18
19
20
21
# 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

Instance Method Details

#connect { ... } ⇒ Fixnum

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

Yields:

  • Send a message to Janus

Returns:

  • (Fixnum)

    Sender using in current transaction



29
30
31
32
33
34
35
36
# 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

#detachObject

Send a message detach



51
52
53
54
55
56
# 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_deletingObject

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



60
61
62
63
# 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 = {}) ⇒ Janus::Responses::Standard

Publish an message in handle

Parameters:

  • type (String)

    Request file used

  • options (Hash) (defaults to: {})

    Replace/add element in request

Returns:



44
45
46
47
48
# 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