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