removed SimpleMessageMapper, AttributePollingMessageSource now extends AbstractMessageSource
This commit is contained in:
@@ -1,58 +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.gateway;
|
||||
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.mapping.InboundMessageMapper;
|
||||
import org.springframework.integration.mapping.OutboundMessageMapper;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
|
||||
/**
|
||||
* An implementation of the {@link InboundMessageMapper} and
|
||||
* {@link OutboundMessageMapper} strategy interfaces that maps directly to and
|
||||
* from the Message payload instance.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class SimpleMessageMapper implements InboundMessageMapper<Object>, OutboundMessageMapper<Object> {
|
||||
|
||||
/**
|
||||
* Returns the Message payload (or null if the Message is null).
|
||||
*/
|
||||
public Object fromMessage(Message<?> message) {
|
||||
if (message == null) {
|
||||
return null;
|
||||
}
|
||||
return message.getPayload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Message with the given object as its payload, unless the
|
||||
* object is already a Message in which case it will be returned as-is.
|
||||
* If the object is null, the returned Message will also be null.
|
||||
*/
|
||||
public Message<?> toMessage(Object object) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
if (object instanceof Message<?>) {
|
||||
return (Message<?>) object;
|
||||
}
|
||||
return MessageBuilder.withPayload(object).build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,11 +20,9 @@ import javax.management.MBeanServer;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.core.MessageSource;
|
||||
import org.springframework.integration.gateway.SimpleMessageMapper;
|
||||
import org.springframework.integration.mapping.InboundMessageMapper;
|
||||
import org.springframework.integration.endpoint.AbstractMessageSource;
|
||||
import org.springframework.jmx.support.ObjectNameManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -36,7 +34,7 @@ import org.springframework.util.Assert;
|
||||
* @since 2.0
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class AttributePollingMessageSource implements MessageSource {
|
||||
public class AttributePollingMessageSource extends AbstractMessageSource<Object> {
|
||||
|
||||
private volatile ObjectName objectName;
|
||||
|
||||
@@ -44,8 +42,6 @@ public class AttributePollingMessageSource implements MessageSource {
|
||||
|
||||
private volatile MBeanServer server;
|
||||
|
||||
private volatile InboundMessageMapper<Object> mapper = new SimpleMessageMapper();
|
||||
|
||||
|
||||
/**
|
||||
* Provide the MBeanServer where the JMX MBean has been registered.
|
||||
@@ -74,16 +70,15 @@ public class AttributePollingMessageSource implements MessageSource {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the attribute value and returns it in the
|
||||
* payload of a Message.
|
||||
* Retrieves the JMX attribute value.
|
||||
*/
|
||||
public Message<?> receive() {
|
||||
@Override
|
||||
protected Object doReceive() {
|
||||
Assert.notNull(this.server, "MBeanServer is required");
|
||||
Assert.notNull(this.objectName, "object name is required");
|
||||
Assert.notNull(this.attributeName, "attribute name is required");
|
||||
try {
|
||||
Object value = this.server.getAttribute(this.objectName, this.attributeName);
|
||||
return this.mapper.toMessage(value);
|
||||
return this.server.getAttribute(this.objectName, this.attributeName);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new MessagingException("failed to retrieve JMX attribute '"
|
||||
|
||||
Reference in New Issue
Block a user