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.spi;
018
019 import java.util.List;
020 import java.util.Map;
021
022 import org.apache.camel.CamelContext;
023 import org.apache.camel.Endpoint;
024 import org.apache.camel.Processor;
025 import org.apache.camel.RuntimeConfiguration;
026 import org.apache.camel.model.FromDefinition;
027 import org.apache.camel.model.ProcessorDefinition;
028 import org.apache.camel.model.RouteDefinition;
029
030 /**
031 * The context used to activate new routing rules
032 *
033 * @version
034 */
035 public interface RouteContext extends RuntimeConfiguration {
036
037 /**
038 * Gets the endpoint
039 *
040 * @return the endpoint
041 */
042 Endpoint getEndpoint();
043
044 /**
045 * Gets the from type
046 *
047 * @return the from type
048 */
049 FromDefinition getFrom();
050
051 /**
052 * Get the route type
053 *
054 * @return the route type
055 */
056 RouteDefinition getRoute();
057
058 /**
059 * Gets the camel context
060 *
061 * @return the camel context
062 */
063 CamelContext getCamelContext();
064
065 /**
066 * Resolves an endpoint from the URI
067 *
068 * @param uri the URI
069 * @return the resolved endpoint
070 */
071 Endpoint resolveEndpoint(String uri);
072
073 /**
074 * Resolves an endpoint from either a URI or a named reference
075 *
076 * @param uri the URI or
077 * @param ref the named reference
078 * @return the resolved endpoint
079 */
080 Endpoint resolveEndpoint(String uri, String ref);
081
082 /**
083 * lookup an object by name and type
084 *
085 * @param name the name to lookup
086 * @param type the expected type
087 * @return the found object
088 */
089 <T> T lookup(String name, Class<T> type);
090
091 /**
092 * lookup objects by type
093 *
094 * @param type the expected type
095 * @return the found objects with the name as the key in the map. Returns an empty map if none found.
096 */
097 <T> Map<String, T> lookupByType(Class<T> type);
098
099 /**
100 * For completing the route creation, creating a single event driven route
101 * for the current from endpoint with any processors required
102 */
103 void commit();
104
105 /**
106 * Adds an event driven processor
107 *
108 * @param processor the processor
109 */
110 void addEventDrivenProcessor(Processor processor);
111
112 /**
113 * This method retrieves the InterceptStrategy instances this route context.
114 *
115 * @return the strategy
116 */
117 List<InterceptStrategy> getInterceptStrategies();
118
119 /**
120 * This method sets the InterceptStrategy instances on this route context.
121 *
122 * @param interceptStrategies the strategies
123 */
124 void setInterceptStrategies(List<InterceptStrategy> interceptStrategies);
125
126 /**
127 * Adds a InterceptStrategy to this route context
128 *
129 * @param interceptStrategy the strategy
130 */
131 void addInterceptStrategy(InterceptStrategy interceptStrategy);
132
133 /**
134 * Sets a special intercept strategy for management.
135 * <p/>
136 * Is by default used to correlate managed performance counters with processors
137 * when the runtime route is being constructed
138 *
139 * @param interceptStrategy the managed intercept strategy
140 */
141 void setManagedInterceptStrategy(InterceptStrategy interceptStrategy);
142
143 /**
144 * Gets the special managed intercept strategy if any
145 *
146 * @return the managed intercept strategy, or <tt>null</tt> if not managed
147 */
148 InterceptStrategy getManagedInterceptStrategy();
149
150 /**
151 * If this flag is true, {@link ProcessorDefinition#addRoutes(RouteContext, java.util.Collection)}
152 * will not add processor to addEventDrivenProcessor to the RouteContext and it
153 * will prevent from adding an EventDrivenRoute.
154 *
155 * @param value the flag
156 */
157 void setIsRouteAdded(boolean value);
158
159 /**
160 * Returns the isRouteAdded flag
161 *
162 * @return the flag
163 */
164 boolean isRouteAdded();
165
166 /**
167 * Gets the route policy List
168 *
169 * @return the route policy list if any
170 */
171 List<RoutePolicy> getRoutePolicyList();
172
173 /**
174 * Sets a custom route policy List
175 *
176 * @param routePolicyList the custom route policy list
177 */
178 void setRoutePolicyList(List<RoutePolicy> routePolicyList);
179
180 /**
181 * A private counter that increments, is used to as book keeping
182 * when building a route based on the model
183 * <p/>
184 * We need this special book keeping be able to assign the correct
185 * {@link org.apache.camel.model.ProcessorDefinition} to the {@link org.apache.camel.Channel}
186 *
187 * @param node the current node
188 * @return the current count
189 */
190 int getAndIncrement(ProcessorDefinition<?> node);
191
192 }