本文整理汇总了Java中javax.jms.XASession类的典型用法代码示例。如果您正苦于以下问题:Java XASession类的具体用法?Java XASession怎么用?Java XASession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XASession类属于javax.jms包,在下文中一共展示了XASession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createXASession
import javax.jms.XASession; //导入依赖的package包/类
/**
* Create JMS {@link XASession} instance on top of the provided {@link Connection} instance.
*
* @param xAConnection JMS Connection.
* @return Session instance.
* @throws JMSConnectorException Error when creating the XASession.
*/
public XASession createXASession(XAConnection xAConnection) throws JMSConnectorException {
try {
if (logger.isDebugEnabled()) {
logger.debug("Creating a new JMS XASession on: " + this.connectionFactoryString);
}
if (JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec) || JMSConstants.JMS_SPEC_VERSION_2_0
.equals(jmsSpec)) {
return xAConnection.createXASession();
} else if (JMSConstants.JMSDestinationType.QUEUE.equals(this.destinationType)) {
return ((XAQueueConnection) (xAConnection)).createXAQueueSession();
} else {
return ((XATopicConnection) (xAConnection)).createXATopicSession();
}
} catch (JMSException e) {
throw new JMSConnectorException(
"JMS Exception while obtaining session for factory " + connectionFactoryString, e);
}
}
示例2: enlistResources
import javax.jms.XASession; //导入依赖的package包/类
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");
}
}
示例3: testXAPrepare
import javax.jms.XASession; //导入依赖的package包/类
@Test
public void testXAPrepare() throws Exception {
try {
XAConnection connection = xaFactory.createXAConnection();
XASession xasession = connection.createXASession();
Xid xid = newXID();
xasession.getXAResource().start(xid, XAResource.TMNOFLAGS);
Queue queue = xasession.createQueue(queueName);
MessageProducer producer = xasession.createProducer(queue);
producer.send(xasession.createTextMessage("hello"));
producer.send(xasession.createTextMessage("hello"));
xasession.getXAResource().end(xid, XAResource.TMSUCCESS);
xasession.getXAResource().prepare(xid);
connection.close();
System.err.println("Done!!!");
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: testXAResourceCommittedRemoved
import javax.jms.XASession; //导入依赖的package包/类
@Test
public void testXAResourceCommittedRemoved() throws Exception {
Queue queue = null;
Xid xid = newXID();
try (XAConnection xaconnection = xaFactory.createXAConnection()) {
XASession session = xaconnection.createXASession();
queue = session.createQueue(queueName);
session.getXAResource().start(xid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("xa message"));
session.getXAResource().end(xid, XAResource.TMSUCCESS);
session.getXAResource().commit(xid, true);
}
XidImpl xid1 = new XidImpl(xid);
Transaction transaction = server.getResourceManager().getTransaction(xid1);
assertNull(transaction);
}
示例5: testXAResourceRolledBackRemoved
import javax.jms.XASession; //导入依赖的package包/类
@Test
public void testXAResourceRolledBackRemoved() throws Exception {
Queue queue = null;
Xid xid = newXID();
try (XAConnection xaconnection = xaFactory.createXAConnection()) {
XASession session = xaconnection.createXASession();
queue = session.createQueue(queueName);
session.getXAResource().start(xid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("xa message"));
session.getXAResource().end(xid, XAResource.TMSUCCESS);
session.getXAResource().rollback(xid);
}
XidImpl xid1 = new XidImpl(xid);
Transaction transaction = server.getResourceManager().getTransaction(xid1);
assertNull(transaction);
}
示例6: testIsSamRM
import javax.jms.XASession; //导入依赖的package包/类
@Test
public void testIsSamRM() throws Exception {
XAConnection conn = null;
conn = xacf.createXAConnection();
// Create a session
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
// Create a session
XASession sess2 = conn.createXASession();
XAResource res2 = sess2.getXAResource();
Assert.assertTrue(res1.isSameRM(res2));
}
示例7: testRollbackXaErrorCode
import javax.jms.XASession; //导入依赖的package包/类
public void testRollbackXaErrorCode() throws Exception {
String brokerName = "rollbackErrorCode";
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();
Xid tid = createXid();
try {
resource.rollback(tid);
fail("Expected xa exception on no tx");
} catch (XAException expected) {
LOG.info("got expected xa", expected);
assertEquals("no tx", XAException.XAER_NOTA, expected.errorCode);
}
connection.close();
broker.stop();
}
示例8: run
import javax.jms.XASession; //导入依赖的package包/类
@Override
protected void run(XAConnection connection, XASession xaSession, XAResource xaResource) throws Exception {
verbose("Starting XA transaction");
Xid xid = createXid();
xaResource.start(xid, 0);
verbose("Sending message");
MessageProducer producer = xaSession.createProducer(xaSession.createQueue(queue));
producer.send(xaSession.createTextMessage("TEST"));
verbose("Ending XA transaction");
xaResource.end(xid, XAResource.TMSUCCESS);
verbose("Preparing XA transaction");
xaResource.prepare(xid);
println("Created: "+toString(xid));
}
示例9: createXASession
import javax.jms.XASession; //导入依赖的package包/类
/**
* Creates an XASession.
*
* @return A newly created XASession.
* @throws JMSException If the XAConnection fails to create an XASession due to
* some internal error.
*/
public synchronized XASession createXASession() throws JMSException {
checkNotClosed();
if (connectionCloseSignaled) {
throw new IllegalStateException("Object " + toString() + " has been closed");
}
XASession xaSession = _delegate.createXASession();
// Need to alter the class hierarchy to avoid casting
if (xaSession instanceof XASession_9_1) {
xaSessions.add((XASession_9_1) xaSession);
}
return xaSession;
}
示例10: notifyUpdate
import javax.jms.XASession; //导入依赖的package包/类
private void notifyUpdate(Queue queue, String msg) throws Exception {
XAConnection connection = null;
try {
connection = xaConnectionFactory.createXAConnection();
XASession session = connection.createXASession();
MessageProducer messageProducer = session.createProducer(queue);
connection.start();
TextMessage message = session.createTextMessage();
message.setText(msg);
messageProducer.send(message);
messageProducer.close();
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
LOGGER.info("Error closing JMS connection: " + e.getMessage());
}
}
}
}
示例11: getXAResource
import javax.jms.XASession; //导入依赖的package包/类
@Override
public XAResource getXAResource() {
final PooledSessionHolder session;
try {
session = safeGetSessionHolder();
} catch (JMSException e) {
throw JMSExceptionSupport.createRuntimeException(e);
}
if (session.getSession() instanceof XASession) {
return ((XASession) session.getSession()).getXAResource();
}
return null;
}
示例12: createMessageConsumer
import javax.jms.XASession; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected MessageConsumer createMessageConsumer() throws JMSException {
XASession session = getSession();
_conn.start();
MessageConsumer consumer = session
.createConsumer(getDestination(session, _destinationName, _destinationTypeQueue));
return consumer;
}
示例13: getSession
import javax.jms.XASession; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public XASession getSession() throws JMSException {
if (_session == null) {
if (_conn == null) {
_conn = _connFactory.createXAConnection();
}
_session = _conn.createXASession();
}
return _session;
}
示例14: pooledConnectionFactory
import javax.jms.XASession; //导入依赖的package包/类
@Bean
public ConnectionFactory pooledConnectionFactory(
XAConnectionFactoryWrapper wrapper) throws Exception {
XAConnectionFactory connectionFactory = mock(XAConnectionFactory.class);
XAConnection connection = mock(XAConnection.class);
XASession session = mock(XASession.class);
TemporaryQueue queue = mock(TemporaryQueue.class);
XAResource resource = mock(XAResource.class);
given(connectionFactory.createXAConnection()).willReturn(connection);
given(connection.createXASession()).willReturn(session);
given(session.createTemporaryQueue()).willReturn(queue);
given(session.getXAResource()).willReturn(resource);
return wrapper.wrapConnectionFactory(connectionFactory);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:JtaAutoConfigurationTests.java
示例15: create
import javax.jms.XASession; //导入依赖的package包/类
@Override
public synchronized SessionWrapper create() throws Exception {
List<ConnectionWrapper> connectionWrappers;
ConnectionWrapper connectionWrapper = null;
SessionWrapper sessionWrapper = null;
if (jmsConnectionFactory instanceof JMSClientConnectionFactory) {
connectionWrappers = ((JMSClientConnectionFactory) jmsConnectionFactory).getConnections();
// see if we can create more sessions on the final Connection created
if (!connectionWrappers.isEmpty()
&& connectionWrappers.get(connectionWrappers.size() - 1).getSessionCount().get()
< ((JMSClientConnectionFactory) jmsConnectionFactory).getMaxSessionsPerConnection()) {
connectionWrapper = connectionWrappers.get(connectionWrappers.size() - 1);
}
// if it needs to create a new connectionWrapper
if (connectionWrapper == null) {
if (jmsConnectionFactory.isxATransacted()) {
connectionWrapper = new ConnectionWrapper((jmsConnectionFactory.createXAConnection()));
} else {
connectionWrapper = new ConnectionWrapper(jmsConnectionFactory.createConnection());
}
connectionWrappers.add(connectionWrapper);
}
// Create new SessionWrapper (or XASessionWrapper) accordingly
if (jmsConnectionFactory.isxATransacted()) {
XASession xASession = jmsConnectionFactory
.createXASession((XAConnection) connectionWrapper.getConnection());
sessionWrapper = new XASessionWrapper(xASession, xASession.getSession(),
jmsConnectionFactory.createMessageProducer(xASession.getSession()));
} else {
Session session = jmsConnectionFactory.createSession(connectionWrapper.getConnection());
sessionWrapper = new SessionWrapper(session, jmsConnectionFactory.createMessageProducer(session));
}
connectionWrapper.incrementSessionCount();
}
return sessionWrapper;
}