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.interceptor;
018
019import org.apache.camel.Exchange;
020import org.apache.camel.Processor;
021import org.apache.camel.model.ProcessorDefinition;
022
023/**
024 * A handler which reacts on trace events.
025 */
026public interface TraceEventHandler {
027
028    /**
029     * Event called when an {@link Exchange} is about to be processed
030     * <p/>
031     * This event is only called if trace out has been disabled (which it is by default).
032     * <p/>
033     * This method is for coarse grained tracing, where as the the other two methods is for fine grained
034     * with in and event events.
035     *
036     * @param node             the current node
037     * @param target           the current processor being invoked
038     * @param traceInterceptor the trace interceptor
039     * @param exchange         the current exchange
040     * @throws Exception is thrown if an error occurred during tracing
041     */
042    void traceExchange(ProcessorDefinition<?> node, Processor target, TraceInterceptor traceInterceptor, Exchange exchange) throws Exception;
043
044    /**
045     * Event called when an {@link Exchange} is about to be processed (in)
046     * <p/>
047     * This event is only called if trace out has been enabled.
048     *
049     * @param node             the current node
050     * @param target           the current processor being invoked
051     * @param traceInterceptor the trace interceptor
052     * @param exchange         the current exchange
053     * @return an optional return object to pass in the <tt>traceEventOut</tt> method.
054     * @throws Exception is thrown if an error occurred during tracing
055     */
056    Object traceExchangeIn(ProcessorDefinition<?> node, Processor target, TraceInterceptor traceInterceptor, Exchange exchange) throws Exception;
057
058    /**
059     * Event called when an {@link Exchange} has been processed (out)
060     * <p/>
061     * This event is only called if trace out has been enabled.
062     *
063     * @param node             the current node
064     * @param target           the current processor being invoked
065     * @param traceInterceptor the trace interceptor
066     * @param exchange         the current exchange (contains exception if the processing failed with an exception)
067     * @param traceState       the optional object which was returned from the <tt>traceEventIn</tt> method.
068     * @throws Exception is thrown if an error occurred during tracing
069     */
070    void traceExchangeOut(ProcessorDefinition<?> node, Processor target, TraceInterceptor traceInterceptor, Exchange exchange, Object traceState) throws Exception;
071
072}