001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.processor;
018
019import org.apache.camel.Exchange;
020
021/**
022 * An advice (before and after) to execute cross cutting functionality in the Camel routing engine.
023 * <p/>
024 * The Camel routing engine will execute the {@link #before(org.apache.camel.Exchange)} and
025 * {@link #after(org.apache.camel.Exchange, Object)} methods during routing in correct order.
026 *
027 * @param <T>
028 * @see CamelInternalProcessor
029 */
030public interface CamelInternalProcessorAdvice<T> {
031
032    /**
033     * Callback executed before processing a step in the route.
034     *
035     * @param exchange  the current exchange
036     * @return any state to keep and provide as data to the {@link #after(org.apache.camel.Exchange, Object)} method, or use <tt>null</tt> for no state.
037     * @throws Exception is thrown if error during the call.
038     */
039    T before(Exchange exchange) throws Exception;
040
041    /**
042     * Callback executed after processing a step in the route.
043     *
044     * @param exchange  the current exchange
045     * @param data      the state, if any, returned in the {@link #before(org.apache.camel.Exchange)} method.
046     * @throws Exception is thrown if error during the call.
047     */
048    void after(Exchange exchange, T data) throws Exception;
049}