Cache key classes implement Comparable and consistently provide a toString representation

Issue: SPR-14017
This commit is contained in:
Juergen Hoeller
2016-03-26 14:32:10 +01:00
parent a8b5ea1c51
commit 54aeb7a5d6
15 changed files with 222 additions and 54 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -509,7 +509,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
* Simple wrapper class around a Destination reference.
* Used as the cache key when caching MessageProducer objects.
*/
private static class DestinationCacheKey {
private static class DestinationCacheKey implements Comparable<DestinationCacheKey> {
private final Destination destination;
@@ -537,7 +537,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
public boolean equals(Object other) {
// Effectively checking object equality as well as toString equality.
// On WebSphere MQ, Destination objects do not implement equals...
return (other == this || destinationEquals((DestinationCacheKey) other));
return (this == other || destinationEquals((DestinationCacheKey) other));
}
@Override
@@ -547,6 +547,16 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
// for equivalent destinations... Thanks a lot, WebSphere MQ!
return this.destination.getClass().hashCode();
}
@Override
public String toString() {
return getDestinationString();
}
@Override
public int compareTo(DestinationCacheKey other) {
return getDestinationString().compareTo(other.getDestinationString());
}
}
@@ -584,6 +594,12 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
ObjectUtils.nullSafeEquals(this.subscription, otherKey.subscription) &&
this.durable == otherKey.durable);
}
@Override
public String toString() {
return super.toString() + " [selector=" + this.selector + ", noLocal=" + this.noLocal +
", subscription=" + this.subscription + ", durable=" + this.durable + "]";
}
}
}