From 473b8fa96db5702bfadd07fc147e846d2d54a7d0 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 25 Oct 2010 10:58:20 -0700 Subject: [PATCH] INT-1507: remove control bus from JMX XSD --- .../integration/jmx/ControlBus.java | 101 --------- .../jmx/config/ControlBusFactoryBean.java | 55 ----- .../jmx/config/ControlBusParser.java | 51 ----- .../jmx/config/JmxNamespaceHandler.java | 2 +- .../jmx/config/spring-integration-jmx-2.0.xsd | 39 ---- .../integration/IgnoredTestSuite.java | 35 ++- .../ControlBusOperationChannelTests.java | 101 --------- .../integration/control/ControlBusTests.java | 201 ------------------ .../control/ControlBusXmlTests-context.xml | 39 ---- .../control/ControlBusXmlTests.java | 86 -------- .../config/ControlBusParserTests-context.xml | 4 +- .../jmx/config/ControlBusParserTests.java | 40 ++-- ...hMessageProducingHandlersTests-context.xml | 8 - 13 files changed, 37 insertions(+), 725 deletions(-) delete mode 100644 spring-integration-jmx/src/main/java/org/springframework/integration/jmx/ControlBus.java delete mode 100644 spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/ControlBusFactoryBean.java delete mode 100644 spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/ControlBusParser.java delete mode 100644 spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusOperationChannelTests.java delete mode 100644 spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusTests.java delete mode 100644 spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusXmlTests-context.xml delete mode 100644 spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusXmlTests.java diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/ControlBus.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/ControlBus.java deleted file mode 100644 index 771a62d1a2..0000000000 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/ControlBus.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.ListableBeanFactory; -import org.springframework.integration.Message; -import org.springframework.integration.MessageHeaders; -import org.springframework.integration.core.SubscribableChannel; -import org.springframework.integration.monitor.ObjectNameLocator; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.util.Assert; - -import javax.management.MBeanServer; - -/** - * JMX-based Control Bus implementation. Routes control messages on an operation channel to the other control points - * (channels and handlers) via JMX. To use the control bus send a message to the operation channel with a header - * {@link #TARGET_BEAN_NAME} equal to the bean name of the channel or endpoint you want to target. Include also a header - * {@link JmxHeaders#OPERATION_NAME} to specify the operation you want to invoke and a message payload containing the - * arguments (if any). - * - * @author Mark Fisher - * @since 2.0 - */ -public class ControlBus implements BeanFactoryAware, InitializingBean { - - public static final String TARGET_BEAN_NAME = JmxHeaders.PREFIX + "_controlBus_targetBeanName"; - - private final SubscribableChannel operationChannel; - - private volatile ListableBeanFactory beanFactory; - - private final ObjectNameLocator exporter; - - private final MBeanServer server; - - /** - * Create a {@link ControlBus}. - */ - public ControlBus(ObjectNameLocator locator, MBeanServer server, SubscribableChannel operationChannel) { - this.exporter = locator; - this.server = server; - this.operationChannel = operationChannel; - } - - /** - * Returns the channel to which operation-invoking Messages may be sent. Any messages sent to this channel must - * contain {@link ControlBus#TARGET_BEAN_NAME} and {@link JmxHeaders#OPERATION_NAME} header values, and the target - * bean name must match one that has been exported by this Control Bus. If the operation returns a result, the - * {@link MessageHeaders#REPLY_CHANNEL} header is also required. - */ - public SubscribableChannel getOperationChannel() { - return this.operationChannel; - } - - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - Assert.isTrue(beanFactory instanceof ListableBeanFactory, "A ListableBeanFactory is required."); - this.beanFactory = (ListableBeanFactory) beanFactory; - } - - public void afterPropertiesSet() throws Exception { - OperationInvokingMessageHandler handler = new ControlBusOperationInvokingMessageHandler(); - handler.setBeanFactory(this.beanFactory); - handler.setServer(this.server); - handler.afterPropertiesSet(); - this.operationChannel.subscribe(handler); - } - - private class ControlBusOperationInvokingMessageHandler extends OperationInvokingMessageHandler { - - @Override - protected Object handleRequestMessage(Message requestMessage) { - String beanName = requestMessage.getHeaders().get(TARGET_BEAN_NAME, String.class); - Assert.notNull(beanName, "The ControlBus.TARGET_BEAN_NAME is required."); - String objectName = exporter.getObjectName(beanName); - Assert.notNull(objectName, "ControlBus has not exported an MBean for '" + beanName + "'"); - requestMessage = MessageBuilder.fromMessage(requestMessage).setHeader(JmxHeaders.OBJECT_NAME, objectName) - .setHeader(TARGET_BEAN_NAME, null).build(); - return super.handleRequestMessage(requestMessage); - } - } - -} diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/ControlBusFactoryBean.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/ControlBusFactoryBean.java deleted file mode 100644 index 77cb1ef046..0000000000 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/ControlBusFactoryBean.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 org.springframework.beans.factory.FactoryBean; -import org.springframework.integration.channel.DirectChannel; -import org.springframework.integration.jmx.ControlBus; -import org.springframework.integration.core.SubscribableChannel; -import org.springframework.integration.monitor.IntegrationMBeanExporter; - -/** - * @author Dave Syer - * @since 2.0 - * - */ -public class ControlBusFactoryBean implements FactoryBean { - - private final SubscribableChannel operationChannel; - private final IntegrationMBeanExporter exporter; - - public ControlBusFactoryBean(IntegrationMBeanExporter exporter, SubscribableChannel operationChannel) { - this.exporter = exporter; - this.operationChannel = operationChannel; - } - - public ControlBusFactoryBean(IntegrationMBeanExporter exporter) { - this(exporter, new DirectChannel()); - } - - public ControlBus getObject() throws Exception { - return new ControlBus(exporter, exporter.getServer(), operationChannel); - } - - public Class getObjectType() { - return ControlBus.class; - } - - public boolean isSingleton() { - return true; - } - -} diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/ControlBusParser.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/ControlBusParser.java deleted file mode 100644 index 4e1ed05dbe..0000000000 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/ControlBusParser.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.util.StringUtils; -import org.w3c.dom.Element; - -/** - * @author Mark Fisher - * @since 2.0 - */ -public class ControlBusParser extends AbstractSingleBeanDefinitionParser { - - @Override - protected boolean shouldGenerateIdAsFallback() { - return true; - } - - @Override - protected String getBeanClassName(Element element) { - return "org.springframework.integration.jmx.config.ControlBusFactoryBean"; - } - - @Override - protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - builder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); - builder.addConstructorArgReference(element.getAttribute("mbean-exporter")); - if (StringUtils.hasLength(element.getAttribute("operation-channel"))) { - builder.addConstructorArgReference(element.getAttribute("operation-channel")); - - } - } - -} diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/JmxNamespaceHandler.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/JmxNamespaceHandler.java index eff9e98816..3d498e3924 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/JmxNamespaceHandler.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/JmxNamespaceHandler.java @@ -23,6 +23,7 @@ import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHa * * @author Mark Fisher * @author Oleg Zhurakousky + * @author Dave Syer * @since 2.0 */ public class JmxNamespaceHandler extends AbstractIntegrationNamespaceHandler { @@ -34,7 +35,6 @@ public class JmxNamespaceHandler extends AbstractIntegrationNamespaceHandler { this.registerBeanDefinitionParser("notification-listening-channel-adapter", new NotificationListeningChannelAdapterParser()); this.registerBeanDefinitionParser("notification-publishing-channel-adapter", new NotificationPublishingChannelAdapterParser()); this.registerBeanDefinitionParser("mbean-export", new MBeanExporterParser()); - this.registerBeanDefinitionParser("control-bus", new ControlBusParser()); } } diff --git a/spring-integration-jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.0.xsd b/spring-integration-jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.0.xsd index bcff9d33df..30b58d08d6 100644 --- a/spring-integration-jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.0.xsd +++ b/spring-integration-jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.0.xsd @@ -117,45 +117,6 @@ - - - - Control bus accepts control messages for channels and endpoints on an (optional) "operation - channel". - - - - - - - - A reference to the MBeanExporter created using <mbean-exporter/> in this namespace. - - - - - - - - - - - - If provided a control bus will be created and subscribed to the Message Channel. - The channel can - then be used to send operation commands to - this Control Bus. It must implement SubscribableChannel. - - - - - - - - - - - diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/IgnoredTestSuite.java b/spring-integration-jmx/src/test/java/org/springframework/integration/IgnoredTestSuite.java index b6061b93dc..3adf09261a 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/IgnoredTestSuite.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/IgnoredTestSuite.java @@ -4,33 +4,29 @@ import org.junit.Ignore; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import org.springframework.integration.control.ControlBusTests; -import org.springframework.integration.control.ControlBusXmlTests; +import org.springframework.integration.config.xml.ControlBusTests; import org.springframework.integration.jmx.AttributePollingMessageSourceTests; import org.springframework.integration.jmx.NotificationListeningMessageProducerTests; import org.springframework.integration.jmx.OperationInvokingMessageHandlerTests; import org.springframework.integration.jmx.config.NotificationListeningChannelAdapterParserTests; import org.springframework.integration.jmx.config.OperationInvokingChannelAdapterParserTests; import org.springframework.integration.jmx.config.OperationInvokingOutboundGatewayTests; -import org.springframework.integration.monitor.ExponentialMovingAverageTests; import org.springframework.integration.monitor.ExponentialMovingAverageRatioTests; +import org.springframework.integration.monitor.ExponentialMovingAverageTests; import org.springframework.integration.monitor.HandlerMonitoringIntegrationTests; import org.springframework.integration.monitor.MessageChannelsMonitorIntegrationTests; /* * Copyright 2009-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. + * + * 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. */ /** @@ -40,11 +36,10 @@ import org.springframework.integration.monitor.MessageChannelsMonitorIntegration * */ @RunWith(Suite.class) -@SuiteClasses(value = { OperationInvokingMessageHandlerTests.class, - ExponentialMovingAverageTests.class, OperationInvokingChannelAdapterParserTests.class, - HandlerMonitoringIntegrationTests.class, NotificationListeningMessageProducerTests.class, - OperationInvokingOutboundGatewayTests.class, NotificationListeningChannelAdapterParserTests.class, - ControlBusXmlTests.class, ExponentialMovingAverageRatioTests.class, +@SuiteClasses(value = { OperationInvokingMessageHandlerTests.class, ExponentialMovingAverageTests.class, + OperationInvokingChannelAdapterParserTests.class, HandlerMonitoringIntegrationTests.class, + NotificationListeningMessageProducerTests.class, OperationInvokingOutboundGatewayTests.class, + NotificationListeningChannelAdapterParserTests.class, ExponentialMovingAverageRatioTests.class, AttributePollingMessageSourceTests.class, ControlBusTests.class, MessageChannelsMonitorIntegrationTests.class }) @Ignore public class IgnoredTestSuite { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusOperationChannelTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusOperationChannelTests.java deleted file mode 100644 index 83b2e9ec51..0000000000 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusOperationChannelTests.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.control; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.After; -import org.junit.Test; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.context.support.GenericApplicationContext; -import org.springframework.integration.Message; -import org.springframework.integration.channel.DirectChannel; -import org.springframework.integration.core.MessageHandler; -import org.springframework.integration.endpoint.EventDrivenConsumer; -import org.springframework.integration.jmx.ControlBus; -import org.springframework.integration.jmx.JmxHeaders; -import org.springframework.integration.monitor.IntegrationMBeanExporter; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.jmx.support.MBeanServerFactoryBean; - -/** - * @author Mark Fisher - * @since 2.0 - */ -public class ControlBusOperationChannelTests { - - private final String domain = "domain.test"; - private GenericApplicationContext context; - - - @Test - public void replyProducingOperation() throws Exception { - context = new GenericApplicationContext(); - RootBeanDefinition endpointDef = new RootBeanDefinition(EventDrivenConsumer.class); - endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new DirectChannel()); - endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RootBeanDefinition(TestHandler.class)); - context.registerBeanDefinition("testEndpoint", endpointDef); - registerControlBus(context, domain); - context.refresh(); - ControlBus controlBus = context.getBean("controlBus", ControlBus.class); - EventDrivenConsumer endpoint = context.getBean("testEndpoint", EventDrivenConsumer.class); - Message stopMessage = MessageBuilder.withPayload("test") - .setHeader(ControlBus.TARGET_BEAN_NAME, "testEndpoint") - .setHeader(JmxHeaders.OPERATION_NAME, "stop") - .build(); - Message startMessage = MessageBuilder.withPayload("test") - .setHeader(ControlBus.TARGET_BEAN_NAME, "testEndpoint") - .setHeader(JmxHeaders.OPERATION_NAME, "start") - .build(); - assertTrue("endpoint should be running after startup", endpoint.isRunning()); - controlBus.getOperationChannel().send(stopMessage); - assertFalse("endpoint should have been stopped", endpoint.isRunning()); - controlBus.getOperationChannel().send(startMessage); - assertTrue("endpoint should be running after being restarted", endpoint.isRunning()); - close(); - } - - @After - public void close() { - context.close(); - } - - private BeanDefinition registerControlBus(GenericApplicationContext context, String domain) { - RootBeanDefinition serverDef = new RootBeanDefinition(MBeanServerFactoryBean.class); - serverDef.getPropertyValues().add("locateExistingServerIfPossible", true); - context.registerBeanDefinition("mbeanServer", serverDef); - BeanDefinition exporterDef = new RootBeanDefinition(IntegrationMBeanExporter.class); - exporterDef.getPropertyValues().addPropertyValue("server", new RuntimeBeanReference("mbeanServer")); - exporterDef.getPropertyValues().addPropertyValue("defaultDomain", domain); - context.registerBeanDefinition("exporter", exporterDef); - BeanDefinition controlBusDef = new RootBeanDefinition(ControlBus.class); - controlBusDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("mbeanServer")); - controlBusDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("exporter")); - controlBusDef.getConstructorArgumentValues().addGenericArgumentValue(new DirectChannel()); - context.registerBeanDefinition("controlBus", controlBusDef); - return exporterDef; - } - - private static class TestHandler implements MessageHandler { - public void handleMessage(Message message) { - } - } - -} diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusTests.java deleted file mode 100644 index 3ad903112a..0000000000 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusTests.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * 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.control; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.Collections; -import java.util.concurrent.atomic.AtomicInteger; - -import javax.management.MBeanServer; -import javax.management.MBeanServerFactory; -import javax.management.ObjectInstance; -import javax.management.ObjectName; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.context.support.GenericApplicationContext; -import org.springframework.integration.Message; -import org.springframework.integration.channel.DirectChannel; -import org.springframework.integration.channel.QueueChannel; -import org.springframework.integration.core.MessageHandler; -import org.springframework.integration.endpoint.EventDrivenConsumer; -import org.springframework.integration.endpoint.PollingConsumer; -import org.springframework.integration.handler.BridgeHandler; -import org.springframework.integration.jmx.ControlBus; -import org.springframework.integration.monitor.IntegrationMBeanExporter; -import org.springframework.integration.monitor.LifecycleMessageHandlerMetrics; -import org.springframework.integration.monitor.QueueChannelMetrics; -import org.springframework.integration.monitor.DirectChannelMetrics; -import org.springframework.integration.scheduling.PollerMetadata; -import org.springframework.jmx.support.MBeanServerFactoryBean; -import org.springframework.jmx.support.ObjectNameManager; -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; -import org.springframework.scheduling.support.PeriodicTrigger; - -/** - * @author Mark Fisher - * @since 2.0 - */ -public class ControlBusTests { - - private volatile GenericApplicationContext context; - - @Before - public void createContext() { - this.context = new GenericApplicationContext(); - RootBeanDefinition serverDef = new RootBeanDefinition(MBeanServerFactoryBean.class); - serverDef.getPropertyValues().add("locateExistingServerIfPossible", true); - context.registerBeanDefinition("mbeanServer", serverDef); - } - - @After - public void closeContext() { - MBeanServer mbeanServer = this.context.getBean("mbeanServer", MBeanServer.class); - try { - MBeanServerFactory.releaseMBeanServer(mbeanServer); - } - catch (Exception e) { - // ignore - } - this.context.close(); - } - - @Test - public void directChannelRegistered() throws Exception { - context.registerBeanDefinition("directChannel", new RootBeanDefinition(DirectChannel.class)); - registerControlBus(context, "domain.test1"); - context.refresh(); - MBeanServer mbeanServer = context.getBean("mbeanServer", MBeanServer.class); - ObjectInstance instance = mbeanServer.getObjectInstance(ObjectNameManager - .getInstance("domain.test1:type=MessageChannel,name=directChannel")); - assertEquals(DirectChannelMetrics.class.getName(), instance.getClassName()); - } - - @Test - public void anonymousDirectChannelRegistered() throws Exception { - context.registerBeanDefinition("org.springframework.integration.generated#0", new RootBeanDefinition( - DirectChannel.class)); - registerControlBus(context, "domain.test1b"); - context.refresh(); - MBeanServer mbeanServer = context.getBean("mbeanServer", MBeanServer.class); - ObjectInstance instance = mbeanServer - .getObjectInstance(ObjectNameManager - .getInstance("domain.test1b:type=MessageChannel,name=org.springframework.integration.generated#0,source=anonymous")); - assertEquals(DirectChannelMetrics.class.getName(), instance.getClassName()); - } - - @Test - public void staticObjectNamePropertiesRegistered() throws Exception { - context.registerBeanDefinition("directChannel", new RootBeanDefinition(DirectChannel.class)); - BeanDefinition exporterDef = registerControlBus(context, "domain.test1a"); - exporterDef.getPropertyValues().add("objectNameStaticProperties", Collections.singletonMap("foo", "bar")); - context.refresh(); - MBeanServer mbeanServer = context.getBean("mbeanServer", MBeanServer.class); - ObjectInstance instance = mbeanServer.getObjectInstance(ObjectNameManager - .getInstance("domain.test1a:type=MessageChannel,name=directChannel,foo=bar")); - assertEquals(DirectChannelMetrics.class.getName(), instance.getClassName()); - } - - @Test - public void queueChannelRegistered() throws Exception { - context.registerBeanDefinition("queueChannel", new RootBeanDefinition(QueueChannel.class)); - registerControlBus(context, "domain.test2"); - context.refresh(); - MBeanServer mbeanServer = context.getBean("mbeanServer", MBeanServer.class); - ObjectInstance instance = mbeanServer.getObjectInstance(ObjectNameManager - .getInstance("domain.test2:type=MessageChannel,name=queueChannel")); - assertEquals(QueueChannelMetrics.class.getName(), instance.getClassName()); - } - - @Test - public void eventDrivenConsumerRegistered() throws Exception { - context.registerBeanDefinition("testChannel", new RootBeanDefinition(DirectChannel.class)); - RootBeanDefinition endpointDef = new RootBeanDefinition(EventDrivenConsumer.class); - endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("testChannel")); - endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RootBeanDefinition(BridgeHandler.class)); - context.registerBeanDefinition("eventDrivenConsumer", endpointDef); - registerControlBus(context, "domain.test3"); - context.refresh(); - MBeanServer mbeanServer = context.getBean("mbeanServer", MBeanServer.class); - ObjectInstance instance = mbeanServer.getObjectInstance(ObjectNameManager - .getInstance("domain.test3:type=MessageHandler,name=eventDrivenConsumer,bean=endpoint")); - assertEquals(LifecycleMessageHandlerMetrics.class.getName(), instance.getClassName()); - } - - @Test - public void pollingConsumerRegistered() throws Exception { - context.registerBeanDefinition("testChannel", new RootBeanDefinition(QueueChannel.class)); - RootBeanDefinition endpointDef = new RootBeanDefinition(PollingConsumer.class); - endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("testChannel")); - endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RootBeanDefinition(BridgeHandler.class)); - RootBeanDefinition pollerMetaDefinition = new RootBeanDefinition(PollerMetadata.class); - pollerMetaDefinition.getPropertyValues().add("trigger", new PeriodicTrigger(10000)); - endpointDef.getPropertyValues().add("pollerMetadata", pollerMetaDefinition); - context.registerBeanDefinition("pollingConsumer", endpointDef); - context.registerBeanDefinition("taskScheduler", new RootBeanDefinition(ThreadPoolTaskScheduler.class)); - registerControlBus(context, "domain.test4"); - context.refresh(); - MBeanServer mbeanServer = context.getBean("mbeanServer", MBeanServer.class); - ObjectInstance instance = mbeanServer.getObjectInstance(ObjectNameManager - .getInstance("domain.test4:type=MessageHandler,name=pollingConsumer,bean=endpoint")); - assertEquals(LifecycleMessageHandlerMetrics.class.getName(), instance.getClassName()); - } - - @Test - public void channelMonitoring() throws Exception { - RootBeanDefinition channelDef = new RootBeanDefinition(DirectChannel.class); - context.registerBeanDefinition("testChannel", channelDef); - RootBeanDefinition endpointDef = new RootBeanDefinition(EventDrivenConsumer.class); - endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("testChannel")); - endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new MessageHandler() { - private final AtomicInteger count = new AtomicInteger(); - - public void handleMessage(Message message) { - int current = count.incrementAndGet(); - if (current % 10 == 0) { - throw new RuntimeException("intentional test failure"); - } - } - }); - context.registerBeanDefinition("testEndpoint", endpointDef); - registerControlBus(context, "domain.channel.monitor"); - context.refresh(); - MBeanServer server = context.getBean("mbeanServer", MBeanServer.class); - ObjectName objectName = ObjectNameManager.getInstance("domain.channel.monitor:type=MessageChannel,name=testChannel"); - assertNotNull(server.getObjectInstance(objectName)); - } - - private BeanDefinition registerControlBus(GenericApplicationContext context, String domain) { - BeanDefinition exporterDef = new RootBeanDefinition(IntegrationMBeanExporter.class); - exporterDef.getPropertyValues().addPropertyValue("server", new RuntimeBeanReference("mbeanServer")); - exporterDef.getPropertyValues().addPropertyValue("defaultDomain", domain); - context.registerBeanDefinition("exporter", exporterDef); - BeanDefinition controlBusDef = new RootBeanDefinition(ControlBus.class); - controlBusDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("mbeanServer")); - controlBusDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("exporter")); - controlBusDef.getConstructorArgumentValues().addGenericArgumentValue(new DirectChannel()); - context.registerBeanDefinition("controlBus", controlBusDef); - return exporterDef; - } - -} diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusXmlTests-context.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusXmlTests-context.xml deleted file mode 100644 index 03ac2709fd..0000000000 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusXmlTests-context.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusXmlTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusXmlTests.java deleted file mode 100644 index d726617b78..0000000000 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusXmlTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.control; - -import static org.junit.Assert.assertEquals; - -import java.util.Set; - -import javax.management.MBeanServer; -import javax.management.ObjectInstance; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.integration.monitor.LifecycleMessageHandlerMetrics; -import org.springframework.integration.monitor.QueueChannelMetrics; -import org.springframework.integration.monitor.DirectChannelMetrics; -import org.springframework.jmx.support.ObjectNameManager; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @author Mark Fisher - */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) -public class ControlBusXmlTests { - - private static final String DOMAIN = "control.bus.xml.test"; - - - @Autowired - private MBeanServer mbeanServer; - - - @Test - public void directChannelRegistered() throws Exception { - ObjectInstance instance = mbeanServer.getObjectInstance( - ObjectNameManager.getInstance(DOMAIN + ":type=MessageChannel,name=testDirectChannel")); - assertEquals(DirectChannelMetrics.class.getName(), instance.getClassName()); - } - - @Test - public void queueChannelRegistered() throws Exception { - ObjectInstance instance = mbeanServer.getObjectInstance( - ObjectNameManager.getInstance(DOMAIN + ":type=MessageChannel,name=testQueueChannel")); - assertEquals(QueueChannelMetrics.class.getName(), instance.getClassName()); - } - - @Test - public void eventDrivenConsumerRegistered() throws Exception { - ObjectInstance instance = mbeanServer.getObjectInstance( - ObjectNameManager.getInstance(DOMAIN + ":type=MessageHandler,name=testEventDrivenBridge,bean=endpoint")); - assertEquals(LifecycleMessageHandlerMetrics.class.getName(), instance.getClassName()); - } - - @Test - public void anonymousConsumerRegistered() throws Exception { - Set instances = mbeanServer.queryMBeans( - ObjectNameManager.getInstance(DOMAIN + ":type=MessageHandler,bean=anonymous,*"), null); - assertEquals(1, instances.size()); - assertEquals(LifecycleMessageHandlerMetrics.class.getName(), instances.iterator().next().getClassName()); - } - - @Test - public void pollingConsumerRegistered() throws Exception { - ObjectInstance instance = mbeanServer.getObjectInstance( - ObjectNameManager.getInstance(DOMAIN + ":type=MessageHandler,name=testPollingBridge,bean=endpoint")); - assertEquals(LifecycleMessageHandlerMetrics.class.getName(), instance.getClassName()); - } - -} diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests-context.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests-context.xml index 998d5b86fe..3fc4566e5d 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests-context.xml +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests-context.xml @@ -17,7 +17,9 @@ - + + + diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java index ac22cf5c22..55af365d7b 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java @@ -1,31 +1,26 @@ /* * 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. + * + * 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 javax.management.MBeanServer; - import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.integration.jmx.ControlBus; +import org.springframework.integration.MessageChannel; +import org.springframework.integration.core.MessagingTemplate; import org.springframework.jmx.export.MBeanExporter; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -42,12 +37,13 @@ public class ControlBusParserTests { private ApplicationContext context; @Test - public void test() throws InterruptedException { - ControlBus controlBus = this.context.getBean(ControlBus.class); - assertEquals(controlBus.getOperationChannel(), this.context.getBean("testChannel")); - MBeanServer server = this.context.getBean("mbs", MBeanServer.class); - MBeanExporter exporter = (MBeanExporter) new DirectFieldAccessor(controlBus).getPropertyValue("exporter"); - assertEquals(server, exporter.getServer()); + public void testControlMessageToChannelMetrics() throws InterruptedException { + MessageChannel control = this.context.getBean("controlChannel", MessageChannel.class); + MessagingTemplate messagingTemplate = new MessagingTemplate(); + Object value = messagingTemplate.convertSendAndReceive(control, + "@mbeanExporter.getChannelSendRate('testChannel').count"); + assertEquals(new Integer(0), value); + MBeanExporter exporter = this.context.getBean(MBeanExporter.class); exporter.destroy(); } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChainWithMessageProducingHandlersTests-context.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChainWithMessageProducingHandlersTests-context.xml index 27234f27a4..9e6e2ba0a4 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChainWithMessageProducingHandlersTests-context.xml +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChainWithMessageProducingHandlersTests-context.xml @@ -6,14 +6,6 @@ xmlns:int="http://www.springframework.org/schema/integration" xmlns:p="http://www.springframework.org/schema/p"> - - - - - - - -