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