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 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 validators that can be referenced in the routes. 238 * 239 * @return the validators available 240 */ 241 List<ValidatorDefinition> getValidators(); 242 243 /** 244 * Sets the transformers that can be referenced in the routes. 245 * 246 * @param transformers the transformers 247 */ 248 void setTransformers(List<TransformerDefinition> transformers); 249 250 /** 251 * Gets the transformers that can be referenced in the routes. 252 * 253 * @return the transformers available 254 */ 255 List<TransformerDefinition> getTransformers(); 256 257 /** 258 * Gets the service call configuration by the given name. If no name is 259 * given the default configuration is returned, see 260 * <tt>setServiceCallConfiguration</tt> 261 * 262 * @param serviceName name of service, or <tt>null</tt> to return the 263 * default configuration 264 * @return the configuration, or <tt>null</tt> if no configuration has been 265 * registered 266 */ 267 ServiceCallConfigurationDefinition getServiceCallConfiguration(String serviceName); 268 269 /** 270 * Sets the default service call configuration 271 * 272 * @param configuration the configuration 273 */ 274 void setServiceCallConfiguration(ServiceCallConfigurationDefinition configuration); 275 276 /** 277 * Sets the service call configurations 278 * 279 * @param configurations the configuration list 280 */ 281 void setServiceCallConfigurations(List<ServiceCallConfigurationDefinition> configurations); 282 283 /** 284 * Adds the service call configuration 285 * 286 * @param serviceName name of the service 287 * @param configuration the configuration 288 */ 289 void addServiceCallConfiguration(String serviceName, ServiceCallConfigurationDefinition configuration); 290 291 /** 292 * Start all routes from this model. 293 */ 294 void startRouteDefinitions() throws Exception; 295 296 /** 297 * Used for filtering routes routes matching the given pattern, which 298 * follows the following rules: - Match by route id - Match by route input 299 * endpoint uri The matching is using exact match, by wildcard and regular 300 * expression as documented by 301 * {@link PatternHelper#matchPattern(String, String)}. For example to only 302 * include routes which starts with foo in their route id's, use: 303 * include=foo* And to exclude routes which starts from JMS endpoints, 304 * use: exclude=jms:* Exclude takes precedence over include. 305 * 306 * @param include the include pattern 307 * @param exclude the exclude pattern 308 */ 309 void setRouteFilterPattern(String include, String exclude); 310 311 /** 312 * Sets a custom route filter to use for filtering unwanted routes when 313 * routes are added. 314 * 315 * @param filter the filter 316 */ 317 void setRouteFilter(Function<RouteDefinition, Boolean> filter); 318 319 /** 320 * Gets the current route filter 321 * 322 * @return the filter, or <tt>null</tt> if no custom filter has been 323 * configured. 324 */ 325 Function<RouteDefinition, Boolean> getRouteFilter(); 326 327}