Search in sources :

Example 91 with TemporaryQueue

use of javax.jms.TemporaryQueue in project aries by apache.

the class XaConnectionPool method createSession.

@Override
public Session createSession(boolean transacted, int ackMode) throws JMSException {
    try {
        boolean isXa = (transactionManager != null && transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION);
        if (isXa) {
            // if the xa tx aborts inflight we don't want to auto create a
            // local transaction or auto ack
            transacted = false;
            ackMode = Session.CLIENT_ACKNOWLEDGE;
        } else if (transactionManager != null) {
            // cmt or transactionManager managed
            transacted = false;
            if (ackMode == Session.SESSION_TRANSACTED) {
                ackMode = Session.AUTO_ACKNOWLEDGE;
            }
        }
        PooledSession session = (PooledSession) super.createSession(transacted, ackMode);
        if (isXa) {
            session.addSessionEventListener(new PooledSessionEventListener() {

                @Override
                public void onTemporaryQueueCreate(TemporaryQueue tempQueue) {
                }

                @Override
                public void onTemporaryTopicCreate(TemporaryTopic tempTopic) {
                }

                @Override
                public void onSessionClosed(PooledSession session) {
                    session.setIgnoreClose(true);
                    session.setIsXa(false);
                }
            });
            session.setIgnoreClose(true);
            session.setIsXa(true);
            transactionManager.getTransaction().registerSynchronization(new Synchronization(session));
            incrementReferenceCount();
            transactionManager.getTransaction().enlistResource(createXaResource(session));
        } else {
            session.setIgnoreClose(false);
        }
        return session;
    } catch (RollbackException e) {
        final JMSException jmsException = new JMSException("Rollback Exception");
        jmsException.initCause(e);
        throw jmsException;
    } catch (SystemException e) {
        final JMSException jmsException = new JMSException("System Exception");
        jmsException.initCause(e);
        throw jmsException;
    }
}
Also used : SystemException(javax.transaction.SystemException) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) RollbackException(javax.transaction.RollbackException) TemporaryTopic(javax.jms.TemporaryTopic)

Aggregations

TemporaryQueue (javax.jms.TemporaryQueue)91 Session (javax.jms.Session)56 Test (org.junit.Test)47 Connection (javax.jms.Connection)45 MessageProducer (javax.jms.MessageProducer)38 MessageConsumer (javax.jms.MessageConsumer)35 Message (javax.jms.Message)27 JMSException (javax.jms.JMSException)25 TextMessage (javax.jms.TextMessage)24 JMSContext (javax.jms.JMSContext)13 BytesMessage (javax.jms.BytesMessage)10 Destination (javax.jms.Destination)8 Queue (javax.jms.Queue)8 ConnectionFactory (javax.jms.ConnectionFactory)7 ObjectMessage (javax.jms.ObjectMessage)7 JMSConsumer (javax.jms.JMSConsumer)6 TemporaryTopic (javax.jms.TemporaryTopic)6 HashMap (java.util.HashMap)5 MapMessage (javax.jms.MapMessage)5 StreamMessage (javax.jms.StreamMessage)5