Class: RubyRabbitmqJanus::Janus::Event

Inherits:
OneThread
  • Object
show all
Includes:
Singleton
Defined in:
lib/rrj/janus/threads/event.rb

Overview

For listen standard queue ("from-janus" by default)

Instance Attribute Summary

Attributes inherited from OneThread

#condition, #lock, #rabbit

Instance Method Summary collapse

Methods inherited from OneThread

#start_thread

Constructor Details

#initializeEvent

Initialize Event object. Is used for listen an standard out queue to Janus



11
12
13
14
15
16
# File 'lib/rrj/janus/threads/event.rb', line 11

def initialize
  Tools::Log.instance.debug 'Start listen events in from-janus queue'
  @response = nil
  super
  listen_live
end

Instance Method Details

#initialize_threadObject (private)

Intialize an listen to queue



32
33
34
35
36
37
# File 'lib/rrj/janus/threads/event.rb', line 32

def initialize_thread
  start_transaction
rescue Interrupt
  Tools::Log.instance.info 'Stop to listen standard queue'
  rabbit.close
end

#listenObject

Start listen queue and return each message



19
20
21
22
# File 'lib/rrj/janus/threads/event.rb', line 19

def listen
  lock.synchronize { condition.wait(lock) }
  @response
end

#listen_liveObject (private)

Listen q queue "from-janus"



27
28
29
# File 'lib/rrj/janus/threads/event.rb', line 27

def listen_live
  start_thread
end

#start_transactionObject (private)

Start a transaction with Rabbit an Janus



40
41
42
43
44
45
46
# File 'lib/rrj/janus/threads/event.rb', line 40

def start_transaction
  rabbit.transaction_long do
    publisher = Rabbit::Publisher::Listener.new(rabbit)
    @response = publisher.listen_events
    lock.synchronize { condition.signal }
  end
end