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 */ 017 package org.apache.camel; 018 019 import java.io.IOException; 020 import java.io.InputStream; 021 import java.util.Collection; 022 import java.util.List; 023 import java.util.Map; 024 import java.util.Properties; 025 import java.util.concurrent.ScheduledExecutorService; 026 import java.util.concurrent.TimeUnit; 027 028 import org.apache.camel.builder.ErrorHandlerBuilder; 029 import org.apache.camel.model.DataFormatDefinition; 030 import org.apache.camel.model.RouteDefinition; 031 import org.apache.camel.model.RoutesDefinition; 032 import org.apache.camel.spi.CamelContextNameStrategy; 033 import org.apache.camel.spi.ClassResolver; 034 import org.apache.camel.spi.DataFormat; 035 import org.apache.camel.spi.DataFormatResolver; 036 import org.apache.camel.spi.Debugger; 037 import org.apache.camel.spi.EndpointStrategy; 038 import org.apache.camel.spi.ExecutorServiceManager; 039 import org.apache.camel.spi.FactoryFinder; 040 import org.apache.camel.spi.FactoryFinderResolver; 041 import org.apache.camel.spi.InflightRepository; 042 import org.apache.camel.spi.Injector; 043 import org.apache.camel.spi.InterceptStrategy; 044 import org.apache.camel.spi.Language; 045 import org.apache.camel.spi.LifecycleStrategy; 046 import org.apache.camel.spi.ManagementMBeanAssembler; 047 import org.apache.camel.spi.ManagementNameStrategy; 048 import org.apache.camel.spi.ManagementStrategy; 049 import org.apache.camel.spi.NodeIdFactory; 050 import org.apache.camel.spi.PackageScanClassResolver; 051 import org.apache.camel.spi.ProcessorFactory; 052 import org.apache.camel.spi.Registry; 053 import org.apache.camel.spi.RouteStartupOrder; 054 import org.apache.camel.spi.ServicePool; 055 import org.apache.camel.spi.ShutdownStrategy; 056 import org.apache.camel.spi.StreamCachingStrategy; 057 import org.apache.camel.spi.TypeConverterRegistry; 058 import org.apache.camel.spi.UnitOfWorkFactory; 059 import org.apache.camel.spi.UuidGenerator; 060 import org.apache.camel.util.LoadPropertiesException; 061 062 /** 063 * Interface used to represent the context used to configure routes and the 064 * policies to use during message exchanges between endpoints. 065 * <p/> 066 * The context offers the following methods to control the lifecycle: 067 * <ul> 068 * <li>{@link #start()} - to start (<b>important:</b> the start method is not blocked, see more details 069 * <a href="http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html">here</a>)</li> 070 * <li>{@link #stop()} - to shutdown (will stop all routes/components/endpoints etc and clear internal state/cache)</li> 071 * <li>{@link #suspend()} - to pause routing messages</li> 072 * <li>{@link #resume()} - to resume after a suspend</li> 073 * </ul> 074 * <p/> 075 * <b>Notice:</b> {@link #stop()} and {@link #suspend()} will gracefully stop/suspend routes ensuring any messages 076 * in progress will be given time to complete. See more details at {@link org.apache.camel.spi.ShutdownStrategy}. 077 * <p/> 078 * If you are doing a hot restart then it's advised to use the suspend/resume methods which ensure a faster 079 * restart but also allows any internal state to be kept as is. 080 * The stop/start approach will do a <i>cold</i> restart of Camel, where all internal state is reset. 081 * <p/> 082 * End users are advised to use suspend/resume. Using stop is for shutting down Camel and it's not guaranteed that 083 * when it's being started again using the start method that Camel will operate consistently. 084 * 085 * @version 086 */ 087 public interface CamelContext extends SuspendableService, RuntimeConfiguration { 088 089 /** 090 * Starts the {@link CamelContext} (<b>important:</b> the start method is not blocked, see more details 091 * <a href="http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html">here</a>)</li>. 092 * <p/> 093 * See more details at the class-level javadoc of this class. 094 * 095 * @throws Exception is thrown if starting failed 096 */ 097 void start() throws Exception; 098 099 /** 100 * Stop and shutdown the {@link CamelContext} (will stop all routes/components/endpoints etc and clear internal state/cache). 101 * <p/> 102 * See more details at the class-level javadoc of this class. 103 * 104 * @throws Exception is thrown if stopping failed 105 */ 106 void stop() throws Exception; 107 108 /** 109 * Gets the name (id) of the this context. 110 * 111 * @return the name 112 */ 113 String getName(); 114 115 /** 116 * Gets the current name strategy 117 * 118 * @return name strategy 119 */ 120 CamelContextNameStrategy getNameStrategy(); 121 122 /** 123 * Sets a custom name strategy 124 * 125 * @param nameStrategy name strategy 126 */ 127 void setNameStrategy(CamelContextNameStrategy nameStrategy); 128 129 /** 130 * Gets the current management name strategy 131 * 132 * @return management name strategy 133 */ 134 ManagementNameStrategy getManagementNameStrategy(); 135 136 /** 137 * Sets a custom management name strategy 138 * 139 * @param nameStrategy name strategy 140 */ 141 void setManagementNameStrategy(ManagementNameStrategy nameStrategy); 142 143 /** 144 * Gets the name this {@link CamelContext} was registered in JMX. 145 * <p/> 146 * The reason that a {@link CamelContext} can have a different name in JMX is the fact to remedy for name clash 147 * in JMX when having multiple {@link CamelContext}s in the same JVM. Camel will automatic reassign and use 148 * a free name to avoid failing to start. 149 * 150 * @return the management name 151 */ 152 String getManagementName(); 153 154 /** 155 * Gets the version of the this context. 156 * 157 * @return the version 158 */ 159 String getVersion(); 160 161 /** 162 * Get the status of this context 163 * 164 * @return the status 165 */ 166 ServiceStatus getStatus(); 167 168 /** 169 * Gets the uptime in a human readable format 170 * 171 * @return the uptime in days/hours/minutes 172 */ 173 String getUptime(); 174 175 // Service Methods 176 //----------------------------------------------------------------------- 177 178 /** 179 * Adds a service to this context, which allows this context to control the lifecycle, ensuring 180 * the service is stopped when the context stops. 181 * <p/> 182 * The service will also have {@link CamelContext} injected if its {@link CamelContextAware}. 183 * The service will also be enlisted in JMX for management (if JMX is enabled). 184 * The service will be started, if its not already started. 185 * 186 * @param object the service 187 * @throws Exception can be thrown when starting the service 188 */ 189 void addService(Object object) throws Exception; 190 191 /** 192 * Removes a service from this context. 193 * <p/> 194 * The service is assumed to have been previously added using {@link #addService(Object)} method. 195 * This method will <b>not</b> change the service lifecycle. 196 * 197 * @param object the service 198 * @throws Exception can be thrown if error removing the service 199 * @return <tt>true</tt> if the service was removed, <tt>false</tt> if no service existed 200 */ 201 boolean removeService(Object object) throws Exception; 202 203 /** 204 * Has the given service already been added to this context? 205 * 206 * @param object the service 207 * @return <tt>true</tt> if already added, <tt>false</tt> if not. 208 */ 209 boolean hasService(Object object); 210 211 /** 212 * Adds the given listener to be invoked when {@link CamelContext} have just been started. 213 * <p/> 214 * This allows listeners to do any custom work after the routes and other services have been started and are running. 215 * <p/><b>Important:</b> The listener will always be invoked, also if the {@link CamelContext} has already been 216 * started, see the {@link org.apache.camel.StartupListener#onCamelContextStarted(CamelContext, boolean)} method. 217 * 218 * @param listener the listener 219 * @throws Exception can be thrown if {@link CamelContext} is already started and the listener is invoked 220 * and cause an exception to be thrown 221 */ 222 void addStartupListener(StartupListener listener) throws Exception; 223 224 // Component Management Methods 225 //----------------------------------------------------------------------- 226 227 /** 228 * Adds a component to the context. 229 * 230 * @param componentName the name the component is registered as 231 * @param component the component 232 */ 233 void addComponent(String componentName, Component component); 234 235 /** 236 * Is the given component already registered? 237 * 238 * @param componentName the name of the component 239 * @return the registered Component or <tt>null</tt> if not registered 240 */ 241 Component hasComponent(String componentName); 242 243 /** 244 * Gets a component from the context by name. 245 * 246 * @param componentName the name of the component 247 * @return the component 248 */ 249 Component getComponent(String componentName); 250 251 /** 252 * Gets a component from the context by name. 253 * 254 * @param componentName the name of the component 255 * @param autoCreateComponents whether or not the component should 256 * be lazily created if it does not already exist 257 * @return the component 258 */ 259 Component getComponent(String name, boolean autoCreateComponents); 260 261 /** 262 * Gets a component from the context by name and specifying the expected type of component. 263 * 264 * @param name the name to lookup 265 * @param componentType the expected type 266 * @return the component 267 */ 268 <T extends Component> T getComponent(String name, Class<T> componentType); 269 270 /** 271 * Gets a readonly list of names of the components currently registered 272 * 273 * @return a readonly list with the names of the the components 274 */ 275 List<String> getComponentNames(); 276 277 /** 278 * Removes a previously added component. 279 * <p/> 280 * The component being removed will be stopped first. 281 * 282 * @param componentName the component name to remove 283 * @return the previously added component or null if it had not been previously added. 284 */ 285 Component removeComponent(String componentName); 286 287 // Endpoint Management Methods 288 //----------------------------------------------------------------------- 289 290 /** 291 * Resolves the given name to an {@link Endpoint} of the specified type. 292 * If the name has a singleton endpoint registered, then the singleton is returned. 293 * Otherwise, a new {@link Endpoint} is created and registered. 294 * 295 * @param uri the URI of the endpoint 296 * @return the endpoint 297 */ 298 Endpoint getEndpoint(String uri); 299 300 /** 301 * Resolves the given name to an {@link Endpoint} of the specified type. 302 * If the name has a singleton endpoint registered, then the singleton is returned. 303 * Otherwise, a new {@link Endpoint} is created and registered. 304 * 305 * @param name the name of the endpoint 306 * @param endpointType the expected type 307 * @return the endpoint 308 */ 309 <T extends Endpoint> T getEndpoint(String name, Class<T> endpointType); 310 311 /** 312 * Returns the collection of all registered endpoints. 313 * 314 * @return all endpoints 315 */ 316 Collection<Endpoint> getEndpoints(); 317 318 /** 319 * Returns a new Map containing all of the active endpoints with the key of the map being their 320 * unique key. 321 * 322 * @return map of active endpoints 323 */ 324 Map<String, Endpoint> getEndpointMap(); 325 326 /** 327 * Is the given endpoint already registered? 328 * 329 * @param uri the URI of the endpoint 330 * @return the registered endpoint or <tt>null</tt> if not registered 331 */ 332 Endpoint hasEndpoint(String uri); 333 334 /** 335 * Adds the endpoint to the context using the given URI. 336 * 337 * @param uri the URI to be used to resolve this endpoint 338 * @param endpoint the endpoint to be added to the context 339 * @return the old endpoint that was previously registered or <tt>null</tt> if none was registered 340 * @throws Exception if the new endpoint could not be started or the old endpoint could not be stopped 341 */ 342 Endpoint addEndpoint(String uri, Endpoint endpoint) throws Exception; 343 344 /** 345 * Removes all endpoints with the given URI. 346 * <p/> 347 * The endpoints being removed will be stopped first. 348 * 349 * @param pattern an uri or pattern to match 350 * @return a collection of endpoints removed which could be empty if there are no endpoints found for the given <tt>pattern</tt> 351 * @throws Exception if at least one endpoint could not be stopped 352 * @see org.apache.camel.util.EndpointHelper#matchEndpoint(CamelContext, String, String) for pattern 353 */ 354 Collection<Endpoint> removeEndpoints(String pattern) throws Exception; 355 356 /** 357 * Registers a {@link org.apache.camel.spi.EndpointStrategy callback} to allow you to do custom 358 * logic when an {@link Endpoint} is about to be registered to the {@link CamelContext} endpoint registry. 359 * <p/> 360 * When a callback is added it will be executed on the already registered endpoints allowing you to catch-up 361 * 362 * @param strategy callback to be invoked 363 */ 364 void addRegisterEndpointCallback(EndpointStrategy strategy); 365 366 // Route Management Methods 367 //----------------------------------------------------------------------- 368 369 /** 370 * Returns a list of the current route definitions 371 * 372 * @return list of the current route definitions 373 * @deprecated use {@link org.apache.camel.model.ModelCamelContext#getRouteDefinitions()} 374 */ 375 @Deprecated 376 List<RouteDefinition> getRouteDefinitions(); 377 378 /** 379 * Gets the route definition with the given id 380 * 381 * @param id id of the route 382 * @return the route definition or <tt>null</tt> if not found 383 * @deprecated use {@link org.apache.camel.model.ModelCamelContext#getRouteDefinition(String)} 384 */ 385 @Deprecated 386 RouteDefinition getRouteDefinition(String id); 387 388 /** 389 * Returns the order in which the route inputs was started. 390 * <p/> 391 * The order may not be according to the startupOrder defined on the route. 392 * For example a route could be started manually later, or new routes added at runtime. 393 * 394 * @return a list in the order how routes was started 395 */ 396 List<RouteStartupOrder> getRouteStartupOrder(); 397 398 /** 399 * Returns the current routes in this context 400 * 401 * @return the current routes 402 */ 403 List<Route> getRoutes(); 404 405 /** 406 * Gets the route with the given id 407 * 408 * @param id id of the route 409 * @return the route or <tt>null</tt> if not found 410 */ 411 Route getRoute(String id); 412 413 /** 414 * Adds a collection of routes to this context using the given builder 415 * to build them. 416 * <p/> 417 * <b>Important:</b> The added routes will <b>only</b> be started, if {@link CamelContext} 418 * is already started. You may want to check the state of {@link CamelContext} before 419 * adding the routes, using the {@link org.apache.camel.CamelContext#getStatus()} method. 420 * <p/> 421 * <b>Important: </b> Each route in the same {@link org.apache.camel.CamelContext} must have an <b>unique</b> route id. 422 * If you use the API from {@link org.apache.camel.CamelContext} or {@link org.apache.camel.model.ModelCamelContext} to add routes, then any 423 * new routes which has a route id that matches an old route, then the old route is replaced by the new route. 424 * 425 * @param builder the builder which will create the routes and add them to this context 426 * @throws Exception if the routes could not be created for whatever reason 427 */ 428 void addRoutes(RoutesBuilder builder) throws Exception; 429 430 /** 431 * Loads a collection of route definitions from the given {@link java.io.InputStream}. 432 * 433 * @param is input stream with the route(s) definition to add 434 * @throws Exception if the route definitions could not be loaded for whatever reason 435 * @return the route definitions 436 * @deprecated use {@link org.apache.camel.model.ModelCamelContext#loadRoutesDefinition(java.io.InputStream)} 437 */ 438 @Deprecated 439 RoutesDefinition loadRoutesDefinition(InputStream is) throws Exception; 440 441 /** 442 * Adds a collection of route definitions to the context 443 * 444 * @param routeDefinitions the route(s) definition to add 445 * @throws Exception if the route definitions could not be created for whatever reason 446 * @deprecated use {@link org.apache.camel.model.ModelCamelContext#addRouteDefinitions(java.util.Collection)} 447 */ 448 @Deprecated 449 void addRouteDefinitions(Collection<RouteDefinition> routeDefinitions) throws Exception; 450 451 /** 452 * Add a route definition to the context 453 * 454 * @param routeDefinition the route definition to add 455 * @throws Exception if the route definition could not be created for whatever reason 456 * @deprecated use {@link org.apache.camel.model.ModelCamelContext#addRouteDefinition(org.apache.camel.model.RouteDefinition)} 457 */ 458 @Deprecated 459 void addRouteDefinition(RouteDefinition routeDefinition) throws Exception; 460 461 /** 462 * Removes a collection of route definitions from the context - stopping any previously running 463 * routes if any of them are actively running 464 * 465 * @param routeDefinitions route(s) definitions to remove 466 * @throws Exception if the route definitions could not be removed for whatever reason 467 * @deprecated use {@link org.apache.camel.model.ModelCamelContext#removeRouteDefinitions(java.util.Collection)} 468 */ 469 @Deprecated 470 void removeRouteDefinitions(Collection<RouteDefinition> routeDefinitions) throws Exception; 471 472 /** 473 * Removes a route definition from the context - stopping any previously running 474 * routes if any of them are actively running 475 * 476 * @param routeDefinition route definition to remove 477 * @throws Exception if the route definition could not be removed for whatever reason 478 * @deprecated use {@link org.apache.camel.model.ModelCamelContext#removeRouteDefinition(org.apache.camel.model.RouteDefinition)} 479 */ 480 @Deprecated 481 void removeRouteDefinition(RouteDefinition routeDefinition) throws Exception; 482 483 /** 484 * Starts the given route if it has been previously stopped 485 * 486 * @param route the route to start 487 * @throws Exception is thrown if the route could not be started for whatever reason 488 * @deprecated use {@link org.apache.camel.model.ModelCamelContext#startRoute(org.apache.camel.model.RouteDefinition)} 489 */ 490 @Deprecated 491 void startRoute(RouteDefinition route) throws Exception; 492 493 /** 494 * Starts the given route if it has been previously stopped 495 * 496 * @param routeId the route id 497 * @throws Exception is thrown if the route could not be started for whatever reason 498 */ 499 void startRoute(String routeId) throws Exception; 500 501 /** 502 * Stops the given route. 503 * 504 * @param route the route to stop 505 * @throws Exception is thrown if the route could not be stopped for whatever reason 506 * @deprecated use {@link org.apache.camel.model.ModelCamelContext#stopRoute(org.apache.camel.model.RouteDefinition)} 507 */ 508 @Deprecated 509 void stopRoute(RouteDefinition route) throws Exception; 510 511 /** 512 * Stops the given route using {@link org.apache.camel.spi.ShutdownStrategy}. 513 * 514 * @param routeId the route id 515 * @throws Exception is thrown if the route could not be stopped for whatever reason 516 * @see #suspendRoute(String) 517 */ 518 void stopRoute(String routeId) throws Exception; 519 520 /** 521 * Stops the given route using {@link org.apache.camel.spi.ShutdownStrategy} with a specified timeout. 522 * 523 * @param routeId the route id 524 * @param timeout timeout 525 * @param timeUnit the unit to use 526 * @throws Exception is thrown if the route could not be stopped for whatever reason 527 * @see #suspendRoute(String, long, java.util.concurrent.TimeUnit) 528 */ 529 void stopRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception; 530 531 /** 532 * Stops the given route using {@link org.apache.camel.spi.ShutdownStrategy} with a specified timeout 533 * and optional abortAfterTimeout mode. 534 * 535 * @param routeId the route id 536 * @param timeout timeout 537 * @param timeUnit the unit to use 538 * @param abortAfterTimeout should abort shutdown after timeout 539 * @return <tt>true</tt> if the route is stopped before the timeout 540 * @throws Exception is thrown if the route could not be stopped for whatever reason 541 * @see #suspendRoute(String, long, java.util.concurrent.TimeUnit) 542 */ 543 boolean stopRoute(String routeId, long timeout, TimeUnit timeUnit, boolean abortAfterTimeout) throws Exception; 544 545 /** 546 * Shutdown and <b>removes</b> the given route using {@link org.apache.camel.spi.ShutdownStrategy}. 547 * 548 * @param routeId the route id 549 * @throws Exception is thrown if the route could not be shutdown for whatever reason 550 * @deprecated use {@link #stopRoute(String)} and {@link #removeRoute(String)} 551 */ 552 @Deprecated 553 void shutdownRoute(String routeId) throws Exception; 554 555 /** 556 * Shutdown and <b>removes</b> the given route using {@link org.apache.camel.spi.ShutdownStrategy} with a specified timeout. 557 * 558 * @param routeId the route id 559 * @param timeout timeout 560 * @param timeUnit the unit to use 561 * @throws Exception is thrown if the route could not be shutdown for whatever reason 562 * @deprecated use {@link #stopRoute(String, long, java.util.concurrent.TimeUnit)} and {@link #removeRoute(String)} 563 */ 564 @Deprecated 565 void shutdownRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception; 566 567 /** 568 * Removes the given route (the route <b>must</b> be stopped before it can be removed). 569 * <p/> 570 * <br/>A route which is removed will be unregistered from JMX, have its services stopped/shutdown and the route 571 * definition etc. will also be removed. All the resources related to the route will be stopped and cleared. 572 * <p/> 573 * <br/>End users can use this method to remove unwanted routes or temporary routes which no longer is in demand. 574 * 575 * @param routeId the route id 576 * @return <tt>true</tt> if the route was removed, <tt>false</tt> if the route could not be removed because its not stopped 577 * @throws Exception is thrown if the route could not be shutdown for whatever reason 578 */ 579 boolean removeRoute(String routeId) throws Exception; 580 581 /** 582 * Resumes the given route if it has been previously suspended 583 * <p/> 584 * If the route does <b>not</b> support suspension the route will be started instead 585 * 586 * @param routeId the route id 587 * @throws Exception is thrown if the route could not be resumed for whatever reason 588 */ 589 void resumeRoute(String routeId) throws Exception; 590 591 /** 592 * Suspends the given route using {@link org.apache.camel.spi.ShutdownStrategy}. 593 * <p/> 594 * Suspending a route is more gently than stopping, as the route consumers will be suspended (if they support) 595 * otherwise the consumers will be stopped. 596 * <p/> 597 * By suspending the route services will be kept running (if possible) and therefore its faster to resume the route. 598 * <p/> 599 * If the route does <b>not</b> support suspension the route will be stopped instead 600 * 601 * @param routeId the route id 602 * @throws Exception is thrown if the route could not be suspended for whatever reason 603 */ 604 void suspendRoute(String routeId) throws Exception; 605 606 /** 607 * Suspends the given route using {@link org.apache.camel.spi.ShutdownStrategy} with a specified timeout. 608 * <p/> 609 * Suspending a route is more gently than stopping, as the route consumers will be suspended (if they support) 610 * otherwise the consumers will be stopped. 611 * <p/> 612 * By suspending the route services will be kept running (if possible) and therefore its faster to resume the route. 613 * <p/> 614 * If the route does <b>not</b> support suspension the route will be stopped instead 615 * 616 * @param routeId the route id 617 * @param timeout timeout 618 * @param timeUnit the unit to use 619 * @throws Exception is thrown if the route could not be suspended for whatever reason 620 */ 621 void suspendRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception; 622 623 /** 624 * Returns the current status of the given route 625 * 626 * @param routeId the route id 627 * @return the status for the route 628 */ 629 ServiceStatus getRouteStatus(String routeId); 630 631 /** 632 * Indicates whether current thread is starting route(s). 633 * <p/> 634 * This can be useful to know by {@link LifecycleStrategy} or the likes, in case 635 * they need to react differently. 636 * 637 * @return <tt>true</tt> if current thread is starting route(s), or <tt>false</tt> if not. 638 */ 639 boolean isStartingRoutes(); 640 641 // Properties 642 //----------------------------------------------------------------------- 643 644 /** 645 * Returns the type converter used to coerce types from one type to another 646 * 647 * @return the converter 648 */ 649 TypeConverter getTypeConverter(); 650 651 /** 652 * Returns the type converter registry where type converters can be added or looked up 653 * 654 * @return the type converter registry 655 */ 656 TypeConverterRegistry getTypeConverterRegistry(); 657 658 /** 659 * Returns the registry used to lookup components by name and type such as the Spring ApplicationContext, 660 * JNDI or the OSGi Service Registry 661 * 662 * @return the registry 663 */ 664 Registry getRegistry(); 665 666 /** 667 * Returns the injector used to instantiate objects by type 668 * 669 * @return the injector 670 */ 671 Injector getInjector(); 672 673 /** 674 * Returns the management mbean assembler 675 * 676 * @return the mbean assembler 677 */ 678 ManagementMBeanAssembler getManagementMBeanAssembler(); 679 680 /** 681 * Returns the lifecycle strategies used to handle lifecycle notifications 682 * 683 * @return the lifecycle strategies 684 */ 685 List<LifecycleStrategy> getLifecycleStrategies(); 686 687 /** 688 * Adds the given lifecycle strategy to be used. 689 * 690 * @param lifecycleStrategy the strategy 691 */ 692 void addLifecycleStrategy(LifecycleStrategy lifecycleStrategy); 693 694 /** 695 * Resolves a language for creating expressions 696 * 697 * @param language name of the language 698 * @return the resolved language 699 */ 700 Language resolveLanguage(String language); 701 702 /** 703 * Parses the given text and resolve any property placeholders - using {{key}}. 704 * 705 * @param text the text such as an endpoint uri or the likes 706 * @return the text with resolved property placeholders 707 * @throws Exception is thrown if property placeholders was used and there was an error resolving them 708 */ 709 String resolvePropertyPlaceholders(String text) throws Exception; 710 711 /** 712 * Returns the configured property placeholder prefix token if and only if the context has 713 * property placeholder abilities, otherwise returns {@code null}. 714 * 715 * @return the prefix token or {@code null} 716 */ 717 String getPropertyPrefixToken(); 718 719 /** 720 * Returns the configured property placeholder suffix token if and only if the context has 721 * property placeholder abilities, otherwise returns {@code null}. 722 * 723 * @return the suffix token or {@code null} 724 */ 725 String getPropertySuffixToken(); 726 727 /** 728 * Gets a readonly list with the names of the languages currently registered. 729 * 730 * @return a readonly list with the names of the the languages 731 */ 732 List<String> getLanguageNames(); 733 734 /** 735 * Creates a new {@link ProducerTemplate} which is <b>started</b> and therefore ready to use right away. 736 * <p/> 737 * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html"> 738 * Why does Camel use too many threads with ProducerTemplate?</a> 739 * <p/> 740 * <b>Important:</b> Make sure to call {@link org.apache.camel.ProducerTemplate#stop()} when you are done using the template, 741 * to clean up any resources. 742 * <p/> 743 * Will use cache size defined in Camel property with key {@link Exchange#MAXIMUM_CACHE_POOL_SIZE}. 744 * If no key was defined then it will fallback to a default size of 1000. 745 * You can also use the {@link org.apache.camel.ProducerTemplate#setMaximumCacheSize(int)} method to use a custom value 746 * before starting the template. 747 * 748 * @return the template 749 * @throws RuntimeCamelException is thrown if error starting the template 750 */ 751 ProducerTemplate createProducerTemplate(); 752 753 /** 754 * Creates a new {@link ProducerTemplate} which is <b>started</b> and therefore ready to use right away. 755 * <p/> 756 * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html"> 757 * Why does Camel use too many threads with ProducerTemplate?</a> 758 * <p/> 759 * <b>Important:</b> Make sure to call {@link ProducerTemplate#stop()} when you are done using the template, 760 * to clean up any resources. 761 * 762 * @param maximumCacheSize the maximum cache size 763 * @return the template 764 * @throws RuntimeCamelException is thrown if error starting the template 765 */ 766 ProducerTemplate createProducerTemplate(int maximumCacheSize); 767 768 /** 769 * Creates a new {@link ConsumerTemplate} which is <b>started</b> and therefore ready to use right away. 770 * <p/> 771 * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html"> 772 * Why does Camel use too many threads with ProducerTemplate?</a> as it also applies for ConsumerTemplate. 773 * <p/> 774 * <b>Important:</b> Make sure to call {@link ConsumerTemplate#stop()} when you are done using the template, 775 * to clean up any resources. 776 * <p/> 777 * Will use cache size defined in Camel property with key {@link Exchange#MAXIMUM_CACHE_POOL_SIZE}. 778 * If no key was defined then it will fallback to a default size of 1000. 779 * You can also use the {@link org.apache.camel.ConsumerTemplate#setMaximumCacheSize(int)} method to use a custom value 780 * before starting the template. 781 * 782 * @return the template 783 * @throws RuntimeCamelException is thrown if error starting the template 784 */ 785 ConsumerTemplate createConsumerTemplate(); 786 787 /** 788 * Creates a new {@link ConsumerTemplate} which is <b>started</b> and therefore ready to use right away. 789 * <p/> 790 * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html"> 791 * Why does Camel use too many threads with ProducerTemplate?</a> as it also applies for ConsumerTemplate. 792 * <p/> 793 * <b>Important:</b> Make sure to call {@link ConsumerTemplate#stop()} when you are done using the template, 794 * to clean up any resources. 795 * 796 * @param maximumCacheSize the maximum cache size 797 * @return the template 798 * @throws RuntimeCamelException is thrown if error starting the template 799 */ 800 ConsumerTemplate createConsumerTemplate(int maximumCacheSize); 801 802 /** 803 * Adds the given interceptor strategy 804 * 805 * @param interceptStrategy the strategy 806 */ 807 void addInterceptStrategy(InterceptStrategy interceptStrategy); 808 809 /** 810 * Gets the interceptor strategies 811 * 812 * @return the list of current interceptor strategies 813 */ 814 List<InterceptStrategy> getInterceptStrategies(); 815 816 /** 817 * Gets the default error handler builder which is inherited by the routes 818 * @deprecated The return type will be switched to {@link ErrorHandlerFactory} in Camel 3.0 819 * 820 * @return the builder 821 */ 822 @Deprecated 823 ErrorHandlerBuilder getErrorHandlerBuilder(); 824 825 /** 826 * Sets the default error handler builder which is inherited by the routes 827 * 828 * @param errorHandlerBuilder the builder 829 */ 830 void setErrorHandlerBuilder(ErrorHandlerFactory errorHandlerBuilder); 831 832 /** 833 * Gets the default shared thread pool for error handlers which 834 * leverages this for asynchronous redelivery tasks. 835 */ 836 ScheduledExecutorService getErrorHandlerExecutorService(); 837 838 /** 839 * Sets the data formats that can be referenced in the routes. 840 * 841 * @param dataFormats the data formats 842 * @deprecated use {@link org.apache.camel.model.ModelCamelContext#setDataFormats(java.util.Map)} 843 */ 844 @Deprecated 845 void setDataFormats(Map<String, DataFormatDefinition> dataFormats); 846 847 /** 848 * Gets the data formats that can be referenced in the routes. 849 * 850 * @return the data formats available 851 * @deprecated use {@link org.apache.camel.model.ModelCamelContext#getDataFormats()} 852 */ 853 @Deprecated 854 Map<String, DataFormatDefinition> getDataFormats(); 855 856 /** 857 * Resolve a data format given its name 858 * 859 * @param name the data format name or a reference to it in the {@link Registry} 860 * @return the resolved data format, or <tt>null</tt> if not found 861 */ 862 DataFormat resolveDataFormat(String name); 863 864 /** 865 * Resolve a data format definition given its name 866 * 867 * @param name the data format definition name or a reference to it in the {@link Registry} 868 * @return the resolved data format definition, or <tt>null</tt> if not found 869 * @deprecated use {@link org.apache.camel.model.ModelCamelContext#resolveDataFormatDefinition(String)} 870 */ 871 @Deprecated 872 DataFormatDefinition resolveDataFormatDefinition(String name); 873 874 /** 875 * Gets the current data format resolver 876 * 877 * @return the resolver 878 */ 879 DataFormatResolver getDataFormatResolver(); 880 881 /** 882 * Sets a custom data format resolver 883 * 884 * @param dataFormatResolver the resolver 885 */ 886 void setDataFormatResolver(DataFormatResolver dataFormatResolver); 887 888 /** 889 * Sets the properties that can be referenced in the camel context 890 * 891 * @param properties properties 892 */ 893 void setProperties(Map<String, String> properties); 894 895 /** 896 * Gets the properties that can be referenced in the camel context 897 * 898 * @return the properties 899 */ 900 Map<String, String> getProperties(); 901 902 /** 903 * Gets the property value that can be referenced in the camel context 904 * 905 * @return the string value of property 906 */ 907 String getProperty(String name); 908 909 /** 910 * Gets the default FactoryFinder which will be used for the loading the factory class from META-INF 911 * 912 * @return the default factory finder 913 */ 914 FactoryFinder getDefaultFactoryFinder(); 915 916 /** 917 * Sets the factory finder resolver to use. 918 * 919 * @param resolver the factory finder resolver 920 */ 921 void setFactoryFinderResolver(FactoryFinderResolver resolver); 922 923 /** 924 * Gets the FactoryFinder which will be used for the loading the factory class from META-INF in the given path 925 * 926 * @param path the META-INF path 927 * @return the factory finder 928 * @throws NoFactoryAvailableException is thrown if a factory could not be found 929 */ 930 FactoryFinder getFactoryFinder(String path) throws NoFactoryAvailableException; 931 932 /** 933 * Returns the class resolver to be used for loading/lookup of classes. 934 * 935 * @return the resolver 936 */ 937 ClassResolver getClassResolver(); 938 939 /** 940 * Returns the package scanning class resolver 941 * 942 * @return the resolver 943 */ 944 PackageScanClassResolver getPackageScanClassResolver(); 945 946 /** 947 * Sets the class resolver to be use 948 * 949 * @param resolver the resolver 950 */ 951 void setClassResolver(ClassResolver resolver); 952 953 /** 954 * Sets the package scanning class resolver to use 955 * 956 * @param resolver the resolver 957 */ 958 void setPackageScanClassResolver(PackageScanClassResolver resolver); 959 960 /** 961 * Sets a pluggable service pool to use for {@link Producer} pooling. 962 * 963 * @param servicePool the pool 964 */ 965 void setProducerServicePool(ServicePool<Endpoint, Producer> servicePool); 966 967 /** 968 * Gets the service pool for {@link Producer} pooling. 969 * 970 * @return the service pool 971 */ 972 ServicePool<Endpoint, Producer> getProducerServicePool(); 973 974 /** 975 * Uses a custom node id factory when generating auto assigned ids to the nodes in the route definitions 976 * 977 * @param factory custom factory to use 978 */ 979 void setNodeIdFactory(NodeIdFactory factory); 980 981 /** 982 * Gets the node id factory 983 * 984 * @return the node id factory 985 */ 986 NodeIdFactory getNodeIdFactory(); 987 988 /** 989 * Gets the management strategy 990 * 991 * @return the management strategy 992 */ 993 ManagementStrategy getManagementStrategy(); 994 995 /** 996 * Sets the management strategy to use 997 * 998 * @param strategy the management strategy 999 */ 1000 void setManagementStrategy(ManagementStrategy strategy); 1001 1002 /** 1003 * Gets the default tracer 1004 * 1005 * @return the default tracer 1006 */ 1007 InterceptStrategy getDefaultTracer(); 1008 1009 /** 1010 * Sets a custom tracer to be used as the default tracer. 1011 * <p/> 1012 * <b>Note:</b> This must be set before any routes are created, 1013 * changing the default tracer for existing routes is not supported. 1014 * 1015 * @param tracer the custom tracer to use as default tracer 1016 */ 1017 void setDefaultTracer(InterceptStrategy tracer); 1018 1019 /** 1020 * Gets the default backlog tracer 1021 * 1022 * @return the default backlog tracer 1023 */ 1024 InterceptStrategy getDefaultBacklogTracer(); 1025 1026 /** 1027 * Sets a custom backlog tracer to be used as the default backlog tracer. 1028 * <p/> 1029 * <b>Note:</b> This must be set before any routes are created, 1030 * changing the default backlog tracer for existing routes is not supported. 1031 * 1032 * @param backlogTracer the custom tracer to use as default backlog tracer 1033 */ 1034 void setDefaultBacklogTracer(InterceptStrategy backlogTracer); 1035 1036 /** 1037 * Gets the default backlog debugger 1038 * 1039 * @return the default backlog debugger 1040 */ 1041 InterceptStrategy getDefaultBacklogDebugger(); 1042 1043 /** 1044 * Sets a custom backlog debugger to be used as the default backlog debugger. 1045 * <p/> 1046 * <b>Note:</b> This must be set before any routes are created, 1047 * changing the default backlog debugger for existing routes is not supported. 1048 * 1049 * @param backlogDebugger the custom debugger to use as default backlog debugger 1050 */ 1051 void setDefaultBacklogDebugger(InterceptStrategy backlogDebugger); 1052 1053 /** 1054 * Disables using JMX as {@link org.apache.camel.spi.ManagementStrategy}. 1055 * <p/> 1056 * <b>Important:</b> This method must be called <b>before</b> the {@link CamelContext} is started. 1057 * 1058 * @throws IllegalStateException is thrown if the {@link CamelContext} is not in stopped state. 1059 */ 1060 void disableJMX() throws IllegalStateException; 1061 1062 /** 1063 * Gets the inflight repository 1064 * 1065 * @return the repository 1066 */ 1067 InflightRepository getInflightRepository(); 1068 1069 /** 1070 * Sets a custom inflight repository to use 1071 * 1072 * @param repository the repository 1073 */ 1074 void setInflightRepository(InflightRepository repository); 1075 1076 /** 1077 * Gets the the application context class loader which may be helpful for running camel in other containers 1078 * 1079 * @return the application context class loader 1080 */ 1081 ClassLoader getApplicationContextClassLoader(); 1082 1083 /** 1084 * Sets the application context class loader 1085 * 1086 * @param classLoader the class loader 1087 */ 1088 void setApplicationContextClassLoader(ClassLoader classLoader); 1089 1090 /** 1091 * Gets the current shutdown strategy 1092 * 1093 * @return the strategy 1094 */ 1095 ShutdownStrategy getShutdownStrategy(); 1096 1097 /** 1098 * Sets a custom shutdown strategy 1099 * 1100 * @param shutdownStrategy the custom strategy 1101 */ 1102 void setShutdownStrategy(ShutdownStrategy shutdownStrategy); 1103 1104 /** 1105 * Gets the current {@link org.apache.camel.spi.ExecutorServiceManager} 1106 * 1107 * @return the manager 1108 */ 1109 ExecutorServiceManager getExecutorServiceManager(); 1110 1111 /** 1112 * Gets the current {@link org.apache.camel.spi.ExecutorServiceStrategy} 1113 * 1114 * @return the manager 1115 * @deprecated use {@link #getExecutorServiceManager()} 1116 */ 1117 @Deprecated 1118 org.apache.camel.spi.ExecutorServiceStrategy getExecutorServiceStrategy(); 1119 1120 /** 1121 * Sets a custom {@link org.apache.camel.spi.ExecutorServiceManager} 1122 * 1123 * @param executorServiceManager the custom manager 1124 */ 1125 void setExecutorServiceManager(ExecutorServiceManager executorServiceManager); 1126 1127 /** 1128 * Gets the current {@link org.apache.camel.spi.ProcessorFactory} 1129 * 1130 * @return the factory, can be <tt>null</tt> if no custom factory has been set 1131 */ 1132 ProcessorFactory getProcessorFactory(); 1133 1134 /** 1135 * Sets a custom {@link org.apache.camel.spi.ProcessorFactory} 1136 * 1137 * @param processorFactory the custom factory 1138 */ 1139 void setProcessorFactory(ProcessorFactory processorFactory); 1140 1141 /** 1142 * Gets the current {@link Debugger} 1143 * 1144 * @return the debugger 1145 */ 1146 Debugger getDebugger(); 1147 1148 /** 1149 * Sets a custom {@link Debugger} 1150 * 1151 * @param debugger the debugger 1152 */ 1153 void setDebugger(Debugger debugger); 1154 1155 /** 1156 * Gets the current {@link UuidGenerator} 1157 * 1158 * @return the uuidGenerator 1159 */ 1160 UuidGenerator getUuidGenerator(); 1161 1162 /** 1163 * Sets a custom {@link UuidGenerator} (should only be set once) 1164 * 1165 * @param uuidGenerator the UUID Generator 1166 */ 1167 void setUuidGenerator(UuidGenerator uuidGenerator); 1168 1169 /** 1170 * Whether or not type converters should be loaded lazy 1171 * 1172 * @return <tt>true</tt> to load lazy, <tt>false</tt> to load on startup 1173 * @deprecated this option is no longer supported, will be removed in a future Camel release. 1174 */ 1175 @Deprecated 1176 Boolean isLazyLoadTypeConverters(); 1177 1178 /** 1179 * Sets whether type converters should be loaded lazy 1180 * 1181 * @param lazyLoadTypeConverters <tt>true</tt> to load lazy, <tt>false</tt> to load on startup 1182 * @deprecated this option is no longer supported, will be removed in a future Camel release. 1183 */ 1184 @Deprecated 1185 void setLazyLoadTypeConverters(Boolean lazyLoadTypeConverters); 1186 1187 /** 1188 * Whether or not type converter statistics is enabled. 1189 * <p/> 1190 * By default the type converter utilization statistics is disabled. 1191 * <b>Notice:</b> If enabled then there is a slight performance impact under very heavy load. 1192 * 1193 * @return <tt>true</tt> if enabled, <tt>false</tt> if disabled (default). 1194 */ 1195 Boolean isTypeConverterStatisticsEnabled(); 1196 1197 /** 1198 * Sets whether or not type converter statistics is enabled. 1199 * <p/> 1200 * By default the type converter utilization statistics is disabled. 1201 * <b>Notice:</b> If enabled then there is a slight performance impact under very heavy load. 1202 * <p/> 1203 * You can enable/disable the statistics at runtime using the 1204 * {@link org.apache.camel.spi.TypeConverterRegistry#getStatistics()#setTypeConverterStatisticsEnabled(Boolean)} method, 1205 * or from JMX on the {@link org.apache.camel.api.management.mbean.ManagedTypeConverterRegistryMBean} mbean. 1206 * 1207 * @param typeConverterStatisticsEnabled <tt>true</tt> to enable, <tt>false</tt> to disable 1208 */ 1209 void setTypeConverterStatisticsEnabled(Boolean typeConverterStatisticsEnabled); 1210 1211 /** 1212 * Whether or not <a href="http://www.slf4j.org/api/org/slf4j/MDC.html">MDC</a> logging is being enabled. 1213 * 1214 * @return <tt>true</tt> if MDC logging is enabled 1215 */ 1216 Boolean isUseMDCLogging(); 1217 1218 /** 1219 * Set whether <a href="http://www.slf4j.org/api/org/slf4j/MDC.html">MDC</a> is enabled. 1220 * 1221 * @param useMDCLogging <tt>true</tt> to enable MDC logging, <tt>false</tt> to disable 1222 */ 1223 void setUseMDCLogging(Boolean useMDCLogging); 1224 1225 /** 1226 * Whether or not breadcrumb is enabled. 1227 * 1228 * @return <tt>true</tt> if breadcrumb is enabled 1229 */ 1230 Boolean isUseBreadcrumb(); 1231 1232 /** 1233 * Set whether breadcrumb is enabled. 1234 * 1235 * @param useBreadcrumb <tt>true</tt> to enable breadcrumb, <tt>false</tt> to disable 1236 */ 1237 void setUseBreadcrumb(Boolean useBreadcrumb); 1238 1239 /** 1240 * Find information about all the Camel components available in the classpath and {@link org.apache.camel.spi.Registry}. 1241 * 1242 * @return a map with the component name, and value with component details. 1243 * @throws LoadPropertiesException is thrown if error during classpath discovery of the components 1244 * @throws IOException is thrown if error during classpath discovery of the components 1245 */ 1246 Map<String, Properties> findComponents() throws LoadPropertiesException, IOException; 1247 1248 /** 1249 * Returns the HTML documentation for the given camel component 1250 */ 1251 String getComponentDocumentation(String componentName) throws IOException; 1252 1253 /** 1254 * Gets the {@link StreamCachingStrategy} to use. 1255 */ 1256 StreamCachingStrategy getStreamCachingStrategy(); 1257 1258 /** 1259 * Sets a custom {@link StreamCachingStrategy} to use. 1260 */ 1261 void setStreamCachingStrategy(StreamCachingStrategy streamCachingStrategy); 1262 1263 /** 1264 * Gets the {@link UnitOfWorkFactory} to use. 1265 */ 1266 UnitOfWorkFactory getUnitOfWorkFactory(); 1267 1268 /** 1269 * Sets a custom {@link UnitOfWorkFactory} to use. 1270 */ 1271 void setUnitOfWorkFactory(UnitOfWorkFactory unitOfWorkFactory); 1272 1273 }