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         * Method to signal to {@link CamelContext} that the process to initialize setup routes is in progress.
371         *
372         * @param done <tt>false</tt> to start the process, call again with <tt>true</tt> to signal its done.
373         * @see #isSetupRoutes()
374         */
375        void setupRoutes(boolean done);
376    
377        /**
378         * Returns a list of the current route definitions
379         *
380         * @return list of the current route definitions
381         * @deprecated use {@link org.apache.camel.model.ModelCamelContext#getRouteDefinitions()}
382         */
383        @Deprecated
384        List<RouteDefinition> getRouteDefinitions();
385    
386        /**
387         * Gets the route definition with the given id
388         *
389         * @param id id of the route
390         * @return the route definition or <tt>null</tt> if not found
391         * @deprecated use {@link org.apache.camel.model.ModelCamelContext#getRouteDefinition(String)}
392         */
393        @Deprecated
394        RouteDefinition getRouteDefinition(String id);
395    
396        /**
397         * Returns the order in which the route inputs was started.
398         * <p/>
399         * The order may not be according to the startupOrder defined on the route.
400         * For example a route could be started manually later, or new routes added at runtime.
401         *
402         * @return a list in the order how routes was started
403         */
404        List<RouteStartupOrder> getRouteStartupOrder();
405    
406        /**
407         * Returns the current routes in this context
408         *
409         * @return the current routes
410         */
411        List<Route> getRoutes();
412    
413        /**
414         * Gets the route with the given id
415         *
416         * @param id id of the route
417         * @return the route or <tt>null</tt> if not found
418         */
419        Route getRoute(String id);
420    
421        /**
422         * Adds a collection of routes to this context using the given builder
423         * to build them.
424         * <p/>
425         * <b>Important:</b> The added routes will <b>only</b> be started, if {@link CamelContext}
426         * is already started. You may want to check the state of {@link CamelContext} before
427         * adding the routes, using the {@link org.apache.camel.CamelContext#getStatus()} method.
428         * <p/>
429         * <b>Important: </b> Each route in the same {@link org.apache.camel.CamelContext} must have an <b>unique</b> route id.
430         * If you use the API from {@link org.apache.camel.CamelContext} or {@link org.apache.camel.model.ModelCamelContext} to add routes, then any
431         * new routes which has a route id that matches an old route, then the old route is replaced by the new route.
432         *
433         * @param builder the builder which will create the routes and add them to this context
434         * @throws Exception if the routes could not be created for whatever reason
435         */
436        void addRoutes(RoutesBuilder builder) throws Exception;
437    
438        /**
439         * Loads a collection of route definitions from the given {@link java.io.InputStream}.
440         *
441         * @param is input stream with the route(s) definition to add
442         * @throws Exception if the route definitions could not be loaded for whatever reason
443         * @return the route definitions
444         * @deprecated use {@link org.apache.camel.model.ModelCamelContext#loadRoutesDefinition(java.io.InputStream)}
445         */
446        @Deprecated
447        RoutesDefinition loadRoutesDefinition(InputStream is) throws Exception;
448    
449        /**
450         * Adds a collection of route definitions to the context
451         *
452         * @param routeDefinitions the route(s) definition to add
453         * @throws Exception if the route definitions could not be created for whatever reason
454         * @deprecated use {@link org.apache.camel.model.ModelCamelContext#addRouteDefinitions(java.util.Collection)}
455         */
456        @Deprecated
457        void addRouteDefinitions(Collection<RouteDefinition> routeDefinitions) throws Exception;
458    
459        /**
460         * Add a route definition to the context
461         *
462         * @param routeDefinition the route definition to add
463         * @throws Exception if the route definition could not be created for whatever reason
464         * @deprecated use {@link org.apache.camel.model.ModelCamelContext#addRouteDefinition(org.apache.camel.model.RouteDefinition)}
465         */
466        @Deprecated
467        void addRouteDefinition(RouteDefinition routeDefinition) throws Exception;
468    
469        /**
470         * Removes a collection of route definitions from the context - stopping any previously running
471         * routes if any of them are actively running
472         *
473         * @param routeDefinitions route(s) definitions to remove
474         * @throws Exception if the route definitions could not be removed for whatever reason
475         * @deprecated use {@link org.apache.camel.model.ModelCamelContext#removeRouteDefinitions(java.util.Collection)}
476         */
477        @Deprecated
478        void removeRouteDefinitions(Collection<RouteDefinition> routeDefinitions) throws Exception;
479    
480        /**
481         * Removes a route definition from the context - stopping any previously running
482         * routes if any of them are actively running
483         *
484         * @param routeDefinition route definition to remove
485         * @throws Exception if the route definition could not be removed for whatever reason
486         * @deprecated use {@link org.apache.camel.model.ModelCamelContext#removeRouteDefinition(org.apache.camel.model.RouteDefinition)}
487         */
488        @Deprecated
489        void removeRouteDefinition(RouteDefinition routeDefinition) throws Exception;
490    
491        /**
492         * Starts the given route if it has been previously stopped
493         *
494         * @param route the route to start
495         * @throws Exception is thrown if the route could not be started for whatever reason
496         * @deprecated use {@link org.apache.camel.model.ModelCamelContext#startRoute(org.apache.camel.model.RouteDefinition)}
497         */
498        @Deprecated
499        void startRoute(RouteDefinition route) throws Exception;
500    
501        /**
502         * Starts all the routes which currently is not started.
503         *
504         * @throws Exception is thrown if a route could not be started for whatever reason
505         */
506        void startAllRoutes() throws Exception;
507    
508        /**
509         * Starts the given route if it has been previously stopped
510         *
511         * @param routeId the route id
512         * @throws Exception is thrown if the route could not be started for whatever reason
513         */
514        void startRoute(String routeId) throws Exception;
515    
516        /**
517         * Stops the given route.
518         *
519         * @param route the route to stop
520         * @throws Exception is thrown if the route could not be stopped for whatever reason
521         * @deprecated use {@link org.apache.camel.model.ModelCamelContext#stopRoute(org.apache.camel.model.RouteDefinition)}
522         */
523        @Deprecated
524        void stopRoute(RouteDefinition route) throws Exception;
525    
526        /**
527         * Stops the given route using {@link org.apache.camel.spi.ShutdownStrategy}.
528         *
529         * @param routeId the route id
530         * @throws Exception is thrown if the route could not be stopped for whatever reason
531         * @see #suspendRoute(String)
532         */
533        void stopRoute(String routeId) throws Exception;
534    
535        /**
536         * Stops the given route using {@link org.apache.camel.spi.ShutdownStrategy} with a specified timeout.
537         *
538         * @param routeId the route id
539         * @param timeout  timeout
540         * @param timeUnit the unit to use
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        void stopRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception;
545    
546        /**
547         * Stops the given route using {@link org.apache.camel.spi.ShutdownStrategy} with a specified timeout 
548         * and optional abortAfterTimeout mode.
549         *
550         * @param routeId the route id
551         * @param timeout  timeout
552         * @param timeUnit the unit to use
553         * @param abortAfterTimeout should abort shutdown after timeout
554         * @return <tt>true</tt> if the route is stopped before the timeout
555         * @throws Exception is thrown if the route could not be stopped for whatever reason
556         * @see #suspendRoute(String, long, java.util.concurrent.TimeUnit)
557         */
558        boolean stopRoute(String routeId, long timeout, TimeUnit timeUnit, boolean abortAfterTimeout) throws Exception;
559        
560        /**
561         * Shutdown and <b>removes</b> the given route using {@link org.apache.camel.spi.ShutdownStrategy}.
562         *
563         * @param routeId the route id
564         * @throws Exception is thrown if the route could not be shutdown for whatever reason
565         * @deprecated use {@link #stopRoute(String)} and {@link #removeRoute(String)}
566         */
567        @Deprecated
568        void shutdownRoute(String routeId) throws Exception;
569    
570        /**
571         * Shutdown and <b>removes</b> the given route using {@link org.apache.camel.spi.ShutdownStrategy} with a specified timeout.
572         *
573         * @param routeId  the route id
574         * @param timeout  timeout
575         * @param timeUnit the unit to use
576         * @throws Exception is thrown if the route could not be shutdown for whatever reason
577         * @deprecated use {@link #stopRoute(String, long, java.util.concurrent.TimeUnit)} and {@link #removeRoute(String)}
578         */
579        @Deprecated
580        void shutdownRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception;
581    
582        /**
583         * Removes the given route (the route <b>must</b> be stopped before it can be removed).
584         * <p/>
585         * <br/>A route which is removed will be unregistered from JMX, have its services stopped/shutdown and the route
586         * definition etc. will also be removed. All the resources related to the route will be stopped and cleared.
587         * <p/>
588         * <br/>End users can use this method to remove unwanted routes or temporary routes which no longer is in demand.
589         *
590         * @param routeId the route id
591         * @return <tt>true</tt> if the route was removed, <tt>false</tt> if the route could not be removed because its not stopped
592         * @throws Exception is thrown if the route could not be shutdown for whatever reason
593         */
594        boolean removeRoute(String routeId) throws Exception;
595    
596        /**
597         * Resumes the given route if it has been previously suspended
598         * <p/>
599         * If the route does <b>not</b> support suspension the route will be started instead
600         *
601         * @param routeId the route id
602         * @throws Exception is thrown if the route could not be resumed for whatever reason
603         */
604        void resumeRoute(String routeId) throws Exception;
605    
606        /**
607         * Suspends the given route using {@link org.apache.camel.spi.ShutdownStrategy}.
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         * @throws Exception is thrown if the route could not be suspended for whatever reason
618         */
619        void suspendRoute(String routeId) throws Exception;
620    
621        /**
622         * Suspends the given route using {@link org.apache.camel.spi.ShutdownStrategy} with a specified timeout.
623         * <p/>
624         * Suspending a route is more gently than stopping, as the route consumers will be suspended (if they support)
625         * otherwise the consumers will be stopped.
626         * <p/>
627         * By suspending the route services will be kept running (if possible) and therefore its faster to resume the route.
628         * <p/>
629         * If the route does <b>not</b> support suspension the route will be stopped instead
630         *
631         * @param routeId  the route id
632         * @param timeout  timeout
633         * @param timeUnit the unit to use
634         * @throws Exception is thrown if the route could not be suspended for whatever reason
635         */
636        void suspendRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception;
637    
638        /**
639         * Returns the current status of the given route
640         *
641         * @param routeId the route id
642         * @return the status for the route
643         */
644        ServiceStatus getRouteStatus(String routeId);
645    
646        /**
647         * Indicates whether current thread is starting route(s).
648         * <p/>
649         * This can be useful to know by {@link LifecycleStrategy} or the likes, in case
650         * they need to react differently.
651         *
652         * @return <tt>true</tt> if current thread is starting route(s), or <tt>false</tt> if not.
653         */
654        boolean isStartingRoutes();
655    
656        /**
657         * Indicates whether current thread is setting up route(s) as part of starting Camel from spring/blueprint.
658         * <p/>
659         * This can be useful to know by {@link LifecycleStrategy} or the likes, in case
660         * they need to react differently.
661         * <p/>
662         * As the startup procedure of {@link CamelContext} is slightly different when using plain Java versus
663         * Spring or Blueprint, then we need to know when Spring/Blueprint is setting up the routes, which
664         * can happen after the {@link CamelContext} itself is in started state, due the asynchronous event nature
665         * of especially Blueprint.
666         *
667         * @return <tt>true</tt> if current thread is setting up route(s), or <tt>false</tt> if not.
668         */
669        boolean isSetupRoutes();
670    
671        // Properties
672        //-----------------------------------------------------------------------
673    
674        /**
675         * Returns the type converter used to coerce types from one type to another
676         *
677         * @return the converter
678         */
679        TypeConverter getTypeConverter();
680    
681        /**
682         * Returns the type converter registry where type converters can be added or looked up
683         *
684         * @return the type converter registry
685         */
686        TypeConverterRegistry getTypeConverterRegistry();
687    
688        /**
689         * Returns the registry used to lookup components by name and type such as the Spring ApplicationContext,
690         * JNDI or the OSGi Service Registry
691         *
692         * @return the registry
693         */
694        Registry getRegistry();
695    
696        /**
697         * Returns the injector used to instantiate objects by type
698         *
699         * @return the injector
700         */
701        Injector getInjector();
702    
703        /**
704         * Returns the management mbean assembler
705         *
706         * @return the mbean assembler
707         */
708        ManagementMBeanAssembler getManagementMBeanAssembler();
709    
710        /**
711         * Returns the lifecycle strategies used to handle lifecycle notifications
712         *
713         * @return the lifecycle strategies
714         */
715        List<LifecycleStrategy> getLifecycleStrategies();
716    
717        /**
718         * Adds the given lifecycle strategy to be used.
719         *
720         * @param lifecycleStrategy the strategy
721         */
722        void addLifecycleStrategy(LifecycleStrategy lifecycleStrategy);
723    
724        /**
725         * Resolves a language for creating expressions
726         *
727         * @param language name of the language
728         * @return the resolved language
729         */
730        Language resolveLanguage(String language);
731    
732        /**
733         * Parses the given text and resolve any property placeholders - using {{key}}.
734         *
735         * @param text the text such as an endpoint uri or the likes
736         * @return the text with resolved property placeholders
737         * @throws Exception is thrown if property placeholders was used and there was an error resolving them
738         */
739        String resolvePropertyPlaceholders(String text) throws Exception;
740        
741        /**
742         * Returns the configured property placeholder prefix token if and only if the context has
743         * property placeholder abilities, otherwise returns {@code null}.
744         * 
745         * @return the prefix token or {@code null}
746         */
747        String getPropertyPrefixToken();
748        
749        /**
750         * Returns the configured property placeholder suffix token if and only if the context has
751         * property placeholder abilities, otherwise returns {@code null}.
752         * 
753         * @return the suffix token or {@code null}
754         */
755        String getPropertySuffixToken();
756    
757        /**
758         * Gets a readonly list with the names of the languages currently registered.
759         *
760         * @return a readonly list with the names of the the languages
761         */
762        List<String> getLanguageNames();
763    
764        /**
765         * Creates a new {@link ProducerTemplate} which is <b>started</b> and therefore ready to use right away.
766         * <p/>
767         * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">
768         * Why does Camel use too many threads with ProducerTemplate?</a>
769         * <p/>
770         * <b>Important:</b> Make sure to call {@link org.apache.camel.ProducerTemplate#stop()} when you are done using the template,
771         * to clean up any resources.
772         * <p/>
773         * Will use cache size defined in Camel property with key {@link Exchange#MAXIMUM_CACHE_POOL_SIZE}.
774         * If no key was defined then it will fallback to a default size of 1000.
775         * You can also use the {@link org.apache.camel.ProducerTemplate#setMaximumCacheSize(int)} method to use a custom value
776         * before starting the template.
777         *
778         * @return the template
779         * @throws RuntimeCamelException is thrown if error starting the template
780         */
781        ProducerTemplate createProducerTemplate();
782    
783        /**
784         * Creates a new {@link ProducerTemplate} which is <b>started</b> and therefore ready to use right away.
785         * <p/>
786         * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">
787         * Why does Camel use too many threads with ProducerTemplate?</a>
788         * <p/>
789         * <b>Important:</b> Make sure to call {@link ProducerTemplate#stop()} when you are done using the template,
790         * to clean up any resources.
791         *
792         * @param maximumCacheSize the maximum cache size
793         * @return the template
794         * @throws RuntimeCamelException is thrown if error starting the template
795         */
796        ProducerTemplate createProducerTemplate(int maximumCacheSize);
797    
798        /**
799         * Creates a new {@link ConsumerTemplate} which is <b>started</b> and therefore ready to use right away.
800         * <p/>
801         * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">
802         * Why does Camel use too many threads with ProducerTemplate?</a> as it also applies for ConsumerTemplate.
803         * <p/>
804         * <b>Important:</b> Make sure to call {@link ConsumerTemplate#stop()} when you are done using the template,
805         * to clean up any resources.
806         * <p/>
807         * Will use cache size defined in Camel property with key {@link Exchange#MAXIMUM_CACHE_POOL_SIZE}.
808         * If no key was defined then it will fallback to a default size of 1000.
809         * You can also use the {@link org.apache.camel.ConsumerTemplate#setMaximumCacheSize(int)} method to use a custom value
810         * before starting the template.
811         *
812         * @return the template
813         * @throws RuntimeCamelException is thrown if error starting the template
814         */
815        ConsumerTemplate createConsumerTemplate();
816    
817        /**
818         * Creates a new {@link ConsumerTemplate} which is <b>started</b> and therefore ready to use right away.
819         * <p/>
820         * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">
821         * Why does Camel use too many threads with ProducerTemplate?</a> as it also applies for ConsumerTemplate.
822         * <p/>
823         * <b>Important:</b> Make sure to call {@link ConsumerTemplate#stop()} when you are done using the template,
824         * to clean up any resources.
825         *
826         * @param maximumCacheSize the maximum cache size
827         * @return the template
828         * @throws RuntimeCamelException is thrown if error starting the template
829         */
830        ConsumerTemplate createConsumerTemplate(int maximumCacheSize);
831    
832        /**
833         * Adds the given interceptor strategy
834         *
835         * @param interceptStrategy the strategy
836         */
837        void addInterceptStrategy(InterceptStrategy interceptStrategy);
838    
839        /**
840         * Gets the interceptor strategies
841         *
842         * @return the list of current interceptor strategies
843         */
844        List<InterceptStrategy> getInterceptStrategies();
845    
846        /**
847         * Gets the default error handler builder which is inherited by the routes
848         * @deprecated The return type will be switched to {@link ErrorHandlerFactory} in Camel 3.0
849         *
850         * @return the builder
851         */
852        @Deprecated
853        ErrorHandlerBuilder getErrorHandlerBuilder();
854    
855        /**
856         * Sets the default error handler builder which is inherited by the routes
857         *
858         * @param errorHandlerBuilder the builder
859         */
860        void setErrorHandlerBuilder(ErrorHandlerFactory errorHandlerBuilder);
861    
862        /**
863         * Gets the default shared thread pool for error handlers which
864         * leverages this for asynchronous redelivery tasks.
865         */
866        ScheduledExecutorService getErrorHandlerExecutorService();
867    
868        /**
869         * Sets the data formats that can be referenced in the routes.
870         *
871         * @param dataFormats the data formats
872         * @deprecated use {@link org.apache.camel.model.ModelCamelContext#setDataFormats(java.util.Map)}
873         */
874        @Deprecated
875        void setDataFormats(Map<String, DataFormatDefinition> dataFormats);
876    
877        /**
878         * Gets the data formats that can be referenced in the routes.
879         *
880         * @return the data formats available
881         * @deprecated use {@link org.apache.camel.model.ModelCamelContext#getDataFormats()}
882         */
883        @Deprecated
884        Map<String, DataFormatDefinition> getDataFormats();
885    
886        /**
887         * Resolve a data format given its name
888         *
889         * @param name the data format name or a reference to it in the {@link Registry}
890         * @return the resolved data format, or <tt>null</tt> if not found
891         */
892        DataFormat resolveDataFormat(String name);
893    
894        /**
895         * Resolve a data format definition given its name
896         *
897         * @param name the data format definition name or a reference to it in the {@link Registry}
898         * @return the resolved data format definition, or <tt>null</tt> if not found
899         * @deprecated use {@link org.apache.camel.model.ModelCamelContext#resolveDataFormatDefinition(String)}
900         */
901        @Deprecated
902        DataFormatDefinition resolveDataFormatDefinition(String name);
903    
904        /**
905         * Gets the current data format resolver
906         *
907         * @return the resolver
908         */
909        DataFormatResolver getDataFormatResolver();
910    
911        /**
912         * Sets a custom data format resolver
913         *
914         * @param dataFormatResolver the resolver
915         */
916        void setDataFormatResolver(DataFormatResolver dataFormatResolver);
917    
918        /**
919         * Sets the properties that can be referenced in the camel context
920         *
921         * @param properties properties
922         */
923        void setProperties(Map<String, String> properties);
924    
925        /**
926         * Gets the properties that can be referenced in the camel context
927         *
928         * @return the properties
929         */
930        Map<String, String> getProperties();
931    
932        /**
933         * Gets the property value that can be referenced in the camel context
934         *
935         * @return the string value of property
936         */
937        String getProperty(String name);
938        
939        /**
940         * Gets the default FactoryFinder which will be used for the loading the factory class from META-INF
941         *
942         * @return the default factory finder
943         */
944        FactoryFinder getDefaultFactoryFinder();
945    
946        /**
947         * Sets the factory finder resolver to use.
948         *
949         * @param resolver the factory finder resolver
950         */
951        void setFactoryFinderResolver(FactoryFinderResolver resolver);
952    
953        /**
954         * Gets the FactoryFinder which will be used for the loading the factory class from META-INF in the given path
955         *
956         * @param path the META-INF path
957         * @return the factory finder
958         * @throws NoFactoryAvailableException is thrown if a factory could not be found
959         */
960        FactoryFinder getFactoryFinder(String path) throws NoFactoryAvailableException;
961    
962        /**
963         * Returns the class resolver to be used for loading/lookup of classes.
964         *
965         * @return the resolver
966         */
967        ClassResolver getClassResolver();
968    
969        /**
970         * Returns the package scanning class resolver
971         *
972         * @return the resolver
973         */
974        PackageScanClassResolver getPackageScanClassResolver();
975    
976        /**
977         * Sets the class resolver to be use
978         *
979         * @param resolver the resolver
980         */
981        void setClassResolver(ClassResolver resolver);
982    
983        /**
984         * Sets the package scanning class resolver to use
985         *
986         * @param resolver the resolver
987         */
988        void setPackageScanClassResolver(PackageScanClassResolver resolver);
989    
990        /**
991         * Sets a pluggable service pool to use for {@link Producer} pooling.
992         *
993         * @param servicePool the pool
994         */
995        void setProducerServicePool(ServicePool<Endpoint, Producer> servicePool);
996    
997        /**
998         * Gets the service pool for {@link Producer} pooling.
999         *
1000         * @return the service pool
1001         */
1002        ServicePool<Endpoint, Producer> getProducerServicePool();
1003    
1004        /**
1005         * Uses a custom node id factory when generating auto assigned ids to the nodes in the route definitions
1006         *
1007         * @param factory custom factory to use
1008         */
1009        void setNodeIdFactory(NodeIdFactory factory);
1010    
1011        /**
1012         * Gets the node id factory
1013         *
1014         * @return the node id factory
1015         */
1016        NodeIdFactory getNodeIdFactory();
1017    
1018        /**
1019         * Gets the management strategy
1020         *
1021         * @return the management strategy
1022         */
1023        ManagementStrategy getManagementStrategy();
1024    
1025        /**
1026         * Sets the management strategy to use
1027         *
1028         * @param strategy the management strategy
1029         */
1030        void setManagementStrategy(ManagementStrategy strategy);
1031    
1032        /**
1033         * Gets the default tracer
1034         *
1035         * @return the default tracer
1036         */
1037        InterceptStrategy getDefaultTracer();
1038    
1039        /**
1040         * Sets a custom tracer to be used as the default tracer.
1041         * <p/>
1042         * <b>Note:</b> This must be set before any routes are created,
1043         * changing the default tracer for existing routes is not supported.
1044         *
1045         * @param tracer the custom tracer to use as default tracer
1046         */
1047        void setDefaultTracer(InterceptStrategy tracer);
1048    
1049        /**
1050         * Gets the default backlog tracer
1051         *
1052         * @return the default backlog tracer
1053         */
1054        InterceptStrategy getDefaultBacklogTracer();
1055    
1056        /**
1057         * Sets a custom backlog tracer to be used as the default backlog tracer.
1058         * <p/>
1059         * <b>Note:</b> This must be set before any routes are created,
1060         * changing the default backlog tracer for existing routes is not supported.
1061         *
1062         * @param backlogTracer the custom tracer to use as default backlog tracer
1063         */
1064        void setDefaultBacklogTracer(InterceptStrategy backlogTracer);
1065    
1066        /**
1067         * Gets the default backlog debugger
1068         *
1069         * @return the default backlog debugger
1070         */
1071        InterceptStrategy getDefaultBacklogDebugger();
1072    
1073        /**
1074         * Sets a custom backlog debugger to be used as the default backlog debugger.
1075         * <p/>
1076         * <b>Note:</b> This must be set before any routes are created,
1077         * changing the default backlog debugger for existing routes is not supported.
1078         *
1079         * @param backlogDebugger the custom debugger to use as default backlog debugger
1080         */
1081        void setDefaultBacklogDebugger(InterceptStrategy backlogDebugger);
1082    
1083        /**
1084         * Disables using JMX as {@link org.apache.camel.spi.ManagementStrategy}.
1085         * <p/>
1086         * <b>Important:</b> This method must be called <b>before</b> the {@link CamelContext} is started.
1087         *
1088         * @throws IllegalStateException is thrown if the {@link CamelContext} is not in stopped state.
1089         */
1090        void disableJMX() throws IllegalStateException;
1091    
1092        /**
1093         * Gets the inflight repository
1094         *
1095         * @return the repository
1096         */
1097        InflightRepository getInflightRepository();
1098    
1099        /**
1100         * Sets a custom inflight repository to use
1101         *
1102         * @param repository the repository
1103         */
1104        void setInflightRepository(InflightRepository repository);
1105    
1106        /**
1107         * Gets the the application context class loader which may be helpful for running camel in other containers
1108         *
1109         * @return the application context class loader
1110         */
1111        ClassLoader getApplicationContextClassLoader();
1112    
1113        /**
1114         * Sets the application context class loader
1115         *
1116         * @param classLoader the class loader
1117         */
1118        void setApplicationContextClassLoader(ClassLoader classLoader);
1119    
1120        /**
1121         * Gets the current shutdown strategy
1122         *
1123         * @return the strategy
1124         */
1125        ShutdownStrategy getShutdownStrategy();
1126    
1127        /**
1128         * Sets a custom shutdown strategy
1129         *
1130         * @param shutdownStrategy the custom strategy
1131         */
1132        void setShutdownStrategy(ShutdownStrategy shutdownStrategy);
1133    
1134        /**
1135         * Gets the current {@link org.apache.camel.spi.ExecutorServiceManager}
1136         *
1137         * @return the manager
1138         */
1139        ExecutorServiceManager getExecutorServiceManager();
1140    
1141        /**
1142         * Gets the current {@link org.apache.camel.spi.ExecutorServiceStrategy}
1143         *
1144         * @return the manager
1145         * @deprecated use {@link #getExecutorServiceManager()}
1146         */
1147        @Deprecated
1148        org.apache.camel.spi.ExecutorServiceStrategy getExecutorServiceStrategy();
1149    
1150        /**
1151         * Sets a custom {@link org.apache.camel.spi.ExecutorServiceManager}
1152         *
1153         * @param executorServiceManager the custom manager
1154         */
1155        void setExecutorServiceManager(ExecutorServiceManager executorServiceManager);
1156    
1157        /**
1158         * Gets the current {@link org.apache.camel.spi.ProcessorFactory}
1159         *
1160         * @return the factory, can be <tt>null</tt> if no custom factory has been set
1161         */
1162        ProcessorFactory getProcessorFactory();
1163    
1164        /**
1165         * Sets a custom {@link org.apache.camel.spi.ProcessorFactory}
1166         *
1167         * @param processorFactory the custom factory
1168         */
1169        void setProcessorFactory(ProcessorFactory processorFactory);
1170    
1171        /**
1172         * Gets the current {@link Debugger}
1173         *
1174         * @return the debugger
1175         */
1176        Debugger getDebugger();
1177    
1178        /**
1179         * Sets a custom {@link Debugger}
1180         *
1181         * @param debugger the debugger
1182         */
1183        void setDebugger(Debugger debugger);
1184    
1185        /**
1186         * Gets the current {@link UuidGenerator}
1187         *
1188         * @return the uuidGenerator
1189         */
1190        UuidGenerator getUuidGenerator();
1191        
1192        /**
1193         * Sets a custom {@link UuidGenerator} (should only be set once) 
1194         *
1195         * @param uuidGenerator the UUID Generator
1196         */
1197        void setUuidGenerator(UuidGenerator uuidGenerator);
1198    
1199        /**
1200         * Whether or not type converters should be loaded lazy
1201         *
1202         * @return <tt>true</tt> to load lazy, <tt>false</tt> to load on startup
1203         * @deprecated this option is no longer supported, will be removed in a future Camel release.
1204         */
1205        @Deprecated
1206        Boolean isLazyLoadTypeConverters();
1207    
1208        /**
1209         * Sets whether type converters should be loaded lazy
1210         *
1211         * @param lazyLoadTypeConverters <tt>true</tt> to load lazy, <tt>false</tt> to load on startup
1212         * @deprecated this option is no longer supported, will be removed in a future Camel release.
1213         */
1214        @Deprecated
1215        void setLazyLoadTypeConverters(Boolean lazyLoadTypeConverters);
1216    
1217        /**
1218         * Whether or not type converter statistics is enabled.
1219         * <p/>
1220         * By default the type converter utilization statistics is disabled.
1221         * <b>Notice:</b> If enabled then there is a slight performance impact under very heavy load.
1222         *
1223         * @return <tt>true</tt> if enabled, <tt>false</tt> if disabled (default).
1224         */
1225        Boolean isTypeConverterStatisticsEnabled();
1226    
1227        /**
1228         * Sets whether or not type converter statistics is enabled.
1229         * <p/>
1230         * By default the type converter utilization statistics is disabled.
1231         * <b>Notice:</b> If enabled then there is a slight performance impact under very heavy load.
1232         * <p/>
1233         * You can enable/disable the statistics at runtime using the
1234         * {@link org.apache.camel.spi.TypeConverterRegistry#getStatistics()#setTypeConverterStatisticsEnabled(Boolean)} method,
1235         * or from JMX on the {@link org.apache.camel.api.management.mbean.ManagedTypeConverterRegistryMBean} mbean.
1236         *
1237         * @param typeConverterStatisticsEnabled <tt>true</tt> to enable, <tt>false</tt> to disable
1238         */
1239        void setTypeConverterStatisticsEnabled(Boolean typeConverterStatisticsEnabled);
1240    
1241        /**
1242         * Whether or not <a href="http://www.slf4j.org/api/org/slf4j/MDC.html">MDC</a> logging is being enabled.
1243         *
1244         * @return <tt>true</tt> if MDC logging is enabled
1245         */
1246        Boolean isUseMDCLogging();
1247    
1248        /**
1249         * Set whether <a href="http://www.slf4j.org/api/org/slf4j/MDC.html">MDC</a> is enabled.
1250         *
1251         * @param useMDCLogging <tt>true</tt> to enable MDC logging, <tt>false</tt> to disable
1252         */
1253        void setUseMDCLogging(Boolean useMDCLogging);
1254    
1255        /**
1256         * Whether or not breadcrumb is enabled.
1257         *
1258         * @return <tt>true</tt> if breadcrumb is enabled
1259         */
1260        Boolean isUseBreadcrumb();
1261    
1262        /**
1263         * Set whether breadcrumb is enabled.
1264         *
1265         * @param useBreadcrumb <tt>true</tt> to enable breadcrumb, <tt>false</tt> to disable
1266         */
1267        void setUseBreadcrumb(Boolean useBreadcrumb);
1268    
1269        /**
1270         * Find information about all the Camel components available in the classpath and {@link org.apache.camel.spi.Registry}.
1271         *
1272         * @return a map with the component name, and value with component details.
1273         * @throws LoadPropertiesException is thrown if error during classpath discovery of the components
1274         * @throws IOException is thrown if error during classpath discovery of the components
1275         */
1276        Map<String, Properties> findComponents() throws LoadPropertiesException, IOException;
1277    
1278        /**
1279         * Returns the HTML documentation for the given camel component
1280         */
1281        String getComponentDocumentation(String componentName) throws IOException;
1282    
1283        /**
1284         * Gets the {@link StreamCachingStrategy} to use.
1285         */
1286        StreamCachingStrategy getStreamCachingStrategy();
1287    
1288        /**
1289         * Sets a custom {@link StreamCachingStrategy} to use.
1290         */
1291        void setStreamCachingStrategy(StreamCachingStrategy streamCachingStrategy);
1292    
1293        /**
1294         * Gets the {@link UnitOfWorkFactory} to use.
1295         */
1296        UnitOfWorkFactory getUnitOfWorkFactory();
1297    
1298        /**
1299         * Sets a custom {@link UnitOfWorkFactory} to use.
1300         */
1301        void setUnitOfWorkFactory(UnitOfWorkFactory unitOfWorkFactory);
1302    
1303    }