1 /* 2 * Copyright 2002-2013 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.messaging; 18 19 /** 20 * Defines methods for sending messages. 21 * 22 * @author Mark Fisher 23 * @since 4.0 24 */ 25 public interface MessageChannel { 26 27 /** 28 * Constant for sending a message without a prescribed timeout. 29 */ 30 public static final long INDEFINITE_TIMEOUT = -1; 31 32 33 /** 34 * Send a {@link Message} to this channel. If the message is sent successfully, 35 * the method returns {@code true}. If the message cannot be sent due to a 36 * non-fatal reason, the method returns {@code false}. The method may also 37 * throw a RuntimeException in case of non-recoverable errors. 38 * <p>This method may block indefinitely, depending on the implementation. 39 * To provide a maximum wait time, use {@link #send(Message, long)}. 40 * @param message the message to send 41 * @return whether or not the message was sent 42 */ 43 boolean send(Message<?> message); 44 45 /** 46 * Send a message, blocking until either the message is accepted or the 47 * specified timeout period elapses. 48 * @param message the message to send 49 * @param timeout the timeout in milliseconds or {@link #INDEFINITE_TIMEOUT} 50 * @return {@code true} if the message is sent, {@code false} if not 51 * including a timeout of an interrupt of the send 52 */ 53 boolean send(Message<?> message, long timeout); 54 55 }