Removed the registerHandler() method from MessageBus.

This commit is contained in:
Mark Fisher
2008-08-13 01:16:32 +00:00
parent f56334f06b
commit 5c9ac92f6b
8 changed files with 68 additions and 52 deletions

View File

@@ -46,13 +46,10 @@ import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.factory.ChannelFactory;
import org.springframework.integration.channel.factory.QueueChannelFactory;
import org.springframework.integration.dispatcher.PollingDispatcher;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.endpoint.DefaultEndpointRegistry;
import org.springframework.integration.endpoint.EndpointRegistry;
import org.springframework.integration.endpoint.HandlerEndpoint;
import org.springframework.integration.endpoint.MessageEndpoint;
import org.springframework.integration.endpoint.MessagingGateway;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.integration.message.MessageSource;
import org.springframework.integration.message.MessageTarget;
import org.springframework.integration.message.PollableSource;
@@ -258,27 +255,6 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
return this.channelRegistry.unregisterChannel(name);
}
public void registerHandler(String name, MessageHandler handler, Object input, Schedule schedule) {
Assert.notNull(handler, "'handler' must not be null");
HandlerEndpoint endpoint = new HandlerEndpoint(handler);
this.configureEndpoint(endpoint, name, input, schedule);
this.registerEndpoint(endpoint);
}
private void configureEndpoint(AbstractEndpoint endpoint, String name, Object input, Schedule schedule) {
endpoint.setName(name);
if (input instanceof MessageChannel) {
endpoint.setSource((MessageChannel) input);
}
else if (input instanceof String) {
endpoint.setInputChannelName((String) input);
}
else {
throw new ConfigurationException("'input' must be a MessageChannel or String");
}
endpoint.setSchedule(schedule);
}
public void registerEndpoint(MessageEndpoint endpoint) {
if (!this.initialized) {
this.initialize();

View File

@@ -22,8 +22,6 @@ import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.factory.ChannelFactory;
import org.springframework.integration.endpoint.EndpointRegistry;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.integration.scheduling.Schedule;
/**
* The message bus interface.
@@ -36,6 +34,4 @@ public interface MessageBus extends ChannelRegistry, EndpointRegistry, Lifecycle
ChannelFactory getChannelFactory();
void registerHandler(String name, MessageHandler handler, Object input, Schedule schedule);
}

View File

@@ -28,7 +28,8 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.annotation.Subscriber;
import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.handler.DefaultMessageHandlerAdapter;
import org.springframework.integration.endpoint.SimpleEndpoint;
import org.springframework.integration.handler.DefaultMessageHandler;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
@@ -85,13 +86,16 @@ public class SubscriberAnnotationPostProcessor implements BeanPostProcessor {
Annotation annotation = method.getAnnotation(subscriberAnnotationType);
if (annotation != null) {
String channelName = (String) AnnotationUtils.getValue(annotation, channelNameAttribute);
DefaultMessageHandlerAdapter adapter = new DefaultMessageHandlerAdapter();
adapter.setMethodName(method.getName());
adapter.setObject(bean);
adapter.afterPropertiesSet();
String adapterName = ClassUtils.getShortNameAsProperty(targetClass) +
"-" + method.getName() + "-endpoint";
messageBus.registerHandler(adapterName, adapter, channelName, null);
DefaultMessageHandler handler = new DefaultMessageHandler();
handler.setObject(bean);
handler.setMethod(method);
handler.afterPropertiesSet();
String endpointName = ClassUtils.getShortNameAsProperty(targetClass) +
"." + method.getName() + ".endpoint";
SimpleEndpoint<DefaultMessageHandler> endpoint = new SimpleEndpoint<DefaultMessageHandler>(handler);
endpoint.setBeanName(endpointName);
endpoint.setInputChannelName(channelName);
messageBus.registerEndpoint(endpoint);
}
}
});

View File

@@ -38,6 +38,7 @@ public class DefaultEndpointRegistry implements EndpointRegistry {
public void registerEndpoint(MessageEndpoint endpoint) {
Assert.notNull(endpoint, "'endpoint' must not be null");
Assert.notNull(endpoint.getName(), "endpoint name must not be null");
this.endpoints.put(endpoint.getName(), endpoint);
}