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 */
017 package org.apache.camel;
018
019 import java.util.List;
020
021 import org.apache.camel.model.ProcessorDefinition;
022 import org.apache.camel.spi.InterceptStrategy;
023 import org.apache.camel.spi.RouteContext;
024
025 /**
026 * Channel acts as a channel between {@link Processor}s in the route graph.
027 * <p/>
028 * The channel is responsible for routing the {@link Exchange} to the next {@link Processor} in the route graph.
029 *
030 * @version
031 */
032 public interface Channel extends AsyncProcessor, Navigate<Processor> {
033
034 /**
035 * Sets the processor that the channel should route the {@link Exchange} to.
036 *
037 * @param next the next processor
038 */
039 void setNextProcessor(Processor next);
040
041 /**
042 * Sets the {@link org.apache.camel.processor.ErrorHandler} this Channel uses.
043 *
044 * @param errorHandler the error handler
045 */
046 void setErrorHandler(Processor errorHandler);
047
048 /**
049 * Gets the {@link org.apache.camel.processor.ErrorHandler} this Channel uses.
050 *
051 * @return the error handler, or <tt>null</tt> if no error handler is used.
052 */
053 Processor getErrorHandler();
054
055 /**
056 * Adds a {@link org.apache.camel.spi.InterceptStrategy} to apply each {@link Exchange} before
057 * its routed to the next {@link Processor}.
058 *
059 * @param strategy the intercept strategy
060 */
061 void addInterceptStrategy(InterceptStrategy strategy);
062
063 /**
064 * Adds a list of {@link org.apache.camel.spi.InterceptStrategy} to apply each {@link Exchange} before
065 * its routed to the next {@link Processor}.
066 *
067 * @param strategy list of strategies
068 */
069 void addInterceptStrategies(List<InterceptStrategy> strategy);
070
071 /**
072 * Gets the list of {@link org.apache.camel.spi.InterceptStrategy} registered to this Channel.
073 *
074 * @return list of strategies, returns an empty list if no strategies is registered.
075 */
076 List<InterceptStrategy> getInterceptStrategies();
077
078 /**
079 * Initializes the channel.
080 *
081 * @param outputDefinition the route definition the {@link Channel} represents
082 * @param routeContext the route context
083 * @throws Exception is thrown if some error occurred
084 */
085 void initChannel(ProcessorDefinition<?> outputDefinition, RouteContext routeContext) throws Exception;
086
087 /**
088 * If the initialized output definition contained outputs (children) then we need to
089 * set the child so we can leverage fine grained tracing
090 *
091 * @param child the child
092 */
093 void setChildDefinition(ProcessorDefinition<?> child);
094
095 /**
096 * Gets the wrapped output that at runtime should be delegated to.
097 *
098 * @return the output to route the {@link Exchange} to
099 */
100 Processor getOutput();
101
102 /**
103 * Sets the wrapped output that at runtime should be delegated to.
104 *
105 * @param output the output to route the {@link Exchange} to
106 */
107 void setOutput(Processor output);
108
109 /**
110 * Gets the next {@link Processor} to route to (not wrapped)
111 *
112 * @return the next processor
113 */
114 Processor getNextProcessor();
115
116 /**
117 * Gets the definition of the next processor
118 *
119 * @return the processor definition
120 */
121 ProcessorDefinition<?> getProcessorDefinition();
122
123 /**
124 * Gets the {@link RouteContext}
125 *
126 * @return the route context
127 */
128 RouteContext getRouteContext();
129 }