INT-2487 Object Name Patterns for Notifications
Permit the specification of an ObjectName pattern in NotificationListeningMessageProducer. Permit a collection of ObjectNames (patterns). INT-2487 Polishing Use varargs and a SpEL Reference instead of 2 setters. Log an error if no MBeans matching pattern(s). INT-2487 Polishing: PR Review Comments Add patterns to ERROR log when no MBean(s) found. Add doc to schema and reference.
This commit is contained in:
committed by
Oleg Zhurakousky
parent
3d26bd1a5f
commit
d28fefc884
@@ -4,14 +4,12 @@
|
||||
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.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<context:mbean-export/>
|
||||
<context:mbean-server/>
|
||||
@@ -26,9 +24,32 @@
|
||||
|
||||
<bean id="testPublisher" class="org.springframework.integration.jmx.config.TestPublisher"/>
|
||||
|
||||
<bean id="testPublisher2" class="org.springframework.integration.jmx.config.TestPublisher"/>
|
||||
|
||||
<jmx:notification-listening-channel-adapter id="autoChannel"
|
||||
object-name="org.springframework.integration.jmx.config:type=TestPublisher,name=testPublisher"/>
|
||||
|
||||
<si:bridge input-channel="autoChannel" output-channel="nullChannel" />
|
||||
|
||||
<si:channel id="patternChannel">
|
||||
<si:queue/>
|
||||
</si:channel>
|
||||
|
||||
<jmx:notification-listening-channel-adapter id="patternAdapter"
|
||||
channel="patternChannel"
|
||||
object-name="org.springframework.integration.jmx.config:type=*,name=testPublisher"/>
|
||||
|
||||
<si:channel id="multiChannel">
|
||||
<si:queue/>
|
||||
</si:channel>
|
||||
|
||||
<jmx:notification-listening-channel-adapter id="multiAdapter"
|
||||
channel="multiChannel"
|
||||
object-name="#{patterns}"/>
|
||||
|
||||
<util:list id="patterns">
|
||||
<value>org.springframework.integration.jmx.config:type=*,name=testPublisher</value>
|
||||
<value>org.springframework.integration.jmx.config:type=*,name=testPub*</value>
|
||||
</util:list>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.management.Notification;
|
||||
|
||||
@@ -37,6 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@@ -46,9 +48,18 @@ public class NotificationListeningChannelAdapterParserTests {
|
||||
@Autowired
|
||||
private PollableChannel channel;
|
||||
|
||||
@Autowired
|
||||
private PollableChannel patternChannel;
|
||||
|
||||
@Autowired
|
||||
private PollableChannel multiChannel;
|
||||
|
||||
@Autowired
|
||||
private TestPublisher testPublisher;
|
||||
|
||||
@Autowired
|
||||
private TestPublisher testPublisher2;
|
||||
|
||||
@Autowired
|
||||
private MessageChannel autoChannel;
|
||||
|
||||
@@ -59,10 +70,26 @@ public class NotificationListeningChannelAdapterParserTests {
|
||||
public void receiveNotification() throws Exception {
|
||||
assertNull(channel.receive(0));
|
||||
testPublisher.send("ABC");
|
||||
verifyReceipt(channel, "testPublisher");
|
||||
verifyReceipt(patternChannel, "testPublisher");
|
||||
// multiChannel should see 2 copies
|
||||
verifyReceipt(multiChannel, "testPublisher");
|
||||
verifyReceipt(multiChannel, "testPublisher");
|
||||
|
||||
testPublisher2.send("ABC");
|
||||
assertNull(channel.receive(0));
|
||||
assertNull(patternChannel.receive(0));
|
||||
// multiChannel should see only 1 copy
|
||||
verifyReceipt(multiChannel, "testPublisher2");
|
||||
assertNull(multiChannel.receive(0));
|
||||
}
|
||||
|
||||
private void verifyReceipt(PollableChannel channel, String beanName) {
|
||||
Message<?> message = channel.receive(1000);
|
||||
assertNotNull(message);
|
||||
assertEquals(Notification.class, message.getPayload().getClass());
|
||||
assertEquals("ABC", ((Notification) message.getPayload()).getMessage());
|
||||
assertTrue(((String) ((Notification) message.getPayload()).getSource()).endsWith(beanName));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.jmx.config;
|
||||
|
||||
import javax.management.Notification;
|
||||
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.jmx.export.notification.NotificationPublisher;
|
||||
import org.springframework.jmx.export.notification.NotificationPublisherAware;
|
||||
@@ -27,17 +28,22 @@ import org.springframework.jmx.export.notification.NotificationPublisherAware;
|
||||
* @since 2.0
|
||||
*/
|
||||
@ManagedResource
|
||||
public class TestPublisher implements NotificationPublisherAware {
|
||||
public class TestPublisher implements NotificationPublisherAware, BeanNameAware {
|
||||
|
||||
private volatile NotificationPublisher notificationPublisher;
|
||||
|
||||
private String beanName;
|
||||
|
||||
public void setNotificationPublisher(NotificationPublisher notificationPublisher) {
|
||||
this.notificationPublisher = notificationPublisher;
|
||||
}
|
||||
|
||||
public void setBeanName(String name) {
|
||||
this.beanName = name;
|
||||
}
|
||||
public void send(String s) {
|
||||
Notification notification = new Notification("test.type",
|
||||
"org.springframework.integration.jmx.config:type=TestPublisher,name=testPublisher", 1, s);
|
||||
"org.springframework.integration.jmx.config:type=TestPublisher,name=" + this.beanName, 1, s);
|
||||
this.notificationPublisher.sendNotification(notification);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user