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.model; 018 019import java.util.Collection; 020import java.util.List; 021import java.util.Map; 022import java.util.function.Function; 023 024import org.apache.camel.CamelContext; 025import org.apache.camel.model.cloud.ServiceCallConfigurationDefinition; 026import org.apache.camel.model.rest.RestDefinition; 027import org.apache.camel.model.transformer.TransformerDefinition; 028import org.apache.camel.model.validator.ValidatorDefinition; 029import org.apache.camel.support.PatternHelper; 030 031/** 032 * Model interface 033 */ 034public interface Model { 035 036 /** 037 * Returns a list of the current route definitions 038 * 039 * @return list of the current route definitions 040 */ 041 List<RouteDefinition> getRouteDefinitions(); 042 043 /** 044 * Gets the route definition with the given id 045 * 046 * @param id id of the route 047 * @return the route definition or <tt>null</tt> if not found 048 */ 049 RouteDefinition getRouteDefinition(String id); 050 051 /** 052 * Adds a collection of route definitions to the context 053 * <p/> 054 * <b>Important: </b> Each route in the same {@link CamelContext} must have 055 * an <b>unique</b> route id. If you use the API from {@link CamelContext} 056 * or {@link Model} to add routes, then any new routes which has a route id 057 * that matches an old route, then the old route is replaced by the new 058 * route. 059 * 060 * @param routeDefinitions the route(s) definition to add 061 * @throws Exception if the route definitions could not be added for 062 * whatever reason 063 */ 064 void addRouteDefinitions(Collection<RouteDefinition> routeDefinitions) throws Exception; 065 066 /** 067 * Add a route definition to the context 068 * <p/> 069 * <b>Important: </b> Each route in the same {@link CamelContext} must have 070 * an <b>unique</b> route id. If you use the API from {@link CamelContext} 071 * or {@link Model} to add routes, then any new routes which has a route id 072 * that matches an old route, then the old route is replaced by the new 073 * route. 074 * 075 * @param routeDefinition the route definition to add 076 * @throws Exception if the route definition could not be added for whatever 077 * reason 078 */ 079 void addRouteDefinition(RouteDefinition routeDefinition) throws Exception; 080 081 /** 082 * Removes a collection of route definitions from the context - stopping any 083 * previously running routes if any of them are actively running 084 * 085 * @param routeDefinitions route(s) definitions to remove 086 * @throws Exception if the route definitions could not be removed for 087 * whatever reason 088 */ 089 void removeRouteDefinitions(Collection<RouteDefinition> routeDefinitions) throws Exception; 090 091 /** 092 * Removes a route definition from the context - stopping any previously 093 * running routes if any of them are actively running 094 * 095 * @param routeDefinition route definition to remove 096 * @throws Exception if the route definition could not be removed for 097 * whatever reason 098 */ 099 void removeRouteDefinition(RouteDefinition routeDefinition) throws Exception; 100 101 /** 102 * Returns a list of the current REST definitions 103 * 104 * @return list of the current REST definitions 105 */ 106 List<RestDefinition> getRestDefinitions(); 107 108 /** 109 * Adds a collection of rest definitions to the context 110 * 111 * @param restDefinitions the rest(s) definition to add 112 * @param addToRoutes whether the rests should also automatically be added 113 * as routes 114 * @throws Exception if the rest definitions could not be created for 115 * whatever reason 116 */ 117 void addRestDefinitions(Collection<RestDefinition> restDefinitions, boolean addToRoutes) throws Exception; 118 119 /** 120 * Sets the data formats that can be referenced in the routes. 121 * 122 * @param dataFormats the data formats 123 */ 124 void setDataFormats(Map<String, DataFormatDefinition> dataFormats); 125 126 /** 127 * Gets the data formats that can be referenced in the routes. 128 * 129 * @return the data formats available 130 */ 131 Map<String, DataFormatDefinition> getDataFormats(); 132 133 /** 134 * Resolve a data format definition given its name 135 * 136 * @param name the data format definition name or a reference to it in the 137 * {@link org.apache.camel.spi.Registry} 138 * @return the resolved data format definition, or <tt>null</tt> if not 139 * found 140 */ 141 DataFormatDefinition resolveDataFormatDefinition(String name); 142 143 /** 144 * Gets the processor definition from any of the routes which with the given 145 * id 146 * 147 * @param id id of the processor definition 148 * @return the processor definition or <tt>null</tt> if not found 149 */ 150 ProcessorDefinition<?> getProcessorDefinition(String id); 151 152 /** 153 * Gets the processor definition from any of the routes which with the given 154 * id 155 * 156 * @param id id of the processor definition 157 * @param type the processor definition type 158 * @return the processor definition or <tt>null</tt> if not found 159 * @throws ClassCastException is thrown if the type is not correct type 160 */ 161 <T extends ProcessorDefinition<T>> T getProcessorDefinition(String id, Class<T> type); 162 163 /** 164 * Sets the validators that can be referenced in the routes. 165 * 166 * @param validators the validators 167 */ 168 void setValidators(List<ValidatorDefinition> validators); 169 170 /** 171 * Gets the Hystrix configuration by the given name. If no name is given the 172 * default configuration is returned, see <tt>setHystrixConfiguration</tt> 173 * 174 * @param id id of the configuration, or <tt>null</tt> to return the default 175 * configuration 176 * @return the configuration, or <tt>null</tt> if no configuration has been 177 * registered 178 */ 179 HystrixConfigurationDefinition getHystrixConfiguration(String id); 180 181 /** 182 * Sets the default Hystrix configuration 183 * 184 * @param configuration the configuration 185 */ 186 void setHystrixConfiguration(HystrixConfigurationDefinition configuration); 187 188 /** 189 * Sets the Hystrix configurations 190 * 191 * @param configurations the configuration list 192 */ 193 void setHystrixConfigurations(List<HystrixConfigurationDefinition> configurations); 194 195 /** 196 * Adds the Hystrix configuration 197 * 198 * @param id name of the configuration 199 * @param configuration the configuration 200 */ 201 void addHystrixConfiguration(String id, HystrixConfigurationDefinition configuration); 202 203 /** 204 * Gets the Resilience4j configuration by the given name. If no name is given the 205 * default configuration is returned, see <tt>setResilience4jConfiguration</tt> 206 * 207 * @param id id of the configuration, or <tt>null</tt> to return the default 208 * configuration 209 * @return the configuration, or <tt>null</tt> if no configuration has been 210 * registered 211 */ 212 Resilience4jConfigurationDefinition getResilience4jConfiguration(String id); 213 214 /** 215 * Sets the default Resilience4j configuration 216 * 217 * @param configuration the configuration 218 */ 219 void setResilience4jConfiguration(Resilience4jConfigurationDefinition configuration); 220 221 /** 222 * Sets the Resilience4j configurations 223 * 224 * @param configurations the configuration list 225 */ 226 void setResilience4jConfigurations(List<Resilience4jConfigurationDefinition> configurations); 227 228 /** 229 * Adds the Resilience4j configuration 230 * 231 * @param id name of the configuration 232 * @param configuration the configuration 233 */ 234 void addResilience4jConfiguration(String id, Resilience4jConfigurationDefinition configuration); 235 236 /** 237 * Gets the MicroProfile Fault Tolerance configuration by the given name. If no name is given the 238 * default configuration is returned, see <tt>setFaultToleranceConfigurationDefinition</tt> 239 * 240 * @param id id of the configuration, or <tt>null</tt> to return the default 241 * configuration 242 * @return the configuration, or <tt>null</tt> if no configuration has been 243 * registered 244 */ 245 FaultToleranceConfigurationDefinition getFaultToleranceConfiguration(String id); 246 247 /** 248 * Sets the default MicroProfile Fault Tolerance configuration 249 * 250 * @param configuration the configuration 251 */ 252 void setFaultToleranceConfiguration(FaultToleranceConfigurationDefinition configuration); 253 254 /** 255 * Sets the MicroProfile Fault Tolerance configurations 256 * 257 * @param configurations the configuration list 258 */ 259 void setFaultToleranceConfigurations(List<FaultToleranceConfigurationDefinition> configurations); 260 261 /** 262 * Adds the MicroProfile Fault Tolerance configuration 263 * 264 * @param id name of the configuration 265 * @param configuration the configuration 266 */ 267 void addFaultToleranceConfiguration(String id, FaultToleranceConfigurationDefinition configuration); 268 269 /** 270 * Gets the validators that can be referenced in the routes. 271 * 272 * @return the validators available 273 */ 274 List<ValidatorDefinition> getValidators(); 275 276 /** 277 * Sets the transformers that can be referenced in the routes. 278 * 279 * @param transformers the transformers 280 */ 281 void setTransformers(List<TransformerDefinition> transformers); 282 283 /** 284 * Gets the transformers that can be referenced in the routes. 285 * 286 * @return the transformers available 287 */ 288 List<TransformerDefinition> getTransformers(); 289 290 /** 291 * Gets the service call configuration by the given name. If no name is 292 * given the default configuration is returned, see 293 * <tt>setServiceCallConfiguration</tt> 294 * 295 * @param serviceName name of service, or <tt>null</tt> to return the 296 * default configuration 297 * @return the configuration, or <tt>null</tt> if no configuration has been 298 * registered 299 */ 300 ServiceCallConfigurationDefinition getServiceCallConfiguration(String serviceName); 301 302 /** 303 * Sets the default service call configuration 304 * 305 * @param configuration the configuration 306 */ 307 void setServiceCallConfiguration(ServiceCallConfigurationDefinition configuration); 308 309 /** 310 * Sets the service call configurations 311 * 312 * @param configurations the configuration list 313 */ 314 void setServiceCallConfigurations(List<ServiceCallConfigurationDefinition> configurations); 315 316 /** 317 * Adds the service call configuration 318 * 319 * @param serviceName name of the service 320 * @param configuration the configuration 321 */ 322 void addServiceCallConfiguration(String serviceName, ServiceCallConfigurationDefinition configuration); 323 324 /** 325 * Used for filtering routes routes matching the given pattern, which 326 * follows the following rules: - Match by route id - Match by route input 327 * endpoint uri The matching is using exact match, by wildcard and regular 328 * expression as documented by 329 * {@link PatternHelper#matchPattern(String, String)}. For example to only 330 * include routes which starts with foo in their route id's, use: 331 * include=foo* And to exclude routes which starts from JMS endpoints, 332 * use: exclude=jms:* Exclude takes precedence over include. 333 * 334 * @param include the include pattern 335 * @param exclude the exclude pattern 336 */ 337 void setRouteFilterPattern(String include, String exclude); 338 339 /** 340 * Sets a custom route filter to use for filtering unwanted routes when 341 * routes are added. 342 * 343 * @param filter the filter 344 */ 345 void setRouteFilter(Function<RouteDefinition, Boolean> filter); 346 347 /** 348 * Gets the current route filter 349 * 350 * @return the filter, or <tt>null</tt> if no custom filter has been 351 * configured. 352 */ 353 Function<RouteDefinition, Boolean> getRouteFilter(); 354 355}