INT-1817 added namespace support for object-name-static-properties for IntegrationMBeanExporter

This commit is contained in:
Oleg Zhurakousky
2011-03-09 17:13:13 -05:00
parent 3f06998118
commit 8b53fa1fc7
5 changed files with 47 additions and 12 deletions

View File

@@ -52,6 +52,8 @@ public class MBeanExporterParser extends AbstractSingleBeanDefinitionParser {
Object mbeanServer = getMBeanServer(element, parserContext);
builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "default-domain");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "object-name-static-properties-ref", "objectNameStaticProperties");
builder.addPropertyValue("server", mbeanServer);
}

View File

@@ -17,6 +17,7 @@ import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantLock;
@@ -29,6 +30,7 @@ import javax.management.modelmbean.ModelMBean;
import org.aopalliance.aop.Advice;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.Advisor;
import org.springframework.aop.PointcutAdvisor;
import org.springframework.aop.TargetSource;
@@ -132,7 +134,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
private boolean initialized = false;
private final Map<String, String> objectNameStaticProperties = new HashMap<String, String>();
private final Properties objectNameStaticProperties = new Properties();
private final MetadataMBeanInfoAssembler assembler = new MetadataMBeanInfoAssembler(attributeSource);
@@ -617,7 +619,8 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
return "";
}
StringBuilder builder = new StringBuilder();
for (String key : objectNameStaticProperties.keySet()) {
for (Object key : objectNameStaticProperties.keySet()) {
builder.append("," + key + "=" + objectNameStaticProperties.get(key));
}
return builder.toString();

View File

@@ -112,6 +112,18 @@
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="object-name-static-properties-ref" use="optional">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="java.util.Properties" />
</tool:annotation>
</xsd:appinfo>
<xsd:documentation>
Static object properties to be used for this domain.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

View File

@@ -4,19 +4,25 @@
xmlns:context="http://www.springframework.org/schema/context"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jmx
http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd">
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jmx http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:mbean-server id="mbs"/>
<si:channel id="testChannel"/>
<jmx:mbean-export id="integratioMbeanExporter" server="mbs" default-domain="tests.MBeanExpoerterParser"/>
<jmx:mbean-export id="integratioMbeanExporter"
server="mbs"
default-domain="tests.MBeanExpoerterParser"
object-name-static-properties-ref="appProperties"/>
<util:properties id="appProperties">
<prop key="foo">foo</prop>
<prop key="bar">bar</prop>
</util:properties>
</beans>

View File

@@ -16,20 +16,27 @@
package org.springframework.integration.jmx.config;
import static org.junit.Assert.assertEquals;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import java.util.Properties;
import javax.management.MBeanServer;
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.monitor.IntegrationMBeanExporter;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
* @since 2.0
*/
@ContextConfiguration
@@ -43,6 +50,11 @@ public class MBeanExporterParserTests {
public void testMBeanExporterExists() throws InterruptedException {
IntegrationMBeanExporter exporter = this.context.getBean(IntegrationMBeanExporter.class);
MBeanServer server = this.context.getBean("mbs", MBeanServer.class);
Properties properties = TestUtils.getPropertyValue(exporter, "objectNameStaticProperties", Properties.class);
assertNotNull(properties);
assertEquals(2, properties.size());
assertTrue(properties.containsKey("foo"));
assertTrue(properties.containsKey("bar"));
assertEquals(server, exporter.getServer());
exporter.destroy();
}