diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBus.java b/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBus.java index 7e38993be3..9a66b9ac9d 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBus.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBus.java @@ -51,6 +51,7 @@ 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.endpoint.SourceEndpoint; import org.springframework.integration.endpoint.TargetEndpoint; import org.springframework.integration.handler.MessageHandler; @@ -194,6 +195,15 @@ public class MessageBus implements ChannelRegistry, EndpointRegistry, Applicatio } } + @SuppressWarnings("unchecked") + private void registerGateways(ApplicationContext context) { + Map gatewayBeans = + (Map) context.getBeansOfType(MessagingGateway.class); + for (Map.Entry entry : gatewayBeans.entrySet()) { + this.registerGateway(entry.getKey(), entry.getValue()); + } + } + public void initialize() { synchronized (this.lifecycleMonitor) { if (this.initialized || this.initializing) { @@ -416,6 +426,18 @@ public class MessageBus implements ChannelRegistry, EndpointRegistry, Applicatio } } + private void registerGateway(String name, MessagingGateway gateway) { + if (gateway instanceof Lifecycle) { + this.lifecycleEndpoints.add((Lifecycle) gateway); + if (this.isRunning()) { + ((Lifecycle) gateway).start(); + } + } + if (logger.isInfoEnabled()) { + logger.info("registered gateway '" + name + "'"); + } + } + private void activateSubscription(MessageChannel channel, Target target, Schedule schedule) { SubscriptionManager manager = this.subscriptionManagers.get(channel); if (manager == null) { @@ -496,6 +518,7 @@ public class MessageBus implements ChannelRegistry, EndpointRegistry, Applicatio if (event instanceof ContextRefreshedEvent) { ApplicationContext context = ((ContextRefreshedEvent) event).getApplicationContext(); this.registerEndpoints(context); + this.registerGateways(context); if (this.configureAsyncEventMulticaster) { this.initialize(); this.doConfigureAsyncEventMulticaster(context); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/MessagingGateway.java b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/MessagingGateway.java new file mode 100644 index 0000000000..216ea96601 --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/MessagingGateway.java @@ -0,0 +1,38 @@ +/* + * 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.endpoint; + +import org.springframework.integration.message.Message; + +/** + * Base interface for gateway adapters. In Spring Integration, a "gateway" is a + * component that sends messages to and receives messages from message channels + * so that application code does not need to be aware of channels or even messages. + * + * @author Mark Fisher + */ +public interface MessagingGateway { + + void send(Object object); + + Object receive(); + + Object sendAndReceive(Object object); + + Message sendAndReceiveMessage(Object object); + +} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java index faadf100fc..38ba78542a 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java @@ -17,6 +17,7 @@ package org.springframework.integration.gateway; import org.springframework.integration.channel.MessageChannel; +import org.springframework.integration.endpoint.MessagingGateway; import org.springframework.integration.message.DefaultMessageCreator; import org.springframework.integration.message.DefaultMessageMapper; import org.springframework.integration.message.Message; @@ -34,7 +35,7 @@ import org.springframework.util.Assert; * * @author Mark Fisher */ -public class SimpleMessagingGateway extends MessagingGatewaySupport { +public class SimpleMessagingGateway extends MessagingGatewaySupport implements MessagingGateway { private MessageCreator messageCreator = new DefaultMessageCreator();