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.NamedNode;
026import org.apache.camel.Processor;
027import org.apache.camel.RuntimeConfiguration;
028import org.apache.camel.meta.Experimental;
029
030/**
031 * The context used to activate new routing rules
032 */
033public interface RouteContext extends RuntimeConfiguration, EndpointAware {
034
035    /**
036     * Gets the from type
037     *
038     * @return the from type
039     */
040    NamedNode getFrom();
041
042    /**
043     * Get the route type
044     *
045     * @return the route type
046     */
047    NamedNode getRoute();
048
049    /**
050     * Gets the camel context
051     *
052     * @return the camel context
053     */
054    CamelContext getCamelContext();
055
056    /**
057     * Resolves an endpoint from the URI
058     *
059     * @param uri the URI
060     * @return the resolved endpoint
061     */
062    Endpoint resolveEndpoint(String uri);
063
064    /**
065     * Resolves an endpoint from either a URI or a named reference
066     *
067     * @param uri  the URI or
068     * @param ref  the named reference
069     * @return the resolved endpoint
070     */
071    Endpoint resolveEndpoint(String uri, String ref);
072
073    /**
074     * lookup an object by name and type
075     *
076     * @param name  the name to lookup
077     * @param type  the expected type
078     * @return the found object
079     */
080    <T> T lookup(String name, Class<T> type);
081
082    /**
083     * lookup an object by name and type or throws {@link org.apache.camel.NoSuchBeanException} if not found.
084     *
085     * @param name  the name to lookup
086     * @param type  the expected type
087     * @return the found object
088     */
089    <T> T mandatoryLookup(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 setManagementInterceptStrategy(ManagementInterceptStrategy 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    ManagementInterceptStrategy getManagementInterceptStrategy();
149
150    /**
151     * If this flag is true, {@link org.apache.camel.model.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(NamedNode node);
191
192    /**
193     * Gets the last error.
194     *
195     * @return the error
196     */
197    default RouteError getLastError() {
198        return null;
199    }
200
201    /**
202     * Sets the last error.
203     *
204     * @param error the error
205     */
206    default void setLastError(RouteError error) {
207    }
208
209    /**
210     * Gets the  {@link RouteController} for this route.
211     *
212     * @return the route controller,
213     */
214    @Experimental
215    default RouteController getRouteController() {
216        return null;
217    }
218
219    /**
220     * Sets the {@link RouteController} for this route.
221     *
222     * @param controller the RouteController
223     */
224    @Experimental
225    default void setRouteController(RouteController controller) {
226    }
227}