Search in sources :

Example 11 with IllegalStateException

use of javax.jms.IllegalStateException in project activemq-artemis by apache.

the class ActiveMQRASession method createTemporaryQueue.

/**
 * Create a temporary queue
 *
 * @return The temporary queue
 * @throws JMSException Thrown if an error occurs
 */
@Override
public TemporaryQueue createTemporaryQueue() throws JMSException {
    if (cri.getType() == ActiveMQRAConnectionFactory.TOPIC_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) {
        throw new IllegalStateException("Cannot create temporary queue for javax.jms.TopicSession");
    }
    lock();
    try {
        Session session = getSessionInternal();
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("createTemporaryQueue " + session);
        }
        TemporaryQueue temp = session.createTemporaryQueue();
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("createdTemporaryQueue " + session + " temp=" + temp);
        }
        sf.addTemporaryQueue(temp);
        return temp;
    } finally {
        unlock();
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) TemporaryQueue(javax.jms.TemporaryQueue) XAQueueSession(javax.jms.XAQueueSession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) TopicSession(javax.jms.TopicSession) XATopicSession(javax.jms.XATopicSession) QueueSession(javax.jms.QueueSession)

Example 12 with IllegalStateException

use of javax.jms.IllegalStateException in project activemq-artemis by apache.

the class ActiveMQRASession method recover.

/**
 * Recover
 *
 * @throws JMSException Failed to close session.
 */
@Override
public void recover() throws JMSException {
    lock();
    try {
        Session session = getSessionInternal();
        if (cri.isTransacted()) {
            throw new IllegalStateException("Session is transacted");
        }
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("Recover session " + this);
        }
        session.recover();
    } finally {
        unlock();
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) XAQueueSession(javax.jms.XAQueueSession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) TopicSession(javax.jms.TopicSession) XATopicSession(javax.jms.XATopicSession) QueueSession(javax.jms.QueueSession)

Example 13 with IllegalStateException

use of javax.jms.IllegalStateException in project activemq-artemis by apache.

the class ActiveMQRASession method unsubscribe.

/**
 * Unsubscribe
 *
 * @param name The name
 * @throws JMSException Thrown if an error occurs
 */
@Override
public void unsubscribe(final String name) throws JMSException {
    if (cri.getType() == ActiveMQRAConnectionFactory.QUEUE_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION) {
        throw new IllegalStateException("Cannot unsubscribe for javax.jms.QueueSession");
    }
    lock();
    try {
        Session session = getSessionInternal();
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("unsubscribe " + session + " name=" + name);
        }
        session.unsubscribe(name);
    } finally {
        unlock();
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) XAQueueSession(javax.jms.XAQueueSession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) TopicSession(javax.jms.TopicSession) XATopicSession(javax.jms.XATopicSession) QueueSession(javax.jms.QueueSession)

Example 14 with IllegalStateException

use of javax.jms.IllegalStateException in project activemq-artemis by apache.

the class ActiveMQRASessionFactoryImpl method allocateConnection.

/**
 * Allocate a connection
 *
 * @param transacted      Use transactions
 * @param acknowledgeMode The acknowledge mode
 * @param sessionType     The session type
 * @return The session
 * @throws JMSException Thrown if an error occurs
 */
protected ActiveMQRASession allocateConnection(boolean transacted, int acknowledgeMode, final int sessionType) throws JMSException {
    if (ActiveMQRASessionFactoryImpl.trace) {
        ActiveMQRALogger.LOGGER.trace("allocateConnection(" + transacted + ", " + acknowledgeMode + ", " + sessionType + ")");
    }
    try {
        synchronized (sessions) {
            if (sessions.isEmpty() == false) {
                throw new IllegalStateException("Only allowed one session per connection. See the J2EE spec, e.g. J2EE1.4 Section 6.6");
            }
            // then it should not be included in any JTA transaction and behave like that there is no JTA transaction.
            if (!mcf.isIgnoreJTA() && inJtaTransaction()) {
                transacted = true;
                // from getAcknowledgeMode
                // If the session is transacted, returns SESSION_TRANSACTED.
                acknowledgeMode = Session.SESSION_TRANSACTED;
            } else {
                // The session will always be non-transacted, unless allow-local-transactions is true
                if (transacted && mcf.isAllowLocalTransactions()) {
                    acknowledgeMode = Session.SESSION_TRANSACTED;
                } else {
                    transacted = false;
                    switch(acknowledgeMode) {
                        // using one of the two acknowledgement modes AUTO_ACKNOWLEDGE and DUPS_OK_ACKNOWLEDGE.
                        case Session.AUTO_ACKNOWLEDGE:
                        case Session.DUPS_OK_ACKNOWLEDGE:
                        // plus our own
                        case ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE:
                        case ActiveMQJMSConstants.PRE_ACKNOWLEDGE:
                            break;
                        // The value {@code Session.CLIENT_ACKNOWLEDGE} may not be used.
                        case Session.CLIENT_ACKNOWLEDGE:
                            throw ActiveMQRABundle.BUNDLE.invalidClientAcknowledgeModeRuntime();
                        // same with this although the spec doesn't explicitly say
                        case Session.SESSION_TRANSACTED:
                            if (!mcf.isAllowLocalTransactions()) {
                                throw ActiveMQRABundle.BUNDLE.invalidSessionTransactedModeRuntimeAllowLocal();
                            }
                            transacted = true;
                            break;
                        default:
                            throw ActiveMQRABundle.BUNDLE.invalidAcknowledgeMode(acknowledgeMode);
                    }
                }
            }
            ActiveMQRAConnectionRequestInfo info = new ActiveMQRAConnectionRequestInfo(transacted, acknowledgeMode, sessionType);
            info.setUserName(userName);
            info.setPassword(password);
            info.setClientID(clientID);
            info.setDefaults(((ActiveMQResourceAdapter) mcf.getResourceAdapter()).getProperties());
            if (ActiveMQRASessionFactoryImpl.trace) {
                ActiveMQRALogger.LOGGER.trace("Allocating session for " + this + " with request info=" + info);
            }
            ActiveMQRASession session = (ActiveMQRASession) cm.allocateConnection(mcf, info);
            try {
                if (ActiveMQRASessionFactoryImpl.trace) {
                    ActiveMQRALogger.LOGGER.trace("Allocated  " + this + " session=" + session);
                }
                session.setActiveMQSessionFactory(this);
                if (started) {
                    session.start();
                }
                sessions.add(session);
                return session;
            } catch (Throwable t) {
                try {
                    session.close();
                } catch (Throwable ignored) {
                }
                if (t instanceof Exception) {
                    throw (Exception) t;
                } else {
                    throw new RuntimeException("Unexpected error: ", t);
                }
            }
        }
    } catch (Exception e) {
        Throwable current = e;
        while (current != null && !(current instanceof JMSException)) {
            current = current.getCause();
        }
        if (current != null && current instanceof JMSException) {
            throw (JMSException) current;
        } else {
            JMSException je = new JMSException("Could not create a session: " + e.getMessage());
            je.setLinkedException(e);
            je.initCause(e);
            throw je;
        }
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) JMSException(javax.jms.JMSException) IllegalStateException(javax.jms.IllegalStateException) JMSException(javax.jms.JMSException) SystemException(javax.transaction.SystemException)

Example 15 with IllegalStateException

use of javax.jms.IllegalStateException in project activemq-artemis by apache.

the class ActiveMQSession method deleteTemporaryTopic.

public void deleteTemporaryTopic(final ActiveMQDestination tempTopic) throws JMSException {
    if (!tempTopic.isTemporary()) {
        throw new InvalidDestinationException("Not a temporary topic " + tempTopic);
    }
    try {
        AddressQuery response = session.addressQuery(tempTopic.getSimpleAddress());
        if (!response.isExists()) {
            throw new InvalidDestinationException("Cannot delete temporary topic " + tempTopic.getName() + " does not exist");
        }
        if (response.getQueueNames().size() > 1) {
            throw new IllegalStateException("Cannot delete temporary topic " + tempTopic.getName() + " since it has subscribers");
        }
        SimpleString address = tempTopic.getSimpleAddress();
        session.deleteQueue(address);
        connection.removeTemporaryQueue(address);
    } catch (ActiveMQException e) {
        throw JMSExceptionHelper.convertFromActiveMQException(e);
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) AddressQuery(org.apache.activemq.artemis.api.core.client.ClientSession.AddressQuery) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) InvalidDestinationException(javax.jms.InvalidDestinationException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Aggregations

IllegalStateException (javax.jms.IllegalStateException)44 Session (javax.jms.Session)19 Connection (javax.jms.Connection)12 QueueSession (javax.jms.QueueSession)12 Test (org.junit.Test)12 TopicSession (javax.jms.TopicSession)11 XAQueueSession (javax.jms.XAQueueSession)11 XATopicSession (javax.jms.XATopicSession)11 ActiveMQSession (org.apache.activemq.artemis.jms.client.ActiveMQSession)11 JMSException (javax.jms.JMSException)10 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 InvalidDestinationException (javax.jms.InvalidDestinationException)5 IOException (java.io.IOException)4 Queue (javax.jms.Queue)3 QueueBrowser (javax.jms.QueueBrowser)3 TopicSubscriber (javax.jms.TopicSubscriber)3 QueueQuery (org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery)3 RMQJMSException (com.rabbitmq.jms.util.RMQJMSException)2 TemporaryQueue (javax.jms.TemporaryQueue)2