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();
}
}
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();
}
}
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();
}
}
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;
}
}
}
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);
}
}
Aggregations