本文整理汇总了Java中javax.transaction.Transaction.delistResource方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.delistResource方法的具体用法?Java Transaction.delistResource怎么用?Java Transaction.delistResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.transaction.Transaction
的用法示例。
在下文中一共展示了Transaction.delistResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectionClosed
import javax.transaction.Transaction; //导入方法依赖的package包/类
/**
* Implementation of call back function from ConnectionEventListener interface. This callback will
* be invoked on connection close event.
*
* @param event Connection event object
*/
public void connectionClosed(ConnectionEvent event) {
if (isActive) {
try {
XAConnection conn = (XAConnection) event.getSource();
XAResource xar = (XAResource) xaResourcesMap.get(conn);
xaResourcesMap.remove(conn);
Transaction txn = transManager.getTransaction();
if (txn != null && xar != null)
txn.delistResource(xar, XAResource.TMSUCCESS);
provider.returnConnection(conn);
} catch (Exception e) {
String exception =
"GemFireTransactionDataSource::connectionClosed: Exception occured due to " + e;
if (logger.isDebugEnabled()) {
logger.debug(exception, e);
}
}
}
}
示例2: connectionClosed
import javax.transaction.Transaction; //导入方法依赖的package包/类
/**
* Callback for Connection Closed.
*
* @param event ConnectionEvent Object.
*/
public void connectionClosed(ConnectionEvent event) {
if (isActive) {
ManagedConnection conn = (ManagedConnection) event.getSource();
XAResource xar = null;
if (xaResourcesMap.get(conn) != null)
xar = (XAResource) xaResourcesMap.get(conn);
xaResourcesMap.remove(conn);
try {
Transaction txn = transManager.getTransaction();
if (txn != null && xar != null) {
txn.delistResource(xar, XAResource.TMSUCCESS);
}
}
catch (Exception se) {
String exception = "JCAConnectionManagerImpl::connectionClosed: Exception occured due to "
+ se;
LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
if (writer.fineEnabled()) writer.fine(exception, se);
}
mannPoolCache.returnPooledConnectionToPool(conn);
}
}
示例3: close
import javax.transaction.Transaction; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void close() {
super.close();
try {
if (_session != null) {
Transaction tx = _transactionManager.getTransaction();
if (tx != null) {
tx.delistResource(_session.getXAResource(), XAResource.TMFAIL);
tx.rollback();
}
}
}
catch (SystemException e) {
// Ignore
}
closeSafely(_session);
closeSafely(_conn);
}
示例4: connectionErrorOccurred
import javax.transaction.Transaction; //导入方法依赖的package包/类
/**
* 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;
if (logger.isDebugEnabled()) {
logger.debug(exception, ex);
}
}
}
}
示例5: connectionErrorOccurred
import javax.transaction.Transaction; //导入方法依赖的package包/类
/**
* 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);
}
}
}
示例6: commit
import javax.transaction.Transaction; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void commit() throws JMSException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
try {
Transaction tx = _transactionManager.getTransaction();
if (tx != null) {
tx.delistResource(getSession().getXAResource(), XAResource.TMSUCCESS);
tx.commit();
}
}
catch (SystemException e) {
_logger.error("Failed to rollback", e);
throw new RuntimeException("Failed to rollback", e);
}
}
示例7: rollback
import javax.transaction.Transaction; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void rollback() throws JMSException {
try {
Transaction tx = _transactionManager.getTransaction();
if (tx != null) {
tx.delistResource(getSession().getXAResource(), XAResource.TMFAIL);
tx.rollback();
}
}
catch (SystemException e) {
_logger.error("Failed to rollback", e);
throw new RuntimeException("Failed to rollback", e);
}
}
示例8: close
import javax.transaction.Transaction; //导入方法依赖的package包/类
@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);
}
}
示例9: test2PCSendCommit1PCOptimization
import javax.transaction.Transaction; //导入方法依赖的package包/类
@Test
public void test2PCSendCommit1PCOptimization() throws Exception {
// Since both resources have same RM, TM will probably use 1PC optimization
XAConnection conn = null;
Connection conn2 = null;
try {
conn = xacf.createXAConnection();
tm.begin();
XASession sess = conn.createXASession();
XAResource res = sess.getXAResource();
XAResource res2 = new DummyXAResource();
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
prod.send(m);
m = sess.createTextMessage("XATest2");
prod.send(m);
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.commit();
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sessReceiver.createConsumer(queue1);
TextMessage m2 = (TextMessage) cons.receive(1000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest1", m2.getText());
m2 = (TextMessage) cons.receive(1000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest2", m2.getText());
} finally {
if (conn != null) {
conn.close();
}
if (conn2 != null) {
conn2.close();
}
}
}
示例10: test2PCSendCommit
import javax.transaction.Transaction; //导入方法依赖的package包/类
@Test
public void test2PCSendCommit() throws Exception {
XAConnection conn = null;
Connection conn2 = null;
try {
conn = xacf.createXAConnection();
tm.begin();
XASession sess = conn.createXASession();
XAResource res = sess.getXAResource();
XAResource res2 = new DummyXAResource();
// To prevent 1PC optimization being used
// res.setForceNotSameRM(true);
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
prod.send(m);
m = sess.createTextMessage("XATest2");
prod.send(m);
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.commit();
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sessReceiver.createConsumer(queue1);
TextMessage m2 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest1", m2.getText());
m2 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest2", m2.getText());
} finally {
if (conn != null) {
conn.close();
}
if (conn2 != null) {
conn2.close();
}
}
}
示例11: test2PCSendFailOnPrepare
import javax.transaction.Transaction; //导入方法依赖的package包/类
@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();
}
}
}
示例12: testOneSessionTwoTransactionsCommitSend
import javax.transaction.Transaction; //导入方法依赖的package包/类
@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();
}
}
}
示例13: test2PCReceiveCommit1PCOptimization
import javax.transaction.Transaction; //导入方法依赖的package包/类
@Test
public void test2PCReceiveCommit1PCOptimization() throws Exception {
// Since both resources have some RM, TM will probably use 1PC optimization
XAConnection conn = null;
Connection conn2 = null;
try {
conn2 = cf.createConnection();
conn2.start();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
conn = xacf.createXAConnection();
conn.start();
tm.begin();
XASession sess = conn.createXASession();
XAResource res = sess.getXAResource();
XAResource res2 = new DummyXAResource();
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest1", m2.getText());
m2 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest2", m2.getText());
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.commit();
// New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
Message m3 = cons.receive(100);
Assert.assertNull(m3);
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.commit();
} finally {
if (conn != null) {
conn.close();
}
if (conn2 != null) {
conn2.close();
}
}
}
示例14: test2PCReceiveCommit
import javax.transaction.Transaction; //导入方法依赖的package包/类
@Test
public void test2PCReceiveCommit() throws Exception {
XAConnection conn = null;
Connection conn2 = null;
try {
conn2 = cf.createConnection();
conn2.start();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
conn = xacf.createXAConnection();
conn.start();
tm.begin();
XASession sess = conn.createXASession();
XAResource res = sess.getXAResource();
// res.setForceNotSameRM(true);
XAResource res2 = new DummyXAResource();
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest1", m2.getText());
m2 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest2", m2.getText());
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.commit();
// New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
Message m3 = cons.receive(100);
Assert.assertNull(m3);
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.commit();
} finally {
if (conn != null) {
conn.close();
}
if (conn2 != null) {
conn2.close();
}
}
}
示例15: test2PCReceiveRollback1PCOptimization
import javax.transaction.Transaction; //导入方法依赖的package包/类
@Test
public void test2PCReceiveRollback1PCOptimization() throws Exception {
// Since both resources have some RM, TM will probably use 1PC optimization
XAConnection conn = null;
Connection conn2 = null;
try {
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
conn = xacf.createXAConnection();
conn.start();
tm.begin();
XASession sess = conn.createXASession();
XAResource res = sess.getXAResource();
XAResource res2 = new DummyXAResource();
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest1", m2.getText());
m2 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m2);
Assert.assertEquals("XATest2", m2.getText());
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.rollback();
// Message should be redelivered
// New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
tx.enlistResource(res2);
TextMessage m3 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m3);
Assert.assertEquals("XATest1", m3.getText());
m3 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(m3);
Assert.assertEquals("XATest2", m3.getText());
Assert.assertTrue(m3.getJMSRedelivered());
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.commit();
} finally {
if (conn != null) {
conn.close();
}
if (conn2 != null) {
conn2.close();
}
}
}