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