Java Code Examples for javax.transaction.Transaction#delistResource()
The following examples show how to use
javax.transaction.Transaction#delistResource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JCAConnectionManagerImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * CallBack for Connection Error. * * @param event ConnectionEvent */ public void connectionErrorOccurred(ConnectionEvent event) { if (isActive) { // If its an XAConnection ManagedConnection conn = (ManagedConnection) event.getSource(); XAResource xar = (XAResource) xaResourcesMap.get(conn); xaResourcesMap.remove(conn); TransactionManagerImpl transManager = TransactionManagerImpl .getTransactionManager(); try { Transaction txn = transManager.getTransaction(); if (txn != null && xar != null) txn.delistResource(xar, XAResource.TMSUCCESS); } catch (SystemException se) { se.printStackTrace(); } try { mannPoolCache.expirePooledConnection(conn); //mannPoolCache.destroyPooledConnection(conn); } catch (Exception ex) { String exception = "JCAConnectionManagerImpl::connectionErrorOccured: Exception occured due to " + ex; LogWriterI18n writer = TransactionUtils.getLogWriterI18n(); if (writer.fineEnabled()) writer.fine(exception, ex); } } }
Example 2
Source File: JCAConnectionManagerImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * CallBack for Connection Error. * * @param event ConnectionEvent */ public void connectionErrorOccurred(ConnectionEvent event) { if (isActive) { // If its an XAConnection ManagedConnection conn = (ManagedConnection) event.getSource(); XAResource xar = (XAResource) xaResourcesMap.get(conn); xaResourcesMap.remove(conn); TransactionManagerImpl transManager = TransactionManagerImpl .getTransactionManager(); try { Transaction txn = transManager.getTransaction(); if (txn != null && xar != null) txn.delistResource(xar, XAResource.TMSUCCESS); } catch (SystemException se) { se.printStackTrace(); } try { mannPoolCache.expirePooledConnection(conn); //mannPoolCache.destroyPooledConnection(conn); } catch (Exception ex) { String exception = "JCAConnectionManagerImpl::connectionErrorOccured: Exception occured due to " + ex; LogWriterI18n writer = TransactionUtils.getLogWriterI18n(); if (writer.fineEnabled()) writer.fine(exception, ex); } } }
Example 3
Source File: AtomikosTransactionAssistantImpl.java From genericconnector with Apache License 2.0 | 5 votes |
@Override public void close() { UserTransactionManager utm = getTransactionManager(); try { if(utm.getStatus() == Status.STATUS_NO_TRANSACTION){ throw new RuntimeException("no transaction found. please start one before getting the transaction assistant. status was: " + utm.getStatus()); } Transaction tx = utm.getTransaction(); tx.delistResource(ms, ms.getUnderlyingConnection().wasExecuteSuccessful() ? XAResource.TMSUCCESS : XAResource.TMFAIL); } catch (Exception e) { throw new RuntimeException("Unable to delist resource from transaction", e); } }
Example 4
Source File: TxConnectionListener.java From lams with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void dissociate() throws ResourceException { log.tracef("dissociate: %s", this); try { TransactionManager tm = getConnectionManager().getTransactionIntegration().getTransactionManager(); int status = tm.getStatus(); log.tracef("dissociate: status=%s", TxUtils.getStatusAsString(status)); if (status != Status.STATUS_NO_TRANSACTION) { if (isEnlisted()) { if (doDelistResource) { Transaction tx = tm.getTransaction(); boolean delistResult = tx.delistResource(getXAResource(), XAResource.TMSUCCESS); log.tracef("dissociate: delistResult=%s", delistResult); } } else { log.tracef("dissociate: not enlisted (%s)", this); } if (isTrackByTx()) { ManagedConnectionPool mcp = getManagedConnectionPool(); TransactionSynchronizationRegistry tsr = getConnectionManager().getTransactionIntegration().getTransactionSynchronizationRegistry(); Lock lock = (Lock)tsr.getResource(LockKey.INSTANCE); if (lock != null) { try { lock.lockInterruptibly(); } catch (InterruptedException ie) { Thread.interrupted(); throw new ResourceException(bundle.unableObtainLock(), ie); } try { tsr.putResource(mcp, null); } finally { lock.unlock(); } } } } localTransaction.set(false); setTrackByTx(false); if (transactionSynchronization != null) { transactionSynchronization.cancel(); transactionSynchronization = null; } setEnlisted(false); } catch (Throwable t) { throw new ResourceException(bundle.errorInDissociate(), t); } }
Example 5
Source File: XATest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void test2PCSendFailOnPrepare() throws Exception { XAConnection conn = null; Connection conn2 = null; try { conn = xacf.createXAConnection(); tm.begin(); XASession sess = conn.createXASession(); XAResource res = sess.getXAResource(); // prevent 1Pc optimisation // res.setForceNotSameRM(true); XAResource res2 = new DummyXAResource(true); XAResource res3 = new DummyXAResource(); XAResource res4 = new DummyXAResource(); Transaction tx = tm.getTransaction(); tx.enlistResource(res); tx.enlistResource(res2); tx.enlistResource(res3); tx.enlistResource(res4); MessageProducer prod = sess.createProducer(null); prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); Message m = sess.createTextMessage("XATest1"); prod.send(queue1, m); m = sess.createTextMessage("XATest2"); prod.send(queue1, m); tx.delistResource(res, XAResource.TMSUCCESS); tx.delistResource(res2, XAResource.TMSUCCESS); tx.delistResource(res3, XAResource.TMSUCCESS); tx.delistResource(res4, XAResource.TMSUCCESS); try { tm.commit(); Assert.fail("should not get here"); } catch (Exception e) { // We should expect this } conn2 = cf.createConnection(); conn2.start(); Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = sessReceiver.createConsumer(queue1); Message m2 = cons.receive(100); Assert.assertNull(m2); } finally { if (conn != null) { conn.close(); } if (conn2 != null) { conn2.close(); } } }
Example 6
Source File: XATest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void test2PCSendRollback() throws Exception { XAConnection conn = null; Connection conn2 = null; try { conn = xacf.createXAConnection(); tm.begin(); XASession sess = conn.createXASession(); XAResource res = sess.getXAResource(); // prevent 1Pc optimisation // res.setForceNotSameRM(true); XAResource res2 = new DummyXAResource(); Transaction tx = tm.getTransaction(); tx.enlistResource(res); tx.enlistResource(res2); MessageProducer prod = sess.createProducer(null); prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); Message m = sess.createTextMessage("XATest1"); prod.send(queue1, m); m = sess.createTextMessage("XATest2"); prod.send(queue1, m); tx.delistResource(res, XAResource.TMSUCCESS); tx.delistResource(res2, XAResource.TMSUCCESS); tm.rollback(); conn2 = cf.createConnection(); conn2.start(); Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = sessReceiver.createConsumer(queue1); Message m2 = cons.receive(100); Assert.assertNull(m2); } finally { if (conn != null) { conn.close(); } if (conn2 != null) { conn2.close(); } } }
Example 7
Source File: XATest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testMultipleSessionsOneTxCommitAcknowledge1PCOptimization() throws Exception { XAConnection conn = null; Connection conn2 = null; // Since both resources have some RM, TM will probably use 1PC optimization try { // First send 2 messages conn2 = cf.createConnection(); Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer prod = sessProducer.createProducer(queue1); Message m = sessProducer.createTextMessage("jellyfish1"); prod.send(m); m = sessProducer.createTextMessage("jellyfish2"); prod.send(m); conn = xacf.createXAConnection(); conn.start(); tm.begin(); // Create 2 sessions and enlist them XASession sess1 = conn.createXASession(); XAResource res1 = sess1.getXAResource(); XASession sess2 = conn.createXASession(); XAResource res2 = sess2.getXAResource(); Transaction tx = tm.getTransaction(); tx.enlistResource(res1); tx.enlistResource(res2); // Receive the messages, one on each consumer MessageConsumer cons1 = sess1.createConsumer(queue1); TextMessage r1 = (TextMessage) cons1.receive(5000); Assert.assertNotNull(r1); Assert.assertEquals("jellyfish1", r1.getText()); cons1.close(); MessageConsumer cons2 = sess2.createConsumer(queue1); TextMessage r2 = (TextMessage) cons2.receive(5000); Assert.assertNotNull(r2); Assert.assertEquals("jellyfish2", r2.getText()); tx.delistResource(res1, XAResource.TMSUCCESS); tx.delistResource(res2, XAResource.TMSUCCESS); // commit tm.commit(); Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = sess.createConsumer(queue1); conn2.start(); TextMessage r3 = (TextMessage) cons.receive(100); Assert.assertNull(r3); } finally { if (conn != null) { conn.close(); } if (conn2 != null) { conn2.close(); } } }
Example 8
Source File: XATest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testMultipleSessionsOneTxCommitAcknowledge() throws Exception { XAConnection conn = null; Connection conn2 = null; try { // First send 2 messages conn2 = cf.createConnection(); Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer prod = sessProducer.createProducer(queue1); Message m = sessProducer.createTextMessage("jellyfish1"); prod.send(m); m = sessProducer.createTextMessage("jellyfish2"); prod.send(m); conn = xacf.createXAConnection(); conn.start(); tm.begin(); // Create 2 sessions and enlist them XASession sess1 = conn.createXASession(); ClientSessionInternal res1 = (ClientSessionInternal) sess1.getXAResource(); XASession sess2 = conn.createXASession(); ClientSessionInternal res2 = (ClientSessionInternal) sess2.getXAResource(); res1.setForceNotSameRM(true); res2.setForceNotSameRM(true); Transaction tx = tm.getTransaction(); tx.enlistResource(res1); tx.enlistResource(res2); // Receive the messages, one on each consumer MessageConsumer cons1 = sess1.createConsumer(queue1); TextMessage r1 = (TextMessage) cons1.receive(5000); Assert.assertNotNull(r1); Assert.assertEquals("jellyfish1", r1.getText()); cons1.close(); MessageConsumer cons2 = sess2.createConsumer(queue1); TextMessage r2 = (TextMessage) cons2.receive(5000); Assert.assertNotNull(r2); Assert.assertEquals("jellyfish2", r2.getText()); tx.delistResource(res1, XAResource.TMSUCCESS); tx.delistResource(res2, XAResource.TMSUCCESS); // commit tm.commit(); Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = sess.createConsumer(queue1); conn2.start(); TextMessage r3 = (TextMessage) cons.receive(100); Assert.assertNull(r3); } finally { if (conn != null) { conn.close(); } if (conn2 != null) { conn2.close(); } } }
Example 9
Source File: XATest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testMultipleSessionsOneTxCommitSend1PCOptimization() throws Exception { // Since both resources have some RM, TM will probably use 1PC optimization XAConnection conn = null; Connection conn2 = null; try { conn = xacf.createXAConnection(); conn.start(); tm.begin(); // Create 2 sessions and enlist them XASession sess1 = conn.createXASession(); XAResource res1 = sess1.getXAResource(); XASession sess2 = conn.createXASession(); XAResource res2 = sess2.getXAResource(); Transaction tx = tm.getTransaction(); tx.enlistResource(res1); tx.enlistResource(res2); // Send 2 messages - one from each session MessageProducer prod1 = sess1.createProducer(queue1); MessageProducer prod2 = sess2.createProducer(queue1); prod1.send(sess1.createTextMessage("echidna1")); prod2.send(sess2.createTextMessage("echidna2")); tx.delistResource(res1, XAResource.TMSUCCESS); tx.delistResource(res2, XAResource.TMSUCCESS); // commit tm.commit(); // Messages should be in queue conn2 = cf.createConnection(); Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = sess.createConsumer(queue1); conn2.start(); TextMessage r1 = (TextMessage) cons.receive(5000); Assert.assertNotNull(r1); Assert.assertEquals("echidna1", r1.getText()); TextMessage r2 = (TextMessage) cons.receive(5000); Assert.assertNotNull(r2); Assert.assertEquals("echidna2", r2.getText()); } finally { if (conn != null) { conn.close(); } if (conn2 != null) { conn2.close(); } } }
Example 10
Source File: XATest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testMultipleSessionsOneTxCommitSend() throws Exception { // Since both resources have some RM, TM will probably use 1PC optimization XAConnection conn = null; Connection conn2 = null; try { conn = xacf.createXAConnection(); conn.start(); tm.begin(); // Create 2 sessions and enlist them XASession sess1 = conn.createXASession(); ClientSessionInternal res1 = (ClientSessionInternal) sess1.getXAResource(); XASession sess2 = conn.createXASession(); ClientSessionInternal res2 = (ClientSessionInternal) sess2.getXAResource(); res1.setForceNotSameRM(true); res2.setForceNotSameRM(true); Transaction tx = tm.getTransaction(); tx.enlistResource(res1); tx.enlistResource(res2); // Send 2 messages - one from each session MessageProducer prod1 = sess1.createProducer(queue1); MessageProducer prod2 = sess2.createProducer(queue1); prod1.send(sess1.createTextMessage("echidna1")); prod2.send(sess2.createTextMessage("echidna2")); tx.delistResource(res1, XAResource.TMSUCCESS); tx.delistResource(res2, XAResource.TMSUCCESS); // commit tm.commit(); // Messages should be in queue conn2 = cf.createConnection(); Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = sess.createConsumer(queue1); conn2.start(); TextMessage r1 = (TextMessage) cons.receive(5000); Assert.assertNotNull(r1); Assert.assertEquals("echidna1", r1.getText()); TextMessage r2 = (TextMessage) cons.receive(5000); Assert.assertNotNull(r2); Assert.assertEquals("echidna2", r2.getText()); } finally { if (conn != null) { conn.close(); } if (conn2 != null) { conn2.close(); } } }
Example 11
Source File: XATest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testMultipleSessionsOneTxRollbackSend1PCOptimization() throws Exception { // Since both resources have some RM, TM will probably use 1PC optimization XAConnection conn = null; Connection conn2 = null; try { conn = xacf.createXAConnection(); conn.start(); tm.begin(); // Create 2 sessions and enlist them XASession sess1 = conn.createXASession(); XAResource res1 = sess1.getXAResource(); XASession sess2 = conn.createXASession(); XAResource res2 = sess2.getXAResource(); Transaction tx = tm.getTransaction(); tx.enlistResource(res1); tx.enlistResource(res2); // Send 2 messages - one from each session MessageProducer prod1 = sess1.createProducer(queue1); MessageProducer prod2 = sess2.createProducer(queue1); prod1.send(sess1.createTextMessage("echidna1")); prod2.send(sess2.createTextMessage("echidna2")); tx.delistResource(res1, XAResource.TMSUCCESS); tx.delistResource(res2, XAResource.TMSUCCESS); // rollback tm.rollback(); // Messages should not be in queue conn2 = cf.createConnection(); Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = sess.createConsumer(queue1); conn2.start(); TextMessage r1 = (TextMessage) cons.receive(100); Assert.assertNull(r1); } finally { if (conn != null) { conn.close(); } if (conn2 != null) { conn2.close(); } } }
Example 12
Source File: XATest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testMultipleSessionsOneTxRollbackSend() throws Exception { XAConnection conn = null; Connection conn2 = null; try { conn = xacf.createXAConnection(); conn.start(); tm.begin(); // Create 2 sessions and enlist them XASession sess1 = conn.createXASession(); ClientSessionInternal res1 = (ClientSessionInternal) sess1.getXAResource(); XASession sess2 = conn.createXASession(); ClientSessionInternal res2 = (ClientSessionInternal) sess2.getXAResource(); res1.setForceNotSameRM(true); res2.setForceNotSameRM(true); Transaction tx = tm.getTransaction(); tx.enlistResource(res1); tx.enlistResource(res2); // Send 2 messages - one from each session MessageProducer prod1 = sess1.createProducer(queue1); MessageProducer prod2 = sess2.createProducer(queue1); prod1.send(sess1.createTextMessage("echidna1")); prod2.send(sess2.createTextMessage("echidna2")); tx.delistResource(res1, XAResource.TMSUCCESS); tx.delistResource(res2, XAResource.TMSUCCESS); // rollback tm.rollback(); // Messages should not be in queue conn2 = cf.createConnection(); Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = sess.createConsumer(queue1); conn2.start(); TextMessage r1 = (TextMessage) cons.receive(100); Assert.assertNull(r1); } finally { if (conn != null) { conn.close(); } if (conn2 != null) { conn2.close(); } } }
Example 13
Source File: XATest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testOneSessionTwoTransactionsCommitAcknowledge() throws Exception { XAConnection conn = null; Connection conn2 = null; try { // First send 2 messages conn2 = cf.createConnection(); Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer prod = sessProducer.createProducer(queue1); Message m = sessProducer.createTextMessage("jellyfish1"); prod.send(m); m = sessProducer.createTextMessage("jellyfish2"); prod.send(m); conn = xacf.createXAConnection(); // Create a session XASession sess1 = conn.createXASession(); XAResource res1 = sess1.getXAResource(); conn.start(); MessageConsumer cons1 = sess1.createConsumer(queue1); tm.begin(); Transaction tx1 = tm.getTransaction(); tx1.enlistResource(res1); // Receive one message in one tx TextMessage r1 = (TextMessage) cons1.receive(5000); Assert.assertNotNull(r1); Assert.assertEquals("jellyfish1", r1.getText()); tx1.delistResource(res1, XAResource.TMSUCCESS); // suspend the tx Transaction suspended = tm.suspend(); tm.begin(); Transaction tx2 = tm.getTransaction(); tx2.enlistResource(res1); // Receive 2nd message in a different tx TextMessage r2 = (TextMessage) cons1.receive(5000); Assert.assertNotNull(r2); Assert.assertEquals("jellyfish2", r2.getText()); tx2.delistResource(res1, XAResource.TMSUCCESS); // commit this transaction tm.commit(); // verify that no messages are available conn2.close(); conn2 = cf.createConnection(); Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); conn2.start(); MessageConsumer cons = sess.createConsumer(queue1); TextMessage r3 = (TextMessage) cons.receive(100); Assert.assertNull(r3); // now resume the first tx and then commit it tm.resume(suspended); tm.commit(); } finally { if (conn != null) { conn.close(); } if (conn2 != null) { conn2.close(); } } }
Example 14
Source File: XATest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testOneSessionTwoTransactionsCommitSend() throws Exception { XAConnection conn = null; Connection conn2 = null; try { conn = xacf.createXAConnection(); // Create a session XASession sess1 = conn.createXASession(); XAResource res1 = sess1.getXAResource(); MessageProducer prod1 = sess1.createProducer(queue1); tm.begin(); Transaction tx1 = tm.getTransaction(); tx1.enlistResource(res1); // Send a message prod1.send(sess1.createTextMessage("kangaroo1")); tx1.delistResource(res1, XAResource.TMSUCCESS); // suspend the tx Transaction suspended = tm.suspend(); tm.begin(); // Send another message in another tx using the same session Transaction tx2 = tm.getTransaction(); tx2.enlistResource(res1); // Send a message prod1.send(sess1.createTextMessage("kangaroo2")); tx2.delistResource(res1, XAResource.TMSUCCESS); // commit this transaction tm.commit(); // verify only kangaroo2 message is sent conn2 = cf.createConnection(); Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); conn2.start(); MessageConsumer cons = sess.createConsumer(queue1); TextMessage r1 = (TextMessage) cons.receive(5000); Assert.assertNotNull(r1); Assert.assertEquals("kangaroo2", r1.getText()); TextMessage r2 = (TextMessage) cons.receive(100); Assert.assertNull(r2); // now resume the first tx and then commit it tm.resume(suspended); tm.commit(); // verify that the first text message is received TextMessage r3 = (TextMessage) cons.receive(5000); Assert.assertNotNull(r3); Assert.assertEquals("kangaroo1", r3.getText()); } finally { if (conn != null) { conn.close(); } if (conn2 != null) { conn2.close(); } } }
Example 15
Source File: AbstractTransactionalConnectionListener.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * {@inheritDoc} */ public void delist() throws ResourceException { log.tracef("Delisting: %s", this); try { TransactionalConnectionManager txCM = (TransactionalConnectionManager)cm; TransactionManager tm = txCM.getTransactionIntegration().getTransactionManager(); int status = tm.getStatus(); if (status != Status.STATUS_NO_TRANSACTION && enlisted) { Transaction tx = tm.getTransaction(); boolean delistResult = tx.delistResource(xaResource, XAResource.TMSUCCESS); if (Tracer.isEnabled()) Tracer.delistConnectionListener(cm.getPool().getConfiguration().getId(), getManagedConnectionPool(), this, tx.toString(), true, false, false); if (delistResult) { log.tracef("delist-success: %s", this); } else { log.debugf("delist-success failed: %s", this); } } localTransaction = false; if (transactionSynchronization != null) { transactionSynchronization.cancel(); transactionSynchronization = null; } enlisted = false; log.tracef("Delisted: %s", this); } catch (Exception e) { throw new ResourceException(e); } }