From 2b849f6747474df465c452ec1daf11128cfe038c Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 12 Nov 2010 18:00:49 -0500 Subject: [PATCH] removed SimpleMessageMapper, AttributePollingMessageSource now extends AbstractMessageSource --- .../gateway/SimpleMessageMapper.java | 58 ------------------- .../jmx/AttributePollingMessageSource.java | 17 ++---- 2 files changed, 6 insertions(+), 69 deletions(-) delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessageMapper.java diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessageMapper.java deleted file mode 100644 index 18558b4b06..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessageMapper.java +++ /dev/null @@ -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, OutboundMessageMapper { - - /** - * 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(); - } - -} diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/AttributePollingMessageSource.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/AttributePollingMessageSource.java index d44181a388..536e8cf09c 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/AttributePollingMessageSource.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/AttributePollingMessageSource.java @@ -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 { private volatile ObjectName objectName; @@ -44,8 +42,6 @@ public class AttributePollingMessageSource implements MessageSource { private volatile MBeanServer server; - private volatile InboundMessageMapper 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 '"