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 * Post initializes the channel.
089 *
090 * @param outputDefinition the route definition the {@link Channel} represents
091 * @param routeContext the route context
092 * @throws Exception is thrown if some error occurred
093 */
094 void postInitChannel(ProcessorDefinition<?> outputDefinition, RouteContext routeContext) throws Exception;
095
096 /**
097 * If the initialized output definition contained outputs (children) then we need to
098 * set the child so we can leverage fine grained tracing
099 *
100 * @param child the child
101 */
102 void setChildDefinition(ProcessorDefinition<?> child);
103
104 /**
105 * Gets the wrapped output that at runtime should be delegated to.
106 *
107 * @return the output to route the {@link Exchange} to
108 */
109 Processor getOutput();
110
111 /**
112 * Sets the wrapped output that at runtime should be delegated to.
113 *
114 * @param output the output to route the {@link Exchange} to
115 */
116 void setOutput(Processor output);
117
118 /**
119 * Gets the next {@link Processor} to route to (not wrapped)
120 *
121 * @return the next processor
122 */
123 Processor getNextProcessor();
124
125 /**
126 * Gets the definition of the next processor
127 *
128 * @return the processor definition
129 */
130 ProcessorDefinition<?> getProcessorDefinition();
131
132 /**
133 * Gets the {@link RouteContext}
134 *
135 * @return the route context
136 */
137 RouteContext getRouteContext();
138 }