INT-1507: remove control bus from JMX XSD

This commit is contained in:
Dave Syer
2010-10-25 10:58:20 -07:00
parent 53dd793819
commit 473b8fa96d
13 changed files with 37 additions and 725 deletions

View File

@@ -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);
}
}
}

View File

@@ -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<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

@@ -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"));
}
}
}

View File

@@ -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());
}
}