use of javax.jms.XASession in project activemq-artemis by apache.
the class JMSBridgeImpl method delistResources.
private void delistResources(final Transaction tx) {
if (JMSBridgeImpl.trace) {
ActiveMQJMSBridgeLogger.LOGGER.trace("Delisting resources from tx");
}
XAResource resSource = ((XASession) sourceSession).getXAResource();
try {
tx.delistResource(resSource, XAResource.TMSUCCESS);
} catch (Exception e) {
if (JMSBridgeImpl.trace) {
ActiveMQJMSBridgeLogger.LOGGER.trace("Failed to delist source resource", e);
}
}
XAResource resDest = ((XASession) targetSession).getXAResource();
try {
tx.delistResource(resDest, XAResource.TMSUCCESS);
} catch (Exception e) {
if (JMSBridgeImpl.trace) {
ActiveMQJMSBridgeLogger.LOGGER.trace("Failed to delist target resource", e);
}
}
if (JMSBridgeImpl.trace) {
ActiveMQJMSBridgeLogger.LOGGER.trace("Delisted resources from tx");
}
}
use of javax.jms.XASession in project activemq-artemis by apache.
the class JMSBridgeImpl method enlistResources.
private void enlistResources(final Transaction tx) throws Exception {
if (JMSBridgeImpl.trace) {
ActiveMQJMSBridgeLogger.LOGGER.trace("Enlisting resources in tx");
}
XAResource resSource = ((XASession) sourceSession).getXAResource();
tx.enlistResource(resSource);
XAResource resDest = ((XASession) targetSession).getXAResource();
tx.enlistResource(resDest);
if (JMSBridgeImpl.trace) {
ActiveMQJMSBridgeLogger.LOGGER.trace("Enlisted resources in tx");
}
}
use of javax.jms.XASession in project activemq-artemis by apache.
the class ActiveMQXAConnectionFactoryTest method testExceptionAfterClose.
public void testExceptionAfterClose() throws Exception {
ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
XAConnection connection1 = (XAConnection) cf1.createConnection();
connection1.start();
XASession session = connection1.createXASession();
session.close();
try {
session.commit();
fail("expect exception after close");
} catch (javax.jms.IllegalStateException expected) {
}
try {
session.rollback();
fail("expect exception after close");
} catch (javax.jms.IllegalStateException expected) {
}
try {
session.getTransacted();
fail("expect exception after close");
} catch (javax.jms.IllegalStateException expected) {
}
}
use of javax.jms.XASession in project activemq-artemis by apache.
the class ActiveMQXAConnectionFactoryTest method testIsSameRMOverride.
public void testIsSameRMOverride() throws URISyntaxException, JMSException, XAException {
XAConnection connection1 = null;
XAConnection connection2 = null;
try {
ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false&jms.rmIdFromConnectionId=true");
connection1 = (XAConnection) cf1.createConnection();
XASession session1 = connection1.createXASession();
XAResource resource1 = session1.getXAResource();
ActiveMQXAConnectionFactory cf2 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
connection2 = (XAConnection) cf2.createConnection();
XASession session2 = connection2.createXASession();
XAResource resource2 = session2.getXAResource();
assertFalse(resource1.isSameRM(resource2));
// ensure identity is preserved
XASession session1a = connection1.createXASession();
assertTrue(resource1.isSameRM(session1a.getXAResource()));
session1.close();
session2.close();
} finally {
if (connection1 != null) {
try {
connection1.close();
} catch (Exception e) {
// ignore
}
}
if (connection2 != null) {
try {
connection2.close();
} catch (Exception e) {
// ignore
}
}
}
}
use of javax.jms.XASession in project activemq-artemis by apache.
the class ActiveMQXAConnectionFactoryTest method testCloseSendConnection.
public void testCloseSendConnection() throws Exception {
String brokerName = "closeSend";
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
broker.start();
broker.waitUntilStarted();
ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
XAConnection connection = (XAConnection) cf.createConnection();
connection.start();
XASession session = connection.createXASession();
XAResource resource = session.getXAResource();
Destination dest = new ActiveMQQueue(getName());
// publish a message
Xid tid = createXid();
resource.start(tid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(dest);
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setText(getName());
producer.send(message);
connection.close();
// comment out this check as it doesn't apply to artemis
// assertTransactionGoneFromBroker(tid);
broker.stop();
}
Aggregations