From 86091eecfd507fcb67a72821a871f85dd65f528c Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Thu, 8 Apr 2010 18:10:22 +0000 Subject: [PATCH] INT-1023 Added namespace support for the Control Bus. --- .../jmx/config/ControlBusParser.java | 58 +++++++++++++++++++ .../jmx/config/JmxNamespaceHandler.java | 1 + .../jmx/config/spring-integration-jmx-2.0.xsd | 39 +++++++++++++ .../config/ControlBusParserTests-context.xml | 22 +++++++ .../jmx/config/ControlBusParserTests.java | 48 +++++++++++++++ 5 files changed, 168 insertions(+) create mode 100644 org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/config/ControlBusParser.java create mode 100644 org.springframework.integration.jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests-context.xml create mode 100644 org.springframework.integration.jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java diff --git a/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/config/ControlBusParser.java b/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/config/ControlBusParser.java new file mode 100644 index 0000000000..c658ee6172 --- /dev/null +++ b/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/config/ControlBusParser.java @@ -0,0 +1,58 @@ +/* + * Copyright 2002-2010 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.config; + +import javax.management.MBeanServerFactory; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.config.xml.IntegrationNamespaceUtils; +import org.springframework.util.StringUtils; + +/** + * @author Mark Fisher + * @since 2.0 + */ +public class ControlBusParser extends AbstractSimpleBeanDefinitionParser { + + @Override + protected String getBeanClassName(Element element) { + return "org.springframework.integration.control.ControlBus"; + } + + @Override + protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + Object source = parserContext.extractSource(element); + builder.getRawBeanDefinition().setSource(source); + String mbeanServer = element.getAttribute("mbean-server"); + if (StringUtils.hasText(mbeanServer)) { + builder.addConstructorArgReference(mbeanServer); + } + else { + builder.addConstructorArgValue(MBeanServerFactory.createMBeanServer()); + } + String domain = element.getAttribute("domain"); + if (StringUtils.hasText(domain)) { + builder.addConstructorArgValue(domain); + } + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "operation-channel"); + } + +} diff --git a/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/config/JmxNamespaceHandler.java b/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/config/JmxNamespaceHandler.java index 557716f414..6acc15dc54 100644 --- a/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/config/JmxNamespaceHandler.java +++ b/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/config/JmxNamespaceHandler.java @@ -31,6 +31,7 @@ public class JmxNamespaceHandler extends AbstractIntegrationNamespaceHandler { this.registerBeanDefinitionParser("attribute-polling-channel-adapter", new AttributePollingChannelAdapterParser()); this.registerBeanDefinitionParser("notification-listening-channel-adapter", new NotificationListeningChannelAdapterParser()); this.registerBeanDefinitionParser("notification-publishing-channel-adapter", new NotificationPublishingChannelAdapterParser()); + this.registerBeanDefinitionParser("control-bus", new ControlBusParser()); } } diff --git a/org.springframework.integration.jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.0.xsd b/org.springframework.integration.jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.0.xsd index 0f87ddf7c1..4b4cfcb9ab 100644 --- a/org.springframework.integration.jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.0.xsd +++ b/org.springframework.integration.jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.0.xsd @@ -84,4 +84,43 @@ + + + + Defines a Control Bus that exports Message Channels and Endpoints as MBeans + and connects to an "operation channel". + + + + + + + + The MBeanServer to which this Control Bus should export MBeans. + + + + + + + The domain name for the MBeans exported by this Control Bus. + + + + + + + The Message Channel that can be used to send operation commands to + this Control Bus. It must implement SubscribableChannel. + + + + + + + + + + + \ No newline at end of file diff --git a/org.springframework.integration.jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests-context.xml b/org.springframework.integration.jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests-context.xml new file mode 100644 index 0000000000..b2bfd4e9e0 --- /dev/null +++ b/org.springframework.integration.jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests-context.xml @@ -0,0 +1,22 @@ + + + + + + + + + + diff --git a/org.springframework.integration.jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java b/org.springframework.integration.jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java new file mode 100644 index 0000000000..c81f76c8e3 --- /dev/null +++ b/org.springframework.integration.jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java @@ -0,0 +1,48 @@ +/* + * Copyright 2002-2010 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.config; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.integration.control.ControlBus; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Mark Fisher + * @since 2.0 + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class ControlBusParserTests { + + @Autowired + private ApplicationContext context; + + + @Test + public void test() throws InterruptedException { + ControlBus controlBus = this.context.getBean("controlBus", ControlBus.class); + assertEquals(controlBus.getOperationChannel(), this.context.getBean("testChannel")); + } + +}