001/* 002 * Copyright 2002-2014 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.support; 018 019import org.springframework.messaging.Message; 020import org.springframework.messaging.MessageChannel; 021import org.springframework.messaging.MessageHandler; 022 023/** 024 * An extension of {@link ChannelInterceptor} with callbacks to intercept the 025 * asynchronous sending of a {@link org.springframework.messaging.Message} to 026 * a specific subscriber through an {@link java.util.concurrent.Executor}. 027 * Supported on {@link org.springframework.messaging.MessageChannel} 028 * implementations that can be configured with an Executor. 029 * 030 * @author Rossen Stoyanchev 031 * @since 4.1 032 */ 033public interface ExecutorChannelInterceptor extends ChannelInterceptor { 034 035 /** 036 * Invoked inside the {@link Runnable} submitted to the Executor just before 037 * calling the target MessageHandler to handle the message. Allows for 038 * modification of the Message if necessary or when {@code null} is returned 039 * the MessageHandler is not invoked. 040 * @param message the message to be handled 041 * @param channel the channel on which the message was sent to 042 * @param handler the target handler to handle the message 043 * @return the input message, or a new instance, or {@code null} 044 */ 045 Message<?> beforeHandle(Message<?> message, MessageChannel channel, MessageHandler handler); 046 047 /** 048 * Invoked inside the {@link Runnable} submitted to the Executor after calling 049 * the target MessageHandler regardless of the outcome (i.e. Exception raised 050 * or not) thus allowing for proper resource cleanup. 051 * <p>Note that this will be invoked only if beforeHandle successfully completed 052 * and returned a Message, i.e. it did not return {@code null}. 053 * @param message the message handled 054 * @param channel the channel on which the message was sent to 055 * @param handler the target handler that handled the message 056 * @param ex any exception that may been raised by the handler 057 */ 058 void afterMessageHandled(Message<?> message, MessageChannel channel, MessageHandler handler, Exception ex); 059 060}