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