001/* 002 * Copyright 2002-2015 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.handler; 018 019import org.springframework.messaging.Message; 020 021/** 022 * Contract for mapping conditions to messages. 023 * 024 * <p>Message conditions can be combined (e.g. type + method-level conditions), 025 * matched to a specific Message, as well as compared to each other in the 026 * context of a Message to determine which one matches a request more closely. 027 * 028 * @author Rossen Stoyanchev 029 * @since 4.0 030 * @param <T> the kind of condition that this condition can be combined with or compared to 031 */ 032public interface MessageCondition<T> { 033 034 /** 035 * Define the rules for combining this condition with another. 036 * For example combining type- and method-level conditions. 037 * @param other the condition to combine with 038 * @return the resulting message condition 039 */ 040 T combine(T other); 041 042 /** 043 * Check if this condition matches the given Message and returns a 044 * potentially new condition with content tailored to the current message. 045 * For example a condition with destination patterns might return a new 046 * condition with sorted, matching patterns only. 047 * @return a condition instance in case of a match; or {@code null} if there is no match. 048 */ 049 T getMatchingCondition(Message<?> message); 050 051 /** 052 * Compare this condition to another in the context of a specific message. 053 * It is assumed both instances have been obtained via 054 * {@link #getMatchingCondition(Message)} to ensure they have content 055 * relevant to current message only. 056 */ 057 int compareTo(T other, Message<?> message); 058 059}