use of javax.jms.IllegalStateException in project rabbitmq-jms-client by rabbitmq.
the class RMQConnection method setClientID.
/**
* {@inheritDoc}
*/
@Override
public void setClientID(String clientID) throws JMSException {
logger.trace("set ClientID to '{}'", clientID);
illegalStateExceptionIfClosed();
if (!canSetClientID)
throw new IllegalStateException("Client ID can only be set right after connection creation");
if (this.clientID == null) {
if (CLIENT_IDS.putIfAbsent(clientID, clientID) == null) {
this.clientID = clientID;
} else {
throw new InvalidClientIDException(String.format("A connection with client ID [%s] already exists.", clientID));
}
} else {
throw new IllegalStateException("Client ID already set.");
}
}
use of javax.jms.IllegalStateException in project activemq-artemis by apache.
the class DurableSubscriptionTest method testUnsubscribeWithActiveConsumer.
// See JMS 1.1. spec sec 6.11
@Test
public void testUnsubscribeWithActiveConsumer() throws Exception {
Connection conn = createConnection();
conn.setClientID("zeke");
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber dursub = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "dursub0");
try {
s.unsubscribe("dursub0");
ProxyAssertSupport.fail();
} catch (IllegalStateException e) {
// Ok - it is illegal to ubscribe a subscription if it has active consumers
}
dursub.close();
s.unsubscribe("dursub0");
}
use of javax.jms.IllegalStateException in project activemq-artemis by apache.
the class OpenWireConnection method addConsumer.
public void addConsumer(ConsumerInfo info) throws Exception {
// Todo: add a destination interceptors holder here (amq supports this)
SessionId sessionId = info.getConsumerId().getParentId();
ConnectionId connectionId = sessionId.getParentId();
ConnectionState cs = getState();
if (cs == null) {
throw new IllegalStateException("Cannot add a consumer to a connection that had not been registered: " + connectionId);
}
SessionState ss = cs.getSessionState(sessionId);
if (ss == null) {
throw new IllegalStateException(server + " Cannot add a consumer to a session that had not been registered: " + sessionId);
}
// Avoid replaying dup commands
if (!ss.getConsumerIds().contains(info.getConsumerId())) {
AMQSession amqSession = sessions.get(sessionId);
if (amqSession == null) {
throw new IllegalStateException("Session not exist! : " + sessionId);
}
List<AMQConsumer> consumersList = amqSession.createConsumer(info, new SlowConsumerDetection());
if (consumersList.size() == 0) {
return;
}
this.addConsumerBrokerExchange(info.getConsumerId(), amqSession, consumersList);
ss.addConsumer(info);
amqSession.start();
if (AdvisorySupport.isAdvisoryTopic(info.getDestination())) {
// advisory for temp destinations
if (AdvisorySupport.isTempDestinationAdvisoryTopic(info.getDestination())) {
// Replay the temporary destinations.
List<DestinationInfo> tmpDests = this.protocolManager.getTemporaryDestinations();
for (DestinationInfo di : tmpDests) {
ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(di.getDestination());
String originalConnectionId = di.getConnectionId().getValue();
protocolManager.fireAdvisory(context, topic, di, info.getConsumerId(), originalConnectionId);
}
}
}
}
}
use of javax.jms.IllegalStateException in project activemq-artemis by apache.
the class ChangeSessionDeliveryModeTest method testDoChangeSessionDeliveryMode.
/**
* test following condition- which are defined by JMS Spec 1.1:
* MessageConsumers cannot use a MessageListener and receive() from the same
* session
*
* @throws Exception
*/
public void testDoChangeSessionDeliveryMode() throws Exception {
Destination destination = createDestination("foo.bar");
Connection connection = createConnection();
connection.start();
Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer1 = consumerSession.createConsumer(destination);
consumer1.setMessageListener(this);
MessageConsumer consumer2 = consumerSession.createConsumer(destination);
try {
consumer2.receive(10);
fail("Did not receive expected exception.");
} catch (JMSException e) {
assertTrue(e instanceof IllegalStateException);
}
}
use of javax.jms.IllegalStateException in project activemq-artemis by apache.
the class ActiveMQSession method unsubscribe.
@Override
public void unsubscribe(final String name) throws JMSException {
// As per spec. section 4.11
if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) {
throw new IllegalStateException("Cannot unsubscribe using a QueueSession");
}
SimpleString queueName = ActiveMQDestination.createQueueNameForSubscription(true, connection.getClientID(), name);
try {
QueueQuery response = session.queueQuery(queueName);
if (!response.isExists()) {
throw new InvalidDestinationException("Cannot unsubscribe, subscription with name " + name + " does not exist");
}
if (response.getConsumerCount() != 0) {
throw new IllegalStateException("Cannot unsubscribe durable subscription " + name + " since it has active subscribers");
}
session.deleteQueue(queueName);
} catch (ActiveMQException e) {
throw JMSExceptionHelper.convertFromActiveMQException(e);
}
}
Aggregations