Skip to content

Commit 526b463

Browse files
committed
Standard use of resolvedDestinationCache Map; fixed formatting
Issue: SPR-11939
1 parent 6d15fcc commit 526b463

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

spring-messaging/src/main/java/org/springframework/messaging/core/CachingDestinationResolverProxy.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.messaging.core;
1818

19+
import java.util.Map;
1920
import java.util.concurrent.ConcurrentHashMap;
2021

2122
import org.springframework.beans.factory.InitializingBean;
@@ -34,9 +35,9 @@
3435
*/
3536
public class CachingDestinationResolverProxy<D> implements DestinationResolver<D>, InitializingBean {
3637

37-
private final ConcurrentHashMap<String, D> resolvedDestinationCache = new ConcurrentHashMap<String, D>();
38+
private final Map<String, D> resolvedDestinationCache = new ConcurrentHashMap<String, D>();
3839

39-
private DestinationResolver<D> targetDestinationResolver;
40+
private DestinationResolver<D> targetDestinationResolver;
4041

4142

4243
/**
@@ -47,14 +48,14 @@ public CachingDestinationResolverProxy() {
4748
}
4849

4950
/**
50-
* Create a new CachingDestinationResolverProxy using the given target
51+
* Create a new CachingDestinationResolverProxy using the given target
5152
* DestinationResolver to actually resolve destinations.
52-
* @param targetDestinationResolver the target DestinationResolver to delegate to
53-
*/
54-
public CachingDestinationResolverProxy(DestinationResolver<D> targetDestinationResolver) {
55-
Assert.notNull(targetDestinationResolver, "Target DestinationResolver must not be null");
56-
this.targetDestinationResolver = targetDestinationResolver;
57-
}
53+
* @param targetDestinationResolver the target DestinationResolver to delegate to
54+
*/
55+
public CachingDestinationResolverProxy(DestinationResolver<D> targetDestinationResolver) {
56+
Assert.notNull(targetDestinationResolver, "Target DestinationResolver must not be null");
57+
this.targetDestinationResolver = targetDestinationResolver;
58+
}
5859

5960

6061
/**
@@ -73,22 +74,21 @@ public void afterPropertiesSet() {
7374

7475

7576
/**
76-
*
77-
* Resolves and caches destinations if successfully resolved by the target
78-
* DestinationResolver implementation.
79-
* @param name the destination name to be resolved
80-
* @return the currently resolved destination or an already cached destination
81-
* @throws DestinationResolutionException if the target DestinationResolver
82-
* reports an error during destination resolution
83-
*/
84-
@Override
85-
public D resolveDestination(String name) throws DestinationResolutionException {
86-
D destination = this.resolvedDestinationCache.get(name);
77+
* Resolves and caches destinations if successfully resolved by the target
78+
* DestinationResolver implementation.
79+
* @param name the destination name to be resolved
80+
* @return the currently resolved destination or an already cached destination
81+
* @throws DestinationResolutionException if the target DestinationResolver
82+
* reports an error during destination resolution
83+
*/
84+
@Override
85+
public D resolveDestination(String name) throws DestinationResolutionException {
86+
D destination = this.resolvedDestinationCache.get(name);
8787
if (destination == null) {
88-
destination = this.targetDestinationResolver.resolveDestination(name);
89-
this.resolvedDestinationCache.putIfAbsent(name, destination);
90-
}
91-
return destination;
92-
}
88+
destination = this.targetDestinationResolver.resolveDestination(name);
89+
this.resolvedDestinationCache.put(name, destination);
90+
}
91+
return destination;
92+
}
9393

9494
}

spring-messaging/src/test/java/org/springframework/messaging/core/CachingDestinationResolverTests.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.messaging.core;
1718

1819
import org.junit.Test;
@@ -28,33 +29,33 @@
2829
*/
2930
public class CachingDestinationResolverTests {
3031

31-
@Test
32-
public void cachedDestination() {
33-
@SuppressWarnings("unchecked")
34-
DestinationResolver<String> destinationResolver = (DestinationResolver<String>) mock(DestinationResolver.class);
35-
CachingDestinationResolverProxy<String> cachingDestinationResolver = new CachingDestinationResolverProxy<String>(destinationResolver);
32+
@Test
33+
public void cachedDestination() {
34+
@SuppressWarnings("unchecked")
35+
DestinationResolver<String> destinationResolver = (DestinationResolver<String>) mock(DestinationResolver.class);
36+
CachingDestinationResolverProxy<String> cachingDestinationResolver = new CachingDestinationResolverProxy<String>(destinationResolver);
3637

37-
when(destinationResolver.resolveDestination("abcd")).thenReturn("dcba");
38+
when(destinationResolver.resolveDestination("abcd")).thenReturn("dcba");
3839
when(destinationResolver.resolveDestination("1234")).thenReturn("4321");
3940

40-
assertEquals("dcba", cachingDestinationResolver.resolveDestination("abcd"));
41-
assertEquals("4321", cachingDestinationResolver.resolveDestination("1234"));
41+
assertEquals("dcba", cachingDestinationResolver.resolveDestination("abcd"));
42+
assertEquals("4321", cachingDestinationResolver.resolveDestination("1234"));
4243
assertEquals("4321", cachingDestinationResolver.resolveDestination("1234"));
4344
assertEquals("dcba", cachingDestinationResolver.resolveDestination("abcd"));
4445

45-
verify(destinationResolver, times(1)).resolveDestination("abcd");
46+
verify(destinationResolver, times(1)).resolveDestination("abcd");
4647
verify(destinationResolver, times(1)).resolveDestination("1234");
47-
}
48+
}
4849

4950
@Test(expected = IllegalArgumentException.class)
5051
public void noTargetSet() {
5152
CachingDestinationResolverProxy<String> cachingDestinationResolver = new CachingDestinationResolverProxy<String>();
5253
cachingDestinationResolver.afterPropertiesSet();
5354
}
5455

55-
@Test(expected = IllegalArgumentException.class)
56-
public void nullTargetThroughConstructor() {
57-
new CachingDestinationResolverProxy<String>(null);
58-
}
56+
@Test(expected = IllegalArgumentException.class)
57+
public void nullTargetThroughConstructor() {
58+
new CachingDestinationResolverProxy<String>(null);
59+
}
5960

6061
}

0 commit comments

Comments
 (0)