INT-1628: expose WireTap via @ManagedResource
This commit is contained in:
@@ -18,12 +18,14 @@ package org.springframework.integration.channel.interceptor;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.channel.ChannelInterceptor;
|
||||
import org.springframework.integration.core.MessageSelector;
|
||||
import org.springframework.jmx.export.annotation.ManagedAttribute;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -32,6 +34,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@ManagedResource
|
||||
public class WireTap extends ChannelInterceptorAdapter implements Lifecycle {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(WireTap.class);
|
||||
@@ -80,6 +83,7 @@ public class WireTap extends ChannelInterceptorAdapter implements Lifecycle {
|
||||
/**
|
||||
* Check whether the wire tap is currently running.
|
||||
*/
|
||||
@ManagedAttribute
|
||||
public boolean isRunning() {
|
||||
return this.running;
|
||||
}
|
||||
@@ -87,6 +91,7 @@ public class WireTap extends ChannelInterceptorAdapter implements Lifecycle {
|
||||
/**
|
||||
* Restart the wire tap if it has been stopped. It is running by default.
|
||||
*/
|
||||
@ManagedOperation
|
||||
public void start() {
|
||||
this.running = true;
|
||||
}
|
||||
@@ -94,6 +99,7 @@ public class WireTap extends ChannelInterceptorAdapter implements Lifecycle {
|
||||
/**
|
||||
* Stop the wire tap. To restart, invoke {@link #start()}.
|
||||
*/
|
||||
@ManagedOperation
|
||||
public void stop() {
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.config.xml;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
@@ -31,8 +29,8 @@ import org.springframework.util.StringUtils;
|
||||
public class WireTapParser implements BeanDefinitionRegisteringParser {
|
||||
|
||||
public String parse(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".channel.interceptor.WireTap");
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE + ".channel.interceptor.WireTap");
|
||||
String targetRef = element.getAttribute("channel");
|
||||
if (!StringUtils.hasText(targetRef)) {
|
||||
parserContext.getReaderContext().error("The 'channel' attribute is required.", element);
|
||||
@@ -46,8 +44,14 @@ public class WireTapParser implements BeanDefinitionRegisteringParser {
|
||||
if (StringUtils.hasText(timeout)) {
|
||||
builder.addPropertyValue("timeout", Long.parseLong(timeout));
|
||||
}
|
||||
return BeanDefinitionReaderUtils.registerWithGeneratedName(
|
||||
builder.getBeanDefinition(), parserContext.getRegistry());
|
||||
String id = element.getAttribute("id");
|
||||
if (StringUtils.hasText(id)) {
|
||||
BeanDefinitionReaderUtils.registerBeanDefinition(new BeanDefinitionHolder(builder.getBeanDefinition(), id),
|
||||
parserContext.getRegistry());
|
||||
return id;
|
||||
}
|
||||
return BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(),
|
||||
parserContext.getRegistry());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2488,6 +2488,7 @@ Name of the header whose value will be used to route messages
|
||||
Defines a Wire Tap Channel Interceptor.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:ID" use="optional" />
|
||||
<xsd:attribute name="channel" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
|
||||
@@ -51,6 +51,14 @@ public class WireTapParserTests {
|
||||
assertEquals(original, intercepted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleWireTapWithId() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"wireTapParserTests.xml", this.getClass());
|
||||
WireTap wireTap = (WireTap) context.getBean("wireTap");
|
||||
assertNotNull(wireTap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wireTapWithAcceptingSelector() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
@@ -98,7 +106,7 @@ public class WireTapParserTests {
|
||||
otherTimeoutCount++;
|
||||
}
|
||||
}
|
||||
assertEquals(3, defaultTimeoutCount);
|
||||
assertEquals(4, defaultTimeoutCount);
|
||||
assertEquals(1, expectedTimeoutCount);
|
||||
assertEquals(0, otherTimeoutCount);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,13 @@
|
||||
</interceptors>
|
||||
</channel>
|
||||
|
||||
<channel id="withId">
|
||||
<queue capacity="10"/>
|
||||
<interceptors>
|
||||
<wire-tap id="wireTap" channel="wireTapChannel"/>
|
||||
</interceptors>
|
||||
</channel>
|
||||
|
||||
<channel id="accepting">
|
||||
<queue capacity="10"/>
|
||||
<interceptors>
|
||||
|
||||
Reference in New Issue
Block a user