001/* 002 * Copyright 2002-2016 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.messaging; 018 019/** 020 * Defines methods for sending messages. 021 * 022 * @author Mark Fisher 023 * @since 4.0 024 */ 025public interface MessageChannel { 026 027 /** 028 * Constant for sending a message without a prescribed timeout. 029 */ 030 long INDEFINITE_TIMEOUT = -1; 031 032 033 /** 034 * Send a {@link Message} to this channel. If the message is sent successfully, 035 * the method returns {@code true}. If the message cannot be sent due to a 036 * non-fatal reason, the method returns {@code false}. The method may also 037 * throw a RuntimeException in case of non-recoverable errors. 038 * <p>This method may block indefinitely, depending on the implementation. 039 * To provide a maximum wait time, use {@link #send(Message, long)}. 040 * @param message the message to send 041 * @return whether or not the message was sent 042 */ 043 boolean send(Message<?> message); 044 045 /** 046 * Send a message, blocking until either the message is accepted or the 047 * specified timeout period elapses. 048 * @param message the message to send 049 * @param timeout the timeout in milliseconds or {@link #INDEFINITE_TIMEOUT} 050 * @return {@code true} if the message is sent, {@code false} if not 051 * including a timeout of an interrupt of the send 052 */ 053 boolean send(Message<?> message, long timeout); 054 055}