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; 021import java.util.Set; 022 023import org.apache.camel.CamelContext; 024import org.apache.camel.Endpoint; 025import org.apache.camel.EndpointAware; 026import org.apache.camel.ErrorHandlerFactory; 027import org.apache.camel.NamedNode; 028import org.apache.camel.Processor; 029import org.apache.camel.Route; 030import org.apache.camel.RuntimeConfiguration; 031import org.apache.camel.meta.Experimental; 032 033/** 034 * The context used to activate new routing rules 035 */ 036public interface RouteContext extends RuntimeConfiguration, EndpointAware { 037 038 /** 039 * Gets the route id 040 */ 041 String getRouteId(); 042 043 /** 044 * Get the route type 045 * 046 * @return the route type 047 */ 048 NamedNode getRoute(); 049 050 /** 051 * Gets the camel context 052 * 053 * @return the camel context 054 */ 055 CamelContext getCamelContext(); 056 057 /** 058 * Resolves an endpoint from the URI 059 * 060 * @param uri the URI 061 * @return the resolved endpoint 062 */ 063 Endpoint resolveEndpoint(String uri); 064 065 /** 066 * Resolves an endpoint from either a URI or a named reference 067 * 068 * @param uri the URI or 069 * @param ref the named reference 070 * @return the resolved endpoint 071 */ 072 Endpoint resolveEndpoint(String uri, String ref); 073 074 /** 075 * lookup an object by name and type 076 * 077 * @param name the name to lookup 078 * @param type the expected type 079 * @return the found object 080 */ 081 <T> T lookup(String name, Class<T> type); 082 083 /** 084 * lookup an object by name and type or throws {@link org.apache.camel.NoSuchBeanException} if not found. 085 * 086 * @param name the name to lookup 087 * @param type the expected type 088 * @return the found object 089 */ 090 <T> T mandatoryLookup(String name, Class<T> type); 091 092 /** 093 * lookup objects by type 094 * 095 * @param type the expected type 096 * @return the found objects with the name as the key in the map. Returns an empty map if none found. 097 */ 098 <T> Map<String, T> lookupByType(Class<T> type); 099 100 /** 101 * For completing the route creation, creating a single event driven route 102 * for the current from endpoint with any processors required 103 */ 104 Route commit(); 105 106 /** 107 * Adds an event driven processor 108 * 109 * @param processor the processor 110 */ 111 void addEventDrivenProcessor(Processor processor); 112 113 /** 114 * This method retrieves the InterceptStrategy instances this route context. 115 * 116 * @return the strategy 117 */ 118 List<InterceptStrategy> getInterceptStrategies(); 119 120 /** 121 * This method sets the InterceptStrategy instances on this route context. 122 * 123 * @param interceptStrategies the strategies 124 */ 125 void setInterceptStrategies(List<InterceptStrategy> interceptStrategies); 126 127 /** 128 * Adds a InterceptStrategy to this route context 129 * 130 * @param interceptStrategy the strategy 131 */ 132 void addInterceptStrategy(InterceptStrategy interceptStrategy); 133 134 /** 135 * Sets a special intercept strategy for management. 136 * <p/> 137 * Is by default used to correlate managed performance counters with processors 138 * when the runtime route is being constructed 139 * 140 * @param interceptStrategy the managed intercept strategy 141 */ 142 void setManagementInterceptStrategy(ManagementInterceptStrategy interceptStrategy); 143 144 /** 145 * Gets the special managed intercept strategy if any 146 * 147 * @return the managed intercept strategy, or <tt>null</tt> if not managed 148 */ 149 ManagementInterceptStrategy getManagementInterceptStrategy(); 150 151 /** 152 * If this flag is true, {@link org.apache.camel.reifier.ProcessorReifier#addRoutes(RouteContext)} 153 * will not add processor to addEventDrivenProcessor to the RouteContext and it 154 * will prevent from adding an EventDrivenRoute. 155 * 156 * @param value the flag 157 */ 158 void setIsRouteAdded(boolean value); 159 160 void setEndpoint(Endpoint endpoint); 161 162 /** 163 * Returns the isRouteAdded flag 164 * 165 * @return the flag 166 */ 167 boolean isRouteAdded(); 168 169 /** 170 * Gets the route policy List 171 * 172 * @return the route policy list if any 173 */ 174 List<RoutePolicy> getRoutePolicyList(); 175 176 /** 177 * Sets a custom route policy List 178 * 179 * @param routePolicyList the custom route policy list 180 */ 181 void setRoutePolicyList(List<RoutePolicy> routePolicyList); 182 183 /** 184 * Sets whether the route should automatically start when Camel starts. 185 * <p/> 186 * Default is <tt>true</tt> to always start up. 187 * 188 * @param autoStartup whether to start up automatically. 189 */ 190 @Override 191 void setAutoStartup(Boolean autoStartup); 192 193 /** 194 * Gets whether the route should automatically start when Camel starts. 195 * <p/> 196 * Default is <tt>true</tt> to always start up. 197 * 198 * @return <tt>true</tt> if route should automatically start 199 */ 200 @Override 201 Boolean isAutoStartup(); 202 203 void setStartupOrder(Integer startupOrder); 204 205 Integer getStartupOrder(); 206 207 void setErrorHandlerFactory(ErrorHandlerFactory errorHandlerFactory); 208 209 ErrorHandlerFactory getErrorHandlerFactory(); 210 211 void addAdvice(CamelInternalProcessorAdvice<?> advice); 212 213 void addProperty(String key, Object value); 214 215 /** 216 * Gets the last error. 217 * 218 * @return the error 219 */ 220 default RouteError getLastError() { 221 return null; 222 } 223 224 /** 225 * Sets the last error. 226 * 227 * @param error the error 228 */ 229 default void setLastError(RouteError error) { 230 } 231 232 /** 233 * Gets the {@link RouteController} for this route. 234 * 235 * @return the route controller, 236 */ 237 @Experimental 238 default RouteController getRouteController() { 239 return null; 240 } 241 242 /** 243 * Sets the {@link RouteController} for this route. 244 * 245 * @param controller the RouteController 246 */ 247 @Experimental 248 default void setRouteController(RouteController controller) { 249 } 250 251 Processor getOnCompletion(String onCompletionId); 252 253 void setOnCompletion(String onCompletionId, Processor processor); 254 255 Processor getOnException(String onExceptionId); 256 257 void setOnException(String onExceptionId, Processor processor); 258 259 /** 260 * Adds error handler for the given exception type 261 * 262 * @param factory the error handler factory 263 * @param exception the exception to handle 264 */ 265 void addErrorHandler(ErrorHandlerFactory factory, NamedNode exception); 266 267 /** 268 * Gets the error handlers 269 * 270 * @param factory the error handler factory 271 */ 272 Set<NamedNode> getErrorHandlers(ErrorHandlerFactory factory); 273 274 /** 275 * Link the error handlers from a factory to another 276 * 277 * @param source the source factory 278 * @param target the target factory 279 */ 280 void addErrorHandlerFactoryReference(ErrorHandlerFactory source, ErrorHandlerFactory target); 281 282}