From b899595e01d149bf20af3bbbfb01ecc5e0bee198 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 20 Jan 2012 17:10:30 -0500 Subject: [PATCH] INT-2413 And When an AbstractMappingMessageRouter is included in an ApplicationContext that also has an , the @ManagedOperations (set and remove mapping) are no longer visible to the . Adds these methods to a new interface MappingMessageRouterManagement, thus making them available on the proxy that the MBean exporter creates. --- .../router/AbstractMappingMessageRouter.java | 4 +- .../MappingMessageRouterManagement.java | 39 +++++++++++++ .../jmx/UpdateMappingsTests-context.xml | 32 ++++++++++ .../integration/jmx/UpdateMappingsTests.java | 58 +++++++++++++++++++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/router/MappingMessageRouterManagement.java create mode 100644 spring-integration-jmx/src/test/java/org/springframework/integration/jmx/UpdateMappingsTests-context.xml create mode 100644 spring-integration-jmx/src/test/java/org/springframework/integration/jmx/UpdateMappingsTests.java diff --git a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java index 72f496b8b6..25a243bd7c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -45,7 +45,7 @@ import org.springframework.util.StringUtils; * @author Gary Russell * @since 2.1 */ -public abstract class AbstractMappingMessageRouter extends AbstractMessageRouter { +public abstract class AbstractMappingMessageRouter extends AbstractMessageRouter implements MappingMessageRouterManagement { private volatile Map channelMappings = new ConcurrentHashMap(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/router/MappingMessageRouterManagement.java b/spring-integration-core/src/main/java/org/springframework/integration/router/MappingMessageRouterManagement.java new file mode 100644 index 0000000000..08ed86e7bf --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/router/MappingMessageRouterManagement.java @@ -0,0 +1,39 @@ +/* + * Copyright 2002-2012 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.integration.router; + +import org.springframework.jmx.export.annotation.ManagedOperation; + +/** + * @author Gary Russell + * @since 2.1 + * + */ +public interface MappingMessageRouterManagement { + + /** + * Add a channel mapping from the provided key to channel name. + */ + @ManagedOperation + public abstract void setChannelMapping(String key, String channelName); + + /** + * Remove a channel mapping for the given key if present. + */ + @ManagedOperation + public abstract void removeChannelMapping(String key); + +} \ No newline at end of file diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/UpdateMappingsTests-context.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/UpdateMappingsTests-context.xml new file mode 100644 index 0000000000..a3a95ee8a0 --- /dev/null +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/UpdateMappingsTests-context.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/UpdateMappingsTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/UpdateMappingsTests.java new file mode 100644 index 0000000000..91b60ae712 --- /dev/null +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/UpdateMappingsTests.java @@ -0,0 +1,58 @@ +/* + * Copyright 2002-2012 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.integration.jmx; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.Message; +import org.springframework.integration.MessageChannel; +import org.springframework.integration.core.PollableChannel; +import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Gary Russell + * @since 2.1 + * + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class UpdateMappingsTests { + + @Autowired + private MessageChannel control; + + @Autowired + private MessageChannel in; + + @Autowired + private PollableChannel qux; + + @Test + public void test() { + control.send(new GenericMessage("@myRouter.setChannelMapping('baz', 'qux')")); + Message message = MessageBuilder.withPayload("Hello, world!") + .setHeader("routing.header", "baz").build(); + in.send(message); + assertNotNull(qux.receive()); + } + +}