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