diff --git a/spring-eai-core/src/main/java/org/springframework/integration/MessageSource.java b/spring-eai-core/src/main/java/org/springframework/integration/MessageSource.java new file mode 100644 index 0000000000..97b726b354 --- /dev/null +++ b/spring-eai-core/src/main/java/org/springframework/integration/MessageSource.java @@ -0,0 +1,48 @@ +/* + * Copyright 2002-2007 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; + +import org.springframework.integration.message.Message; + +/** + * Base interface for any component that enables message reception. + * + * @author Mark Fisher + */ +public interface MessageSource { + + /** + * Receive a message, blocking indefinitely if necessary. + * + * @return the next available {@link Message} or + * null if interrupted + */ + Message receive(); + + /** + * Receive a message, blocking until either a message is + * available or the specified timeout period elapses. + * + * @param timeout the timeout in milliseconds + * + * @return the next available {@link Message} or + * null if the specified timeout period + * elapses or the message reception is interrupted + */ + Message receive(long timeout); + +} diff --git a/spring-eai-core/src/main/java/org/springframework/integration/MessageTarget.java b/spring-eai-core/src/main/java/org/springframework/integration/MessageTarget.java new file mode 100644 index 0000000000..26c37c876f --- /dev/null +++ b/spring-eai-core/src/main/java/org/springframework/integration/MessageTarget.java @@ -0,0 +1,51 @@ +/* + * Copyright 2002-2007 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; + +import org.springframework.integration.message.Message; + +/** + * Base interface for any component that enables message sending. + * + * @author Mark Fisher + */ +public interface MessageTarget { + + /** + * Send a message, blocking indefinitely if necessary. + * + * @param message the {@link Message} to send + * + * @return true if the message is sent + * successfully, false if interrupted + */ + boolean send(Message message); + + /** + * Send a message, blocking until either the message is + * accepted or the specified timeout period elapses. + * + * @param message the {@link Message} to send + * @param timeout the timeout in milliseconds + * + * @return true if the message is sent + * successfully, false if the specified + * timeout period elapses or the send is interrupted + */ + boolean send(Message message, long timeout); + +} diff --git a/spring-eai-core/src/main/java/org/springframework/integration/channel/MessageChannel.java b/spring-eai-core/src/main/java/org/springframework/integration/channel/MessageChannel.java index b8b6af7f40..c7d284b7c3 100644 --- a/spring-eai-core/src/main/java/org/springframework/integration/channel/MessageChannel.java +++ b/spring-eai-core/src/main/java/org/springframework/integration/channel/MessageChannel.java @@ -16,22 +16,17 @@ package org.springframework.integration.channel; -import org.springframework.integration.message.Message; +import org.springframework.integration.MessageSource; +import org.springframework.integration.MessageTarget; /** - * Base channel interface defining the common behavior - * of sending and receiving messages. + * Base channel interface to combine the definitions of {@link MessageSource} + * for message reception and and {@link MessageTarget} for message sending. * * @author Mark Fisher + * @see MessageSource + * @see MessageTarget */ -public interface MessageChannel { - - boolean send(Message message); - - boolean send(Message message, long timeout); - - Message receive(); - - Message receive(long timeout); +public interface MessageChannel extends MessageSource, MessageTarget { }