INT-1418: add control-bus

This commit is contained in:
David Syer
2010-09-03 13:39:49 +00:00
parent 3f390274db
commit 2e4f1e5b5e
14 changed files with 297 additions and 92 deletions

View File

@@ -30,6 +30,11 @@ import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
*/
public class AttributePollingChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser {
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected String parseSource(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(

View File

@@ -0,0 +1,55 @@
/*
* 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.control.ControlBus;
import org.springframework.integration.core.SubscribableChannel;
import org.springframework.integration.monitor.IntegrationMBeanExporter;
/**
* @author Dave Syer
* @since 2.0
*
*/
public class ControlBusFactoryBean implements FactoryBean<ControlBus> {
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;
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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"));
}
}
}

View File

@@ -34,6 +34,7 @@ public class JmxNamespaceHandler extends AbstractIntegrationNamespaceHandler {
this.registerBeanDefinitionParser("notification-listening-channel-adapter", new NotificationListeningChannelAdapterParser());
this.registerBeanDefinitionParser("notification-publishing-channel-adapter", new NotificationPublishingChannelAdapterParser());
this.registerBeanDefinitionParser("mbean-exporter", new MBeanExporterParser());
this.registerBeanDefinitionParser("control-bus", new ControlBusParser());
}
}

View File

@@ -19,9 +19,8 @@ package org.springframework.integration.jmx.config;
import javax.management.MBeanServerFactory;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.util.StringUtils;
@@ -31,23 +30,24 @@ import org.w3c.dom.Element;
* @author Mark Fisher
* @since 2.0
*/
public class MBeanExporterParser extends AbstractBeanDefinitionParser {
public class MBeanExporterParser extends AbstractSingleBeanDefinitionParser {
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
protected String getBeanClassName(Element element) {
return "org.springframework.integration.monitor.IntegrationMBeanExporter";
}
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
Object mbeanServer = getMBeanServer(element, parserContext);
BeanDefinitionBuilder builder = BeanDefinitionBuilder
.genericBeanDefinition("org.springframework.integration.monitor.IntegrationMBeanExporter");
builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "domain");
builder.addPropertyValue("server", mbeanServer);
if (StringUtils.hasText(element.getAttribute("operation-channel"))) {
AbstractBeanDefinition controlBus = getControlBus(element, parserContext, mbeanServer, builder
.getRawBeanDefinition());
parserContext.getRegistry().registerBeanDefinition(
parserContext.getReaderContext().generateBeanName(controlBus), controlBus);
}
return builder.getBeanDefinition();
}
private Object getMBeanServer(Element element, ParserContext parserContext) {
@@ -60,15 +60,4 @@ public class MBeanExporterParser extends AbstractBeanDefinitionParser {
}
}
private AbstractBeanDefinition getControlBus(Element element, ParserContext parserContext, Object mbeanServer,
Object mbeanExporter) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder
.genericBeanDefinition("org.springframework.integration.control.ControlBus");
builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
builder.addConstructorArgValue(mbeanExporter);
builder.addConstructorArgValue(mbeanServer);
builder.addConstructorArgReference(element.getAttribute("operation-channel"));
return builder.getBeanDefinition();
}
}

View File

@@ -30,6 +30,11 @@ import org.springframework.util.StringUtils;
*/
public class NotificationListeningChannelAdapterParser extends AbstractSimpleBeanDefinitionParser {
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected String getBeanClassName(Element element) {
return "org.springframework.integration.jmx.NotificationListeningMessageProducer";

View File

@@ -30,6 +30,11 @@ import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
*/
public class NotificationPublishingChannelAdapterParser extends AbstractOutboundChannelAdapterParser {
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(

View File

@@ -30,6 +30,11 @@ import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
*/
public class OperationInvokingChannelAdapterParser extends AbstractOutboundChannelAdapterParser {
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(

View File

@@ -25,7 +25,7 @@ import org.w3c.dom.Element;
* @author Oleg Zhurakousky
* @since 2.0
*/
public class OperationInvokingOutboundGatewayParser extends AbstractConsumerEndpointParser{
public class OperationInvokingOutboundGatewayParser extends AbstractConsumerEndpointParser {
@Override
protected String getInputChannelAttributeName() {