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
22
23
# 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
rescue
  raise Errors::Janus::TransactionHandle::Initialize
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



31
32
33
34
35
36
37
38
39
40
# File 'lib/rrj/janus/transactions/handle.rb', line 31

def connect
  rabbit.transaction_short do
    choose_queue
    create_handle if @handle.eql?(0)
    yield
  end
  handle
rescue
  raise Errors::Janus::TransactionHandle::Connect
end

#detachObject

Send a message detach



57
58
59
60
61
62
63
64
# File 'lib/rrj/janus/transactions/handle.rb', line 57

def detach
  options = opts.merge('instance' => @instance)
  Tools::Log.instance.debug "Detach handle #{options}"
  publisher.publish(Janus::Messages::Standard.new('base::detach',
                                                  options))
rescue
  raise Errors::Janus::TransactionHandle::Detach
end

#detach_for_deletingObject

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



68
69
70
71
72
73
# File 'lib/rrj/janus/transactions/handle.rb', line 68

def detach_for_deleting
  detach
  Models::JanusInstance.disable(opts['session_id'])
rescue
  raise Errors::Janus::TransactionHandle::DetachForDeleting
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:



48
49
50
51
52
53
54
# File 'lib/rrj/janus/transactions/handle.rb', line 48

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)
rescue
  raise Errors::Janus::TransactionHandle::PublishMessage
end