fixed JMS CachingConnectionFactory to correctly cache a producer without fixed destination as well (SPR-7148)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3485 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2010-07-15 17:05:30 +00:00
parent 4852217b79
commit 8e826873ca
1 changed files with 24 additions and 11 deletions

View File

@ -314,18 +314,30 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
}
else {
this.transactionOpen = true;
if ((methodName.equals("createProducer") || methodName.equals("createSender") ||
methodName.equals("createPublisher")) && isCacheProducers()) {
if (isCacheProducers() && (methodName.equals("createProducer") ||
methodName.equals("createSender") || methodName.equals("createPublisher"))) {
// Destination argument being null is ok for a producer
return getCachedProducer((Destination) args[0]);
}
else if ((methodName.equals("createConsumer") || methodName.equals("createReceiver") ||
methodName.equals("createSubscriber")) && isCacheConsumers()) {
return getCachedConsumer((Destination) args[0], (args.length > 1 ? (String) args[1] : null),
(args.length > 2 && (Boolean) args[2]), null);
}
else if (methodName.equals("createDurableSubscriber") && isCacheConsumers()) {
return getCachedConsumer((Destination) args[0], (args.length > 2 ? (String) args[2] : null),
(args.length > 3 && (Boolean) args[3]), (String) args[1]);
else if (isCacheConsumers()) {
// let raw JMS invocation throw an exception if Destination (i.e. args[0]) is null
if ((methodName.equals("createConsumer") || methodName.equals("createReceiver") ||
methodName.equals("createSubscriber"))) {
if (args[0] != null) {
return getCachedConsumer((Destination) args[0],
(args.length > 1 ? (String) args[1] : null),
(args.length > 2 && (Boolean) args[2]),
null);
}
}
else if (methodName.equals("createDurableSubscriber")) {
if (args[0] != null) {
return getCachedConsumer((Destination) args[0],
(args.length > 2 ? (String) args[2] : null),
(args.length > 3 && (Boolean) args[3]),
(String) args[1]);
}
}
}
}
try {
@ -337,7 +349,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
}
private MessageProducer getCachedProducer(Destination dest) throws JMSException {
DestinationCacheKey cacheKey = new DestinationCacheKey(dest);
DestinationCacheKey cacheKey = (dest != null ? new DestinationCacheKey(dest) : null);
MessageProducer producer = this.cachedProducers.get(cacheKey);
if (producer != null) {
if (logger.isTraceEnabled()) {
@ -439,6 +451,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
private String destinationString;
public DestinationCacheKey(Destination destination) {
Assert.notNull(destination, "Destination must not be null");
this.destination = destination;
}