Module: ModernTimes::JMS::Connection
Instance Method Summary collapse
- #close ⇒ Object
- #connection ⇒ Object
-
#create_consumer_session ⇒ Object
Create a session targeted for a consumer (producers should use the session_pool).
-
#init(config) ⇒ Object
Initialize the messaging system and connection pool for this VM.
- #inited? ⇒ Boolean
- #log_times? ⇒ Boolean
- #session_pool ⇒ Object
Instance Method Details
#close ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/modern_times/jms/connection.rb', line 52 def close return if @closed ModernTimes.logger.info "Closing #{self.name}" @session_pool.close if @session_pool if @connection @connection.stop @connection.close end @closed = true end |
#connection ⇒ Object
63 64 65 66 |
# File 'lib/modern_times/jms/connection.rb', line 63 def connection raise "#{self.name} never had it's init method called" unless @connection @connection end |
#create_consumer_session ⇒ Object
Create a session targeted for a consumer (producers should use the session_pool)
38 39 40 |
# File 'lib/modern_times/jms/connection.rb', line 38 def create_consumer_session connection.create_session(@config || {}) end |
#init(config) ⇒ Object
Initialize the messaging system and connection pool for this VM
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/modern_times/jms/connection.rb', line 11 def init(config) @config = config @inited = true @log_times = config.delete(:log_times) # Default to true @log_times = true if @log_times.nil? # Let's not create a session_pool unless we're going to use it @session_pool_mutex = Mutex.new @connection = ::JMS::Connection.new(config) @connection.start at_exit do close end end |
#inited? ⇒ Boolean
29 30 31 |
# File 'lib/modern_times/jms/connection.rb', line 29 def inited? @inited end |
#log_times? ⇒ Boolean
33 34 35 |
# File 'lib/modern_times/jms/connection.rb', line 33 def log_times? @log_times end |
#session_pool ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/modern_times/jms/connection.rb', line 42 def session_pool # Don't use the mutex unless we have to! return @session_pool if @session_pool @session_pool_mutex.synchronize do # if it's been created in between the above call and now, return it return @session_pool if @session_pool return @session_pool = connection.create_session_pool(@config) end end |