From 1bc41bdf0f4f491259c2079de48a93ed1dfbe9eb Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 2 Nov 2015 16:13:33 +0100 Subject: [PATCH] Expose JMS message listener container ids Issue: SPR-13633 --- .../jms/config/JmsListenerEndpointRegistry.java | 10 ++++++++++ .../annotation/AbstractJmsAnnotationDrivenTests.java | 2 ++ .../jms/config/JmsListenerEndpointRegistrarTests.java | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistry.java b/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistry.java index 2056a38b93..96778ca6af 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistry.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistry.java @@ -19,6 +19,7 @@ package org.springframework.jms.config; import java.util.Collection; import java.util.Collections; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; @@ -68,12 +69,21 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc * @param id the id of the container * @return the container or {@code null} if no container with that id exists * @see JmsListenerEndpoint#getId() + * @see #getListenerContainerIds() */ public MessageListenerContainer getListenerContainer(String id) { Assert.notNull(id, "Container identifier must not be null"); return this.listenerContainers.get(id); } + /** + * Return the ids of the managed {@link MessageListenerContainer} instance(s). + * @see #getListenerContainer(String) + */ + public Set getListenerContainerIds() { + return Collections.unmodifiableSet(this.listenerContainers.keySet()); + } + /** * Return the managed {@link MessageListenerContainer} instance(s). */ diff --git a/spring-jms/src/test/java/org/springframework/jms/annotation/AbstractJmsAnnotationDrivenTests.java b/spring-jms/src/test/java/org/springframework/jms/annotation/AbstractJmsAnnotationDrivenTests.java index b58bfb4dd6..94ae1162cc 100644 --- a/spring-jms/src/test/java/org/springframework/jms/annotation/AbstractJmsAnnotationDrivenTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/annotation/AbstractJmsAnnotationDrivenTests.java @@ -169,6 +169,8 @@ public abstract class AbstractJmsAnnotationDrivenTests { JmsListenerEndpointRegistry customRegistry = context.getBean("customRegistry", JmsListenerEndpointRegistry.class); + assertEquals("Wrong number of containers in the registry", 2, + customRegistry.getListenerContainerIds().size()); assertEquals("Wrong number of containers in the registry", 2, customRegistry.getListenerContainers().size()); assertNotNull("Container with custom id on the annotation should be found", diff --git a/spring-jms/src/test/java/org/springframework/jms/config/JmsListenerEndpointRegistrarTests.java b/spring-jms/src/test/java/org/springframework/jms/config/JmsListenerEndpointRegistrarTests.java index 4ada4a2798..ed6e90826e 100644 --- a/spring-jms/src/test/java/org/springframework/jms/config/JmsListenerEndpointRegistrarTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/config/JmsListenerEndpointRegistrarTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -76,6 +76,7 @@ public class JmsListenerEndpointRegistrarTests { registrar.afterPropertiesSet(); assertNotNull("Container not created", registry.getListenerContainer("some id")); assertEquals(1, registry.getListenerContainers().size()); + assertEquals("some id", registry.getListenerContainerIds().iterator().next()); } @Test @@ -98,6 +99,7 @@ public class JmsListenerEndpointRegistrarTests { registrar.afterPropertiesSet(); assertNotNull("Container not created", registry.getListenerContainer("myEndpoint")); assertEquals(1, registry.getListenerContainers().size()); + assertEquals("myEndpoint", registry.getListenerContainerIds().iterator().next()); } } -- GitLab