git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1166216 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2011-09-07 15:11:10 +00:00
parent acde68e3ab
commit 251dc7bb23
2 changed files with 123 additions and 99 deletions

View File

@ -87,6 +87,7 @@ import org.apache.activemq.thread.Scheduler;
import org.apache.activemq.transaction.Synchronization; import org.apache.activemq.transaction.Synchronization;
import org.apache.activemq.usage.MemoryUsage; import org.apache.activemq.usage.MemoryUsage;
import org.apache.activemq.util.Callback; import org.apache.activemq.util.Callback;
import org.apache.activemq.util.JMSExceptionSupport;
import org.apache.activemq.util.LongSequenceGenerator; import org.apache.activemq.util.LongSequenceGenerator;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -181,12 +182,12 @@ import org.slf4j.LoggerFactory;
*/ */
public class ActiveMQSession implements Session, QueueSession, TopicSession, StatsCapable, ActiveMQDispatcher { public class ActiveMQSession implements Session, QueueSession, TopicSession, StatsCapable, ActiveMQDispatcher {
/** /**
* Only acknowledge an individual message - using message.acknowledge() * Only acknowledge an individual message - using message.acknowledge()
* as opposed to CLIENT_ACKNOWLEDGE which * as opposed to CLIENT_ACKNOWLEDGE which
* acknowledges all messages consumed by a session at when acknowledge() * acknowledges all messages consumed by a session at when acknowledge()
* is called * is called
*/ */
public static final int INDIVIDUAL_ACKNOWLEDGE = 4; public static final int INDIVIDUAL_ACKNOWLEDGE = 4;
public static final int MAX_ACK_CONSTANT = INDIVIDUAL_ACKNOWLEDGE; public static final int MAX_ACK_CONSTANT = INDIVIDUAL_ACKNOWLEDGE;
@ -1273,6 +1274,11 @@ public class ActiveMQSession implements Session, QueueSession, TopicSession, Sta
public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal) throws JMSException { public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal) throws JMSException {
checkClosed(); checkClosed();
if (isIndividualAcknowledge()) {
throw JMSExceptionSupport.create("Cannot create a durable consumer for a Session in "+
"INDIVIDUAL_ACKNOWLEDGE mode.", null);
}
if (topic instanceof CustomDestination) { if (topic instanceof CustomDestination) {
CustomDestination customDestination = (CustomDestination)topic; CustomDestination customDestination = (CustomDestination)topic;
return customDestination.createDurableSubscriber(this, name, messageSelector, noLocal); return customDestination.createDurableSubscriber(this, name, messageSelector, noLocal);
@ -1830,7 +1836,7 @@ public class ActiveMQSession implements Session, QueueSession, TopicSession, Sta
} }
public boolean isIndividualAcknowledge(){ public boolean isIndividualAcknowledge(){
return acknowledgementMode == ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE; return acknowledgementMode == ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE;
} }
/** /**

View File

@ -24,6 +24,7 @@ import javax.jms.MessageProducer;
import javax.jms.Queue; import javax.jms.Queue;
import javax.jms.Session; import javax.jms.Session;
import javax.jms.TextMessage; import javax.jms.TextMessage;
import javax.jms.Topic;
/** /**
* *
@ -153,6 +154,23 @@ public class JMSIndividualAckTest extends TestSupport {
session.close(); session.close();
} }
/**
* Tests that a durable consumer cannot be created for Individual Ack mode.
*
* @throws JMSException
*/
public void testCreateDurableConsumerFails() throws JMSException {
connection.start();
Session session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
Topic dest = session.createTopic(getName());
try {
session.createDurableSubscriber(dest, getName());
fail("Should not be able to create duable subscriber.");
} catch(Exception e) {
}
}
protected String getQueueName() { protected String getQueueName() {
return getClass().getName() + "." + getName(); return getClass().getName() + "." + getName();
} }