INT-1416: replace control-bus with mbean-exporter
This commit is contained in:
@@ -25,7 +25,6 @@ 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.channel.DirectChannel;
|
||||
import org.springframework.integration.core.SubscribableChannel;
|
||||
import org.springframework.integration.jmx.JmxHeaders;
|
||||
import org.springframework.integration.jmx.OperationInvokingMessageHandler;
|
||||
@@ -43,7 +42,7 @@ public class ControlBus implements BeanFactoryAware, InitializingBean {
|
||||
|
||||
public static final String TARGET_BEAN_NAME = JmxHeaders.PREFIX + "_controlBus_targetBeanName";
|
||||
|
||||
private volatile SubscribableChannel operationChannel;
|
||||
private final SubscribableChannel operationChannel;
|
||||
|
||||
private volatile ListableBeanFactory beanFactory;
|
||||
|
||||
@@ -51,16 +50,12 @@ public class ControlBus implements BeanFactoryAware, InitializingBean {
|
||||
|
||||
private final MBeanServer server;
|
||||
|
||||
|
||||
/**
|
||||
* Create a {@link ControlBus}.
|
||||
*/
|
||||
public ControlBus(ObjectNameLocator locator, MBeanServer server) {
|
||||
public ControlBus(ObjectNameLocator locator, MBeanServer server, SubscribableChannel operationChannel) {
|
||||
this.exporter = locator;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public void setOperationChannel(SubscribableChannel operationChannel) {
|
||||
this.operationChannel = operationChannel;
|
||||
}
|
||||
|
||||
@@ -78,16 +73,12 @@ public class ControlBus implements BeanFactoryAware, InitializingBean {
|
||||
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();
|
||||
if (this.operationChannel == null) {
|
||||
this.operationChannel = new DirectChannel();
|
||||
}
|
||||
this.operationChannel.subscribe(handler);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,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());
|
||||
this.registerBeanDefinitionParser("mbean-exporter", new MBeanExporterParser());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ package org.springframework.integration.jmx.config;
|
||||
|
||||
import javax.management.MBeanServerFactory;
|
||||
|
||||
import org.springframework.beans.BeanMetadataElement;
|
||||
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.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -31,20 +31,23 @@ import org.w3c.dom.Element;
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ControlBusParser extends AbstractSimpleBeanDefinitionParser {
|
||||
public class MBeanExporterParser extends AbstractBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
return "org.springframework.integration.control.ControlBus";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
|
||||
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
||||
Object mbeanServer = getMBeanServer(element, parserContext);
|
||||
builder.addConstructorArgValue(getMBeanExporter(element, parserContext, mbeanServer));
|
||||
builder.addConstructorArgValue(mbeanServer);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "operation-channel");
|
||||
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) {
|
||||
@@ -57,12 +60,14 @@ public class ControlBusParser extends AbstractSimpleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
private BeanMetadataElement getMBeanExporter(Element element, ParserContext parserContext, Object mbeanServer) {
|
||||
private AbstractBeanDefinition getControlBus(Element element, ParserContext parserContext, Object mbeanServer,
|
||||
Object mbeanExporter) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition("org.springframework.integration.monitor.IntegrationMBeanExporter");
|
||||
.genericBeanDefinition("org.springframework.integration.control.ControlBus");
|
||||
builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "domain");
|
||||
builder.addPropertyValue("server", mbeanServer);
|
||||
builder.addConstructorArgValue(mbeanExporter);
|
||||
builder.addConstructorArgValue(mbeanServer);
|
||||
builder.addConstructorArgReference(element.getAttribute("operation-channel"));
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user