Class: TorqueBox::Messaging::Connection
- Inherits:
-
Object
- Object
- TorqueBox::Messaging::Connection
- Includes:
- Injectors
- Defined in:
- lib/torquebox/messaging/connection.rb
Instance Method Summary collapse
- #activate(session) ⇒ Object
- #client_id ⇒ Object
- #client_id=(client_id) ⇒ Object
- #close ⇒ Object
- #create_session ⇒ Object
- #create_xa_session ⇒ Object
- #current ⇒ Object
- #deactivate ⇒ Object
-
#initialize(jms_connection) ⇒ Connection
constructor
A new instance of Connection.
- #sessions ⇒ Object
- #start ⇒ Object
- #transaction ⇒ Object
- #with_session(enlist_tx = true) ⇒ Object
Constructor Details
#initialize(jms_connection) ⇒ Connection
Returns a new instance of Connection.
26 27 28 29 |
# File 'lib/torquebox/messaging/connection.rb', line 26 def initialize(jms_connection) @jms_connection = jms_connection @tm = fetch('transaction-manager') end |
Instance Method Details
#activate(session) ⇒ Object
67 68 69 |
# File 'lib/torquebox/messaging/connection.rb', line 67 def activate(session) sessions.push(session) && current end |
#client_id ⇒ Object
39 40 41 |
# File 'lib/torquebox/messaging/connection.rb', line 39 def client_id @jms_connection.client_id end |
#client_id=(client_id) ⇒ Object
43 44 45 |
# File 'lib/torquebox/messaging/connection.rb', line 43 def client_id=(client_id) @jms_connection.client_id = client_id end |
#close ⇒ Object
35 36 37 |
# File 'lib/torquebox/messaging/connection.rb', line 35 def close @jms_connection.close end |
#create_session ⇒ Object
86 87 88 |
# File 'lib/torquebox/messaging/connection.rb', line 86 def create_session Session.new( @jms_connection.create_session( false, Session::AUTO_ACK ) ) end |
#create_xa_session ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/torquebox/messaging/connection.rb', line 78 def create_xa_session jms_session = @jms_connection.create_xa_session() transaction.enlist_resource( jms_session.xa_resource ) session = TransactedSession.new( jms_session, transaction, self ) transaction.registerSynchronization( session ) session end |
#current ⇒ Object
64 65 66 |
# File 'lib/torquebox/messaging/connection.rb', line 64 def current sessions.last end |
#deactivate ⇒ Object
70 71 72 |
# File 'lib/torquebox/messaging/connection.rb', line 70 def deactivate sessions.pop.close end |
#sessions ⇒ Object
61 62 63 |
# File 'lib/torquebox/messaging/connection.rb', line 61 def sessions Thread.current[:session] ||= [] end |
#start ⇒ Object
31 32 33 |
# File 'lib/torquebox/messaging/connection.rb', line 31 def start @jms_connection.start end |
#transaction ⇒ Object
74 75 76 |
# File 'lib/torquebox/messaging/connection.rb', line 74 def transaction @tm && @tm.transaction end |
#with_session(enlist_tx = true) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/torquebox/messaging/connection.rb', line 47 def with_session(enlist_tx = true) if !enlist_tx || (current.nil? && !transaction) begin yield activate( create_session ) ensure deactivate end elsif transaction && (!current.respond_to?(:transaction) || current.transaction != transaction) yield activate( create_xa_session ) else yield( current ) end end |