Removed the @ChannelAdapter annotation. The inbound version is no longer viable with @Poller removed (so that the polling configuration would be properly externalized - see previous commit log entries). But, the <inbound-channel-adapter/> element is trivial anyways. As far as outbound, the @ServiceActivator can be used for a method with void-return, so that was redundant actually. One consistent way to perform the job should be sufficient.

This commit is contained in:
Mark Fisher
2008-11-25 20:23:40 +00:00
parent c1741edf83
commit c16c3abb30
3 changed files with 0 additions and 145 deletions

View File

@@ -1,51 +0,0 @@
/*
* 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.
*/
package org.springframework.integration.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.stereotype.Component;
/**
* Indicates that a method is capable of serving as a message channel.
* If the method accepts no arguments but does define a non-void return
* type, an inbound Channel Adapter will be created. If the method does
* accept an argument and has a void return, an outbound Channel Adapter
* will be created. If the method does not conform to either contract,
* an Exception will be thrown.
*
* @author Mark Fisher
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@Component
public @interface ChannelAdapter {
/**
* The name of the channel being adapted. If the channel
* name is not resolvable, a new channel will be created.
*/
String value();
}

View File

@@ -1,89 +0,0 @@
/*
* 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.
*/
package org.springframework.integration.config.annotation;
import java.lang.reflect.Method;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.integration.annotation.ChannelAdapter;
import org.springframework.integration.channel.BeanFactoryChannelResolver;
import org.springframework.integration.channel.ChannelResolutionException;
import org.springframework.integration.channel.ChannelResolver;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.SubscribableChannel;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.handler.MethodInvokingMessageHandler;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* Post-processor for methods annotated with {@link ChannelAdapter @ChannelAdapter}.
*
* @author Mark Fisher
*/
public class ChannelAdapterAnnotationPostProcessor implements MethodAnnotationPostProcessor<ChannelAdapter> {
private final ConfigurableBeanFactory beanFactory;
private final ChannelResolver channelResolver;
public ChannelAdapterAnnotationPostProcessor(ConfigurableBeanFactory beanFactory) {
Assert.notNull(beanFactory, "BeanFactory must not be null");
this.beanFactory = beanFactory;
this.channelResolver = new BeanFactoryChannelResolver(this.beanFactory);
}
public Object postProcess(Object bean, String beanName, Method method, ChannelAdapter annotation) {
Assert.notNull(this.beanFactory, "BeanFactory must not be null");
MessageChannel channel = this.resolveOrCreateChannel(annotation.value());
Assert.isInstanceOf(SubscribableChannel.class, channel,
"The channel for an Annotation-based Channel Adapter must be a SubscribableChannel.");
Assert.isTrue(method.getParameterTypes().length > 0,
"A method annotated with @ChannelAdapter must accept at least one argument.");
Assert.isTrue(!hasReturnValue(method),
"A method annotated with @ChannelAdapter must not have a return value."
+ " Consider using a @ServiceActivator if a reply Message is expected.");
MethodInvokingMessageHandler handler = new MethodInvokingMessageHandler(bean, method);
EventDrivenConsumer endpoint = new EventDrivenConsumer((SubscribableChannel) channel, handler);
String annotationName = ClassUtils.getShortNameAsProperty(annotation.annotationType());
String endpointName = beanName + "." + method.getName() + "." + annotationName;
this.beanFactory.registerSingleton(endpointName, endpoint);
endpoint.setBeanFactory(beanFactory);
endpoint.afterPropertiesSet();
return bean;
}
private MessageChannel resolveOrCreateChannel(String channelName) {
try {
return this.channelResolver.resolveChannelName(channelName);
}
catch (ChannelResolutionException e) {
DirectChannel directChannel = new DirectChannel();
directChannel.setBeanName(channelName);
this.beanFactory.registerSingleton(channelName, directChannel);
return directChannel;
}
}
private boolean hasReturnValue(Method method) {
return !method.getReturnType().equals(void.class);
}
}

View File

@@ -39,7 +39,6 @@ import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.annotation.Aggregator;
import org.springframework.integration.annotation.ChannelAdapter;
import org.springframework.integration.annotation.Router;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.annotation.Splitter;
@@ -78,7 +77,6 @@ public class MessagingAnnotationPostProcessor implements BeanPostProcessor, Bean
public void afterPropertiesSet() {
Assert.notNull(this.beanFactory, "BeanFactory must not be null");
postProcessors.put(Aggregator.class, new AggregatorAnnotationPostProcessor(this.beanFactory));
postProcessors.put(ChannelAdapter.class, new ChannelAdapterAnnotationPostProcessor(this.beanFactory));
postProcessors.put(Router.class, new RouterAnnotationPostProcessor(this.beanFactory));
postProcessors.put(ServiceActivator.class, new ServiceActivatorAnnotationPostProcessor(this.beanFactory));
postProcessors.put(Splitter.class, new SplitterAnnotationPostProcessor(this.beanFactory));
@@ -133,9 +131,6 @@ public class MessagingAnnotationPostProcessor implements BeanPostProcessor, Bean
}
private boolean shouldCreateEndpoint(Annotation annotation) {
if (annotation instanceof ChannelAdapter) {
return true;
}
Object inputChannel = AnnotationUtils.getValue(annotation, "inputChannel");
return (inputChannel != null && inputChannel instanceof String
&& StringUtils.hasText((String) inputChannel));