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 $Revision: 836224 $
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 * Creates a processor
067 *
068 * @param node the node
069 * @return the created processor
070 * @throws Exception can be thrown
071 */
072 Processor createProcessor(ProcessorDefinition<?> node) throws Exception;
073
074 /**
075 * Resolves an endpoint from the URI
076 *
077 * @param uri the URI
078 * @return the resolved endpoint
079 */
080 Endpoint resolveEndpoint(String uri);
081
082 /**
083 * Resolves an endpoint from either a URI or a named reference
084 *
085 * @param uri the URI or
086 * @param ref the named reference
087 * @return the resolved endpoint
088 */
089 Endpoint resolveEndpoint(String uri, String ref);
090
091 /**
092 * lookup an object by name and type
093 *
094 * @param name the name to lookup
095 * @param type the expected type
096 * @return the found object
097 */
098 <T> T lookup(String name, Class<T> type);
099
100 /**
101 * lookup objects by type
102 *
103 * @param type the expected type
104 * @return the found objects with the name as the key in the map. Returns an empty map if none found.
105 */
106 <T> Map<String, T> lookupByType(Class<T> type);
107
108 /**
109 * Lets complete the route creation, creating a single event driven route
110 * for the current from endpoint with any processors required
111 */
112 void commit();
113
114 /**
115 * Adds an event driven processor
116 *
117 * @param processor the processor
118 */
119 void addEventDrivenProcessor(Processor processor);
120
121 /**
122 * This method retrieves the InterceptStrategy instances this route context.
123 *
124 * @return the strategy
125 */
126 List<InterceptStrategy> getInterceptStrategies();
127
128 /**
129 * This method sets the InterceptStrategy instances on this route context.
130 *
131 * @param interceptStrategies the strategies
132 */
133 void setInterceptStrategies(List<InterceptStrategy> interceptStrategies);
134
135 /**
136 * Adds a InterceptStrategy to this route context
137 *
138 * @param interceptStrategy the strategy
139 */
140 void addInterceptStrategy(InterceptStrategy interceptStrategy);
141
142 /**
143 * Sets a special intercept strategy for management.
144 * <p/>
145 * Is by default used to correlate managed performance counters with processors
146 * when the runtime route is being constructed
147 *
148 * @param interceptStrategy the managed intercept strategy
149 */
150 void setManagedInterceptStrategy(InterceptStrategy interceptStrategy);
151
152 /**
153 * Gets the special managed intercept strategy if any
154 *
155 * @return the managed intercept strategy, or <tt>null</tt> if not managed
156 */
157 InterceptStrategy getManagedInterceptStrategy();
158
159 /**
160 * If this flag is true, {@link ProcessorDefinition#addRoutes(RouteContext, java.util.Collection)}
161 * will not add processor to addEventDrivenProcessor to the RouteContext and it
162 * will prevent from adding an EventDrivenRoute.
163 *
164 * @param value the flag
165 */
166 void setIsRouteAdded(boolean value);
167
168 /**
169 * Returns the isRouteAdded flag
170 *
171 * @return the flag
172 */
173 boolean isRouteAdded();
174
175 /**
176 * Gets the route policy
177 *
178 * @return the route policy if any
179 */
180 RoutePolicy getRoutePolicy();
181
182 /**
183 * Sets a custom route policy
184 *
185 * @param routePolicy the custom route policy
186 */
187 void setRoutePolicy(RoutePolicy routePolicy);
188
189 /**
190 * A private counter that increments, is used to as book keeping
191 * when building a route based on the model
192 * <p/>
193 * We need this special book keeping be able to assign the correct
194 * {@link org.apache.camel.model.ProcessorDefinition} to the {@link org.apache.camel.Channel}
195 *
196 * @param node the current node
197 * @return the current count
198 */
199 int getAndIncrement(ProcessorDefinition<?> node);
200
201 }