001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel;
018
019import java.util.Collection;
020import java.util.List;
021import java.util.Map;
022import java.util.Set;
023
024import org.apache.camel.spi.CamelContextNameStrategy;
025import org.apache.camel.spi.ClassResolver;
026import org.apache.camel.spi.DataFormat;
027import org.apache.camel.spi.DataType;
028import org.apache.camel.spi.Debugger;
029import org.apache.camel.spi.EndpointRegistry;
030import org.apache.camel.spi.ExecutorServiceManager;
031import org.apache.camel.spi.HeadersMapFactory;
032import org.apache.camel.spi.InflightRepository;
033import org.apache.camel.spi.Injector;
034import org.apache.camel.spi.Language;
035import org.apache.camel.spi.LifecycleStrategy;
036import org.apache.camel.spi.ManagementNameStrategy;
037import org.apache.camel.spi.ManagementStrategy;
038import org.apache.camel.spi.MessageHistoryFactory;
039import org.apache.camel.spi.PropertiesComponent;
040import org.apache.camel.spi.Registry;
041import org.apache.camel.spi.ReloadStrategy;
042import org.apache.camel.spi.RestConfiguration;
043import org.apache.camel.spi.RestRegistry;
044import org.apache.camel.spi.RouteController;
045import org.apache.camel.spi.RoutePolicyFactory;
046import org.apache.camel.spi.RuntimeEndpointRegistry;
047import org.apache.camel.spi.ShutdownStrategy;
048import org.apache.camel.spi.StreamCachingStrategy;
049import org.apache.camel.spi.Transformer;
050import org.apache.camel.spi.TransformerRegistry;
051import org.apache.camel.spi.TypeConverterRegistry;
052import org.apache.camel.spi.UuidGenerator;
053import org.apache.camel.spi.Validator;
054import org.apache.camel.spi.ValidatorRegistry;
055import org.apache.camel.support.jsse.SSLContextParameters;
056
057/**
058 * Interface used to represent the CamelContext used to configure routes and the
059 * policies to use during message exchanges between endpoints.
060 * <p/>
061 * The CamelContext offers the following methods to control the lifecycle:
062 * <ul>
063 *   <li>{@link #start()}  - to start (<b>important:</b> the start method is not blocked, see more details
064 *     <a href="http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html">here</a>)</li>
065 *   <li>{@link #stop()} - to shutdown (will stop all routes/components/endpoints etc and clear internal state/cache)</li>
066 *   <li>{@link #suspend()} - to pause routing messages</li>
067 *   <li>{@link #resume()} - to resume after a suspend</li>
068 * </ul>
069 * <p/>
070 * <b>Notice:</b> {@link #stop()} and {@link #suspend()} will gracefully stop/suspend routes ensuring any messages
071 * in progress will be given time to complete. See more details at {@link org.apache.camel.spi.ShutdownStrategy}.
072 * <p/>
073 * If you are doing a hot restart then it's advised to use the suspend/resume methods which ensure a faster
074 * restart but also allows any internal state to be kept as is.
075 * The stop/start approach will do a <i>cold</i> restart of Camel, where all internal state is reset.
076 * <p/>
077 * End users are advised to use suspend/resume. Using stop is for shutting down Camel and it's not guaranteed that
078 * when it's being started again using the start method that Camel will operate consistently.
079 * <p/>
080 * For more advanced APIs with {@link CamelContext} see {@link ExtendedCamelContext}, which you can obtain via the adapt method.
081 */
082public interface CamelContext extends StatefulService, RuntimeConfiguration {
083
084    /**
085     * Adapts this {@link org.apache.camel.CamelContext} to the specialized type.
086     * <p/>
087     * For example to adapt to <tt>ModelCamelContext</tt>,
088     * or <tt>SpringCamelContext</tt>, or <tt>CdiCamelContext</tt>, etc.
089     *
090     * @param type the type to adapt to
091     * @return this {@link org.apache.camel.CamelContext} adapted to the given type
092     */
093    <T extends CamelContext> T adapt(Class<T> type);
094
095    /**
096     * Gets the extension of the given type.
097     *
098     * @param type  the type of the extension
099     * @return the extension, or <tt>null</tt> if no extension has been installed.
100     */
101    <T> T getExtension(Class<T> type);
102
103    /**
104     * Allows to install custom extensions to the Camel context.
105     *
106     * @param type   the type of the extension
107     * @param module the instance of the extension
108     */
109    <T> void setExtension(Class<T> type, T module);
110
111    /**
112     * If CamelContext during the start procedure was vetoed, and therefore causing Camel to not start.
113     */
114    boolean isVetoStarted();
115
116    /**
117     * Starts the {@link CamelContext} (<b>important:</b> the start method is not blocked, see more details
118     *     <a href="http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html">here</a>)</li>.
119     * <p/>
120     * See more details at the class-level javadoc of this class.
121     *
122     * @throws RuntimeCamelException is thrown if starting failed
123     */
124    void start();
125
126    /**
127     * Stop and shutdown the {@link CamelContext} (will stop all routes/components/endpoints etc and clear internal state/cache).
128     * <p/>
129     * See more details at the class-level javadoc of this class.
130     *
131     * @throws RuntimeCamelException is thrown if stopping failed
132     */
133    void stop();
134
135    /**
136     * Gets the name (id) of the this CamelContext.
137     *
138     * @return the name
139     */
140    String getName();
141
142    /**
143     * Gets the current name strategy
144     *
145     * @return name strategy
146     */
147    CamelContextNameStrategy getNameStrategy();
148
149    /**
150     * Sets a custom name strategy
151     *
152     * @param nameStrategy name strategy
153     */
154    void setNameStrategy(CamelContextNameStrategy nameStrategy);
155
156    /**
157     * Gets the current management name strategy
158     *
159     * @return management name strategy
160     */
161    ManagementNameStrategy getManagementNameStrategy();
162
163    /**
164     * Sets a custom management name strategy
165     *
166     * @param nameStrategy name strategy
167     */
168    void setManagementNameStrategy(ManagementNameStrategy nameStrategy);
169
170    /**
171     * Gets the name this {@link CamelContext} was registered in JMX.
172     * <p/>
173     * The reason that a {@link CamelContext} can have a different name in JMX is the fact to remedy for name clash
174     * in JMX when having multiple {@link CamelContext}s in the same JVM. Camel will automatic reassign and use
175     * a free name to avoid failing to start.
176     *
177     * @return the management name
178     */
179    String getManagementName();
180
181    /**
182     * Sets the name this {@link CamelContext} will be registered in JMX.
183     */
184    void setManagementName(String name);
185
186    /**
187     * Gets the version of the this CamelContext.
188     *
189     * @return the version
190     */
191    String getVersion();
192
193    /**
194     * Get the status of this CamelContext
195     *
196     * @return the status
197     */
198    ServiceStatus getStatus();
199
200    /**
201     * Gets the uptime in a human readable format
202     *
203     * @return the uptime in days/hours/minutes
204     */
205    String getUptime();
206
207    /**
208     * Gets the uptime in milli seconds
209     *
210     * @return the uptime in millis seconds
211     */
212    long getUptimeMillis();
213
214    // Service Methods
215    //-----------------------------------------------------------------------
216
217    /**
218     * Adds a service to this CamelContext, which allows this CamelContext to control the lifecycle, ensuring
219     * the service is stopped when the CamelContext stops.
220     * <p/>
221     * The service will also have {@link CamelContext} injected if its {@link CamelContextAware}.
222     * The service will also be enlisted in JMX for management (if JMX is enabled).
223     * The service will be started, if its not already started.
224     *
225     * @param object the service
226     * @throws Exception can be thrown when starting the service
227     */
228    void addService(Object object) throws Exception;
229
230    /**
231     * Adds a service to this CamelContext.
232     * <p/>
233     * The service will also have {@link CamelContext} injected if its {@link CamelContextAware}.
234     * The service will also be enlisted in JMX for management (if JMX is enabled).
235     * The service will be started, if its not already started.
236     * <p/>
237     * If the option <tt>closeOnShutdown</tt> is <tt>true</tt> then this CamelContext will control the lifecycle, ensuring
238     * the service is stopped when the CamelContext stops.
239     * If the option <tt>closeOnShutdown</tt> is <tt>false</tt> then this CamelContext will not stop the service when the CamelContext stops.
240     *
241     * @param object the service
242     * @param stopOnShutdown whether to stop the service when this CamelContext shutdown.
243     * @throws Exception can be thrown when starting the service
244     */
245    void addService(Object object, boolean stopOnShutdown) throws Exception;
246
247    /**
248     * Adds a service to this CamelContext.
249     * <p/>
250     * The service will also have {@link CamelContext} injected if its {@link CamelContextAware}.
251     * The service will also be enlisted in JMX for management (if JMX is enabled).
252     * The service will be started, if its not already started.
253     * <p/>
254     * If the option <tt>closeOnShutdown</tt> is <tt>true</tt> then this CamelContext will control the lifecycle, ensuring
255     * the service is stopped when the CamelContext stops.
256     * If the option <tt>closeOnShutdown</tt> is <tt>false</tt> then this CamelContext will not stop the service when the CamelContext stops.
257     *
258     * @param object the service
259     * @param stopOnShutdown whether to stop the service when this CamelContext shutdown.
260     * @param forceStart whether to force starting the service right now, as otherwise the service may be deferred being started
261     *                   to later using {@link #deferStartService(Object, boolean)}
262     * @throws Exception can be thrown when starting the service
263     */
264    void addService(Object object, boolean stopOnShutdown, boolean forceStart) throws Exception;
265
266    /**
267     * Removes a service from this CamelContext.
268     * <p/>
269     * The service is assumed to have been previously added using {@link #addService(Object)} method.
270     * This method will <b>not</b> change the service lifecycle.
271     *
272     * @param object the service
273     * @throws Exception can be thrown if error removing the service
274     * @return <tt>true</tt> if the service was removed, <tt>false</tt> if no service existed
275     */
276    boolean removeService(Object object) throws Exception;
277
278    /**
279     * Has the given service already been added to this CamelContext?
280     *
281     * @param object the service
282     * @return <tt>true</tt> if already added, <tt>false</tt> if not.
283     */
284    boolean hasService(Object object);
285
286    /**
287     * Has the given service type already been added to this CamelContext?
288     *
289     * @param type the class type
290     * @return the service instance or <tt>null</tt> if not already added.
291     */
292    <T> T hasService(Class<T> type);
293
294    /**
295     * Has the given service type already been added to this CamelContext?
296     *
297     * @param type the class type
298     * @return the services instance or empty set.
299     */
300    <T> Set<T> hasServices(Class<T> type);
301
302    /**
303     * Defers starting the service until {@link CamelContext} is (almost started) or started and has initialized all its prior services and routes.
304     * <p/>
305     * If {@link CamelContext} is already started then the service is started immediately.
306     *
307     * @param object the service
308     * @param stopOnShutdown whether to stop the service when this CamelContext shutdown. Setting this to <tt>true</tt> will keep a reference to the service in
309     *                       this {@link CamelContext} until the CamelContext is stopped. So do not use it for short lived services.
310     * @throws Exception can be thrown when starting the service, which is only attempted if {@link CamelContext} has already been started when calling this method.
311     */
312    void deferStartService(Object object, boolean stopOnShutdown) throws Exception;
313
314    /**
315     * Adds the given listener to be invoked when {@link CamelContext} have just been started.
316     * <p/>
317     * This allows listeners to do any custom work after the routes and other services have been started and are running.
318     * <p/><b>Important:</b> The listener will always be invoked, also if the {@link CamelContext} has already been
319     * started, see the {@link org.apache.camel.StartupListener#onCamelContextStarted(CamelContext, boolean)} method.
320     *
321     * @param listener the listener
322     * @throws Exception can be thrown if {@link CamelContext} is already started and the listener is invoked
323     *                   and cause an exception to be thrown
324     */
325    void addStartupListener(StartupListener listener) throws Exception;
326
327    // Component Management Methods
328    //-----------------------------------------------------------------------
329
330    /**
331     * Adds a component to the context.
332     *
333     * @param componentName the name the component is registered as
334     * @param component     the component
335     */
336    void addComponent(String componentName, Component component);
337
338    /**
339     * Is the given component already registered?
340     *
341     * @param componentName the name of the component
342     * @return the registered Component or <tt>null</tt> if not registered
343     */
344    Component hasComponent(String componentName);
345
346    /**
347     * Gets a component from the CamelContext by name.
348     * <p/>
349     * Notice the returned component will be auto-started. If you do not intend to do that
350     * then use {@link #getComponent(String, boolean, boolean)}.
351     *
352     * @param componentName the name of the component
353     * @return the component
354     */
355    Component getComponent(String componentName);
356
357    /**
358     * Gets a component from the CamelContext by name.
359     * <p/>
360     * Notice the returned component will be auto-started. If you do not intend to do that
361     * then use {@link #getComponent(String, boolean, boolean)}.
362     *
363     * @param name                 the name of the component
364     * @param autoCreateComponents whether or not the component should
365     *                             be lazily created if it does not already exist
366     * @return the component
367     */
368    Component getComponent(String name, boolean autoCreateComponents);
369
370    /**
371     * Gets a component from the CamelContext by name.
372     *
373     * @param name                 the name of the component
374     * @param autoCreateComponents whether or not the component should
375     *                             be lazily created if it does not already exist
376     * @param autoStart            whether to auto start the component if {@link CamelContext} is already started.
377     * @return the component
378     */
379    Component getComponent(String name, boolean autoCreateComponents, boolean autoStart);
380
381    /**
382     * Gets a component from the CamelContext by name and specifying the expected type of component.
383     *
384     * @param name          the name to lookup
385     * @param componentType the expected type
386     * @return the component
387     */
388    <T extends Component> T getComponent(String name, Class<T> componentType);
389
390    /**
391     * Gets a readonly list of names of the components currently registered
392     *
393     * @return a readonly list with the names of the components
394     */
395    List<String> getComponentNames();
396
397    /**
398     * Removes a previously added component.
399     * <p/>
400     * The component being removed will be stopped first.
401     *
402     * @param componentName the component name to remove
403     * @return the previously added component or null if it had not been previously added.
404     */
405    Component removeComponent(String componentName);
406
407    // Endpoint Management Methods
408    //-----------------------------------------------------------------------
409
410    /**
411     * Gets the {@link org.apache.camel.spi.EndpointRegistry}
412     */
413    EndpointRegistry<? extends ValueHolder<String>> getEndpointRegistry();
414
415    /**
416     * Resolves the given name to an {@link Endpoint} of the specified type.
417     * If the name has a singleton endpoint registered, then the singleton is returned.
418     * Otherwise, a new {@link Endpoint} is created and registered in the {@link org.apache.camel.spi.EndpointRegistry}.
419     *
420     * @param uri the URI of the endpoint
421     * @return the endpoint
422     */
423    Endpoint getEndpoint(String uri);
424
425    /**
426     * Resolves the given name to an {@link Endpoint} of the specified type.
427     * If the name has a singleton endpoint registered, then the singleton is returned.
428     * Otherwise, a new {@link Endpoint} is created and registered in the {@link org.apache.camel.spi.EndpointRegistry}.
429     *
430     * @param name         the name of the endpoint
431     * @param endpointType the expected type
432     * @return the endpoint
433     */
434    <T extends Endpoint> T getEndpoint(String name, Class<T> endpointType);
435
436    /**
437     * Returns a new {@link Collection} of all of the endpoints from the {@link org.apache.camel.spi.EndpointRegistry}
438     *
439     * @return all endpoints
440     */
441    Collection<Endpoint> getEndpoints();
442
443    /**
444     * Returns a new {@link Map} containing all of the endpoints from the {@link org.apache.camel.spi.EndpointRegistry}
445     *
446     * @return map of endpoints
447     * @deprecated use {@link #getEndpointRegistry()}
448     */
449    @Deprecated
450    Map<String, Endpoint> getEndpointMap();
451
452    /**
453     * Is the given endpoint already registered in the {@link org.apache.camel.spi.EndpointRegistry}
454     *
455     * @param uri the URI of the endpoint
456     * @return the registered endpoint or <tt>null</tt> if not registered
457     */
458    Endpoint hasEndpoint(String uri);
459
460    /**
461     * Adds and starts the endpoint to the {@link org.apache.camel.spi.EndpointRegistry} using the given URI.
462     *
463     * @param uri      the URI to be used to resolve this endpoint
464     * @param endpoint the endpoint to be started and added to the registry
465     * @return the old endpoint that was previously registered or <tt>null</tt> if none was registered
466     * @throws Exception if the new endpoint could not be started or the old endpoint could not be stopped
467     */
468    Endpoint addEndpoint(String uri, Endpoint endpoint) throws Exception;
469
470    /**
471     * Removes the endpoint from the {@link org.apache.camel.spi.EndpointRegistry}.
472     * <p/>
473     * The endpoint being removed will be stopped first.
474     *
475     * @param endpoint  the endpoint
476     * @throws Exception if the endpoint could not be stopped
477     */
478    void removeEndpoint(Endpoint endpoint) throws Exception;
479
480    /**
481     * Removes all endpoints with the given URI from the {@link org.apache.camel.spi.EndpointRegistry}.
482     * <p/>
483     * The endpoints being removed will be stopped first.
484     *
485     * @param pattern an uri or pattern to match
486     * @return a collection of endpoints removed which could be empty if there are no endpoints found for the given <tt>pattern</tt>
487     * @throws Exception if at least one endpoint could not be stopped
488     * @see org.apache.camel.support.EndpointHelper#matchEndpoint(CamelContext, String, String) for pattern
489     */
490    Collection<Endpoint> removeEndpoints(String pattern) throws Exception;
491
492    // Route Management Methods
493    //-----------------------------------------------------------------------
494
495    /**
496     * Sets a custom {@link RouteController} to use
497     *
498     * @param routeController the route controller
499     */
500    void setRouteController(RouteController routeController);
501
502    /**
503     * Gets the {@link RouteController}
504     *
505     * @return the route controller.
506     */
507    RouteController getRouteController();
508
509    /**
510     * Returns the current routes in this CamelContext
511     *
512     * @return the current routes
513     */
514    List<Route> getRoutes();
515
516    /**
517     * Gets the route with the given id
518     *
519     * @param id id of the route
520     * @return the route or <tt>null</tt> if not found
521     */
522    Route getRoute(String id);
523
524    /**
525     * Gets the processor from any of the routes which with the given id
526     *
527     * @param id id of the processor
528     * @return the processor or <tt>null</tt> if not found
529     */
530    Processor getProcessor(String id);
531
532    /**
533     * Gets the processor from any of the routes which with the given id
534     *
535     * @param id id of the processor
536     * @param type the processor type
537     * @return the processor or <tt>null</tt> if not found
538     * @throws java.lang.ClassCastException is thrown if the type is not correct type
539     */
540    <T extends Processor> T getProcessor(String id, Class<T> type);
541
542    /**
543     * Adds a collection of routes to this CamelContext using the given builder
544     * to build them.
545     * <p/>
546     * <b>Important:</b> The added routes will <b>only</b> be started, if {@link CamelContext}
547     * is already started. You may want to check the state of {@link CamelContext} before
548     * adding the routes, using the {@link org.apache.camel.CamelContext#getStatus()} method.
549     * <p/>
550     * <b>Important: </b> Each route in the same {@link org.apache.camel.CamelContext} must have an <b>unique</b> route id.
551     * If you use the API from {@link org.apache.camel.CamelContext} or {@link org.apache.camel.model.ModelCamelContext} to add routes, then any
552     * new routes which has a route id that matches an old route, then the old route is replaced by the new route.
553     *
554     * @param builder the builder which will create the routes and add them to this CamelContext
555     * @throws Exception if the routes could not be created for whatever reason
556     */
557    void addRoutes(RoutesBuilder builder) throws Exception;
558
559    /**
560     * Removes the given route (the route <b>must</b> be stopped before it can be removed).
561     * <p/>
562     * A route which is removed will be unregistered from JMX, have its services stopped/shutdown and the route
563     * definition etc. will also be removed. All the resources related to the route will be stopped and cleared.
564     * <p/>
565     * <b>Important:</b> When removing a route, the {@link Endpoint}s which are in the static cache of
566     * {@link org.apache.camel.spi.EndpointRegistry} and are <b>only</b> used by the route (not used by other routes)
567     * will also be removed. But {@link Endpoint}s which may have been created as part of routing messages by the route,
568     * and those endpoints are enlisted in the dynamic cache of {@link org.apache.camel.spi.EndpointRegistry} are
569     * <b>not</b> removed. To remove those dynamic kind of endpoints, use the {@link #removeEndpoints(String)} method.
570     * If not removing those endpoints, they will be kept in the dynamic cache of {@link org.apache.camel.spi.EndpointRegistry},
571     * but my eventually be removed (evicted) when they have not been in use for a longer period of time; and the
572     * dynamic cache upper limit is hit, and it evicts the least used endpoints.
573     * <p/>
574     * End users can use this method to remove unwanted routes or temporary routes which no longer is in demand.
575     *
576     * @param routeId the route id
577     * @return <tt>true</tt> if the route was removed, <tt>false</tt> if the route could not be removed because its not stopped
578     * @throws Exception is thrown if the route could not be shutdown for whatever reason
579     */
580    boolean removeRoute(String routeId) throws Exception;
581
582    /**
583     * Adds the given route policy factory
584     *
585     * @param routePolicyFactory the factory
586     */
587    void addRoutePolicyFactory(RoutePolicyFactory routePolicyFactory);
588
589    /**
590     * Gets the route policy factories
591     *
592     * @return the list of current route policy factories
593     */
594    List<RoutePolicyFactory> getRoutePolicyFactories();
595
596    // Rest Methods
597    //-----------------------------------------------------------------------
598
599    /**
600     * Sets a custom {@link org.apache.camel.spi.RestConfiguration}
601     *
602     * @param restConfiguration the REST configuration
603     */
604    void setRestConfiguration(RestConfiguration restConfiguration);
605
606    /**
607     * Gets the default REST configuration
608     *
609     * @return the configuration, or <tt>null</tt> if none has been configured.
610     */
611    RestConfiguration getRestConfiguration();
612
613    /**
614     * Sets a custom {@link org.apache.camel.spi.RestConfiguration}
615     *
616     * @param restConfiguration the REST configuration
617     */
618    void addRestConfiguration(RestConfiguration restConfiguration);
619
620    /**
621     * Gets the REST configuration for the given component
622     *
623     * @param component the component name to get the configuration
624     * @param defaultIfNotFound determine if the default configuration is returned if there isn't a
625     *        specific configuration for the given component
626     * @return the configuration, or <tt>null</tt> if none has been configured.
627     */
628    RestConfiguration getRestConfiguration(String component, boolean defaultIfNotFound);
629
630    /**
631     * Gets all the RestConfiguration's
632     */
633    Collection<RestConfiguration> getRestConfigurations();
634
635    /**
636     * Gets the {@link org.apache.camel.spi.RestRegistry} to use
637     */
638    RestRegistry getRestRegistry();
639
640    /**
641     * Sets a custom {@link org.apache.camel.spi.RestRegistry} to use.
642     */
643    void setRestRegistry(RestRegistry restRegistry);
644
645    // Properties
646    //-----------------------------------------------------------------------
647
648    /**
649     * Returns the type converter used to coerce types from one type to another
650     *
651     * @return the converter
652     */
653    TypeConverter getTypeConverter();
654
655    /**
656     * Returns the type converter registry where type converters can be added or looked up
657     *
658     * @return the type converter registry
659     */
660    TypeConverterRegistry getTypeConverterRegistry();
661
662    /**
663     * Configures the type converter registry to use, where type converters can be added or looked up.
664     *
665     * @param typeConverterRegistry the registry to use
666     */
667    void setTypeConverterRegistry(TypeConverterRegistry typeConverterRegistry);
668
669    /**
670     * Returns the registry used to lookup components by name and type such as SimpleRegistry, Spring ApplicationContext,
671     * JNDI, or the OSGi Service Registry.
672     *
673     * @return the registry
674     */
675    Registry getRegistry();
676
677    /**
678     * Returns the registry used to lookup components by name and as the given type
679     *
680     * @param type the registry type such as org.apache.camel.impl.JndiRegistry
681     * @return the registry, or <tt>null</tt> if the given type was not found as a registry implementation
682     */
683    <T> T getRegistry(Class<T> type);
684
685    /**
686     * Returns the injector used to instantiate objects by type
687     *
688     * @return the injector
689     */
690    Injector getInjector();
691
692    /**
693     * Returns the lifecycle strategies used to handle lifecycle notifications
694     *
695     * @return the lifecycle strategies
696     */
697    List<LifecycleStrategy> getLifecycleStrategies();
698
699    /**
700     * Adds the given lifecycle strategy to be used.
701     *
702     * @param lifecycleStrategy the strategy
703     */
704    void addLifecycleStrategy(LifecycleStrategy lifecycleStrategy);
705
706    /**
707     * Resolves a language for creating expressions
708     *
709     * @param language name of the language
710     * @return the resolved language
711     */
712    Language resolveLanguage(String language);
713
714    /**
715     * Parses the given text and resolve any property placeholders - using {{key}}.
716     *
717     * @param text the text such as an endpoint uri or the likes
718     * @return the text with resolved property placeholders
719     * @throws IllegalArgumentException is thrown if property placeholders was used and there was an error resolving them
720     */
721    String resolvePropertyPlaceholders(String text);
722    
723    /**
724     * Returns the configured property placeholder prefix token if and only if the CamelContext has
725     * property placeholder abilities, otherwise returns {@code null}.
726     * 
727     * @return the prefix token or {@code null}
728     */
729    String getPropertyPrefixToken();
730    
731    /**
732     * Returns the configured property placeholder suffix token if and only if the CamelContext has
733     * property placeholder abilities, otherwise returns {@code null}.
734     * 
735     * @return the suffix token or {@code null}
736     */
737    String getPropertySuffixToken();
738
739    /**
740     * Returns the configured properties component or create one if none has been configured.
741     *
742     * @return the properties component
743     */
744    PropertiesComponent getPropertiesComponent();
745
746    /**
747     * Returns the configured properties component or create one if none has been configured.
748     *
749     * @param autoCreate whether the component should be created if none is configured
750     * @return the properties component
751     */
752    PropertiesComponent getPropertiesComponent(boolean autoCreate);
753
754    /**
755     * Gets a readonly list with the names of the languages currently registered.
756     *
757     * @return a readonly list with the names of the languages
758     * @deprecated not in use
759     */
760    @Deprecated
761    List<String> getLanguageNames();
762
763    /**
764     * Creates a new {@link ProducerTemplate} which is <b>started</b> and therefore ready to use right away.
765     * <p/>
766     * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">
767     * Why does Camel use too many threads with ProducerTemplate?</a>
768     * <p/>
769     * <b>Important:</b> Make sure to call {@link org.apache.camel.ProducerTemplate#stop()} when you are done using the template,
770     * to clean up any resources.
771     * <p/>
772     * Will use cache size defined in Camel property with key {@link Exchange#MAXIMUM_CACHE_POOL_SIZE}.
773     * If no key was defined then it will fallback to a default size of 1000.
774     * You can also use the {@link org.apache.camel.ProducerTemplate#setMaximumCacheSize(int)} method to use a custom value
775     * before starting the template.
776     *
777     * @return the template
778     * @throws RuntimeCamelException is thrown if error starting the template
779     */
780    ProducerTemplate createProducerTemplate();
781
782    /**
783     * Creates a new {@link ProducerTemplate} which is <b>started</b> and therefore ready to use right away.
784     * <p/>
785     * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">
786     * Why does Camel use too many threads with ProducerTemplate?</a>
787     * <p/>
788     * <b>Important:</b> Make sure to call {@link ProducerTemplate#stop()} when you are done using the template,
789     * to clean up any resources.
790     *
791     * @param maximumCacheSize the maximum cache size
792     * @return the template
793     * @throws RuntimeCamelException is thrown if error starting the template
794     */
795    ProducerTemplate createProducerTemplate(int maximumCacheSize);
796
797    /**
798     * Creates a new {@link FluentProducerTemplate} which is <b>started</b> and therefore ready to use right away.
799     * <p/>
800     * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">
801     * Why does Camel use too many threads with ProducerTemplate?</a>
802     * <p/>
803     * <b>Important:</b> Make sure to call {@link org.apache.camel.FluentProducerTemplate#stop()} when you are done using the template,
804     * to clean up any resources.
805     * <p/>
806     * Will use cache size defined in Camel property with key {@link Exchange#MAXIMUM_CACHE_POOL_SIZE}.
807     * If no key was defined then it will fallback to a default size of 1000.
808     * You can also use the {@link org.apache.camel.FluentProducerTemplate#setMaximumCacheSize(int)} method to use a custom value
809     * before starting the template.
810     *
811     * @return the template
812     * @throws RuntimeCamelException is thrown if error starting the template
813     */
814    FluentProducerTemplate createFluentProducerTemplate();
815
816    /**
817     * Creates a new {@link FluentProducerTemplate} which is <b>started</b> and therefore ready to use right away.
818     * <p/>
819     * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">
820     * Why does Camel use too many threads with ProducerTemplate?</a>
821     * <p/>
822     * <b>Important:</b> Make sure to call {@link FluentProducerTemplate#stop()} when you are done using the template,
823     * to clean up any resources.
824     *
825     * @param maximumCacheSize the maximum cache size
826     * @return the template
827     * @throws RuntimeCamelException is thrown if error starting the template
828     */
829    FluentProducerTemplate createFluentProducerTemplate(int maximumCacheSize);
830
831    /**
832     * Creates a new {@link ConsumerTemplate} which is <b>started</b> and therefore ready to use right away.
833     * <p/>
834     * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">
835     * Why does Camel use too many threads with ProducerTemplate?</a> as it also applies for ConsumerTemplate.
836     * <p/>
837     * <b>Important:</b> Make sure to call {@link ConsumerTemplate#stop()} when you are done using the template,
838     * to clean up any resources.
839     * <p/>
840     * Will use cache size defined in Camel property with key {@link Exchange#MAXIMUM_CACHE_POOL_SIZE}.
841     * If no key was defined then it will fallback to a default size of 1000.
842     * You can also use the {@link org.apache.camel.ConsumerTemplate#setMaximumCacheSize(int)} method to use a custom value
843     * before starting the template.
844     *
845     * @return the template
846     * @throws RuntimeCamelException is thrown if error starting the template
847     */
848    ConsumerTemplate createConsumerTemplate();
849
850    /**
851     * Creates a new {@link ConsumerTemplate} which is <b>started</b> and therefore ready to use right away.
852     * <p/>
853     * See this FAQ before use: <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">
854     * Why does Camel use too many threads with ProducerTemplate?</a> as it also applies for ConsumerTemplate.
855     * <p/>
856     * <b>Important:</b> Make sure to call {@link ConsumerTemplate#stop()} when you are done using the template,
857     * to clean up any resources.
858     *
859     * @param maximumCacheSize the maximum cache size
860     * @return the template
861     * @throws RuntimeCamelException is thrown if error starting the template
862     */
863    ConsumerTemplate createConsumerTemplate(int maximumCacheSize);
864
865    /**
866     * Resolve a data format given its name
867     *
868     * @param name the data format name or a reference to it in the {@link Registry}
869     * @return the resolved data format, or <tt>null</tt> if not found
870     */
871    DataFormat resolveDataFormat(String name);
872
873    /**
874     * Creates the given data format given its name.
875     *
876     * @param name the data format name or a reference to a data format factory in the {@link Registry}
877     * @return the resolved data format, or <tt>null</tt> if not found
878     */
879    DataFormat createDataFormat(String name);
880
881    /**
882     * Resolve a transformer given a scheme
883     *
884     * @param model data model name.
885     * @return the resolved transformer, or <tt>null</tt> if not found
886     */
887    Transformer resolveTransformer(String model);
888
889    /**
890     * Resolve a transformer given from/to data type.
891     *
892     * @param from from data type
893     * @param to to data type
894     * @return the resolved transformer, or <tt>null</tt> if not found
895     */
896    Transformer resolveTransformer(DataType from, DataType to);
897
898    /**
899     * Gets the {@link org.apache.camel.spi.TransformerRegistry}
900     * @return the TransformerRegistry
901     */
902    TransformerRegistry<? extends ValueHolder<String>> getTransformerRegistry();
903
904    /**
905     * Resolve a validator given from/to data type.
906     *
907     * @param type the data type
908     * @return the resolved validator, or <tt>null</tt> if not found
909     */
910    Validator resolveValidator(DataType type);
911
912    /**
913     * Gets the {@link org.apache.camel.spi.ValidatorRegistry}
914     * @return the ValidatorRegistry
915     */
916    ValidatorRegistry<? extends ValueHolder<String>> getValidatorRegistry();
917
918    /**
919     * Sets global options that can be referenced in the camel context
920     * <p/>
921     * <b>Important:</b> This has nothing to do with property placeholders, and is just a plain set of key/value pairs
922     * which are used to configure global options on CamelContext, such as a maximum debug logging length etc.
923     * For property placeholders use {@link #resolvePropertyPlaceholders(String)} method and see more details
924     * at the <a href="http://camel.apache.org/using-propertyplaceholder.html">property placeholder</a> documentation.
925     *
926     * @param globalOptions global options that can be referenced in the camel context
927     */
928    void setGlobalOptions(Map<String, String> globalOptions);
929
930    /**
931     * Gets global options that can be referenced in the camel context.
932     * <p/>
933     * <b>Important:</b> This has nothing to do with property placeholders, and is just a plain set of key/value pairs
934     * which are used to configure global options on CamelContext, such as a maximum debug logging length etc.
935     * For property placeholders use {@link #resolvePropertyPlaceholders(String)} method and see more details
936     * at the <a href="http://camel.apache.org/using-propertyplaceholder.html">property placeholder</a> documentation.
937     *
938     * @return global options for this context
939     */
940    Map<String, String> getGlobalOptions();
941
942    /**
943     * Gets the global option value that can be referenced in the camel context
944     * <p/>
945     * <b>Important:</b> This has nothing to do with property placeholders, and is just a plain set of key/value pairs
946     * which are used to configure global options on CamelContext, such as a maximum debug logging length etc.
947     * For property placeholders use {@link #resolvePropertyPlaceholders(String)} method and see more details
948     * at the <a href="http://camel.apache.org/using-propertyplaceholder.html">property placeholder</a> documentation.
949     *
950     * @return the string value of the global option
951     */
952    String getGlobalOption(String key);
953
954    /**
955     * Returns the class resolver to be used for loading/lookup of classes.
956     *
957     * @return the resolver
958     */
959    ClassResolver getClassResolver();
960
961    /**
962     * Sets the class resolver to be use
963     *
964     * @param resolver the resolver
965     */
966    void setClassResolver(ClassResolver resolver);
967
968    /**
969     * Gets the management strategy
970     *
971     * @return the management strategy
972     */
973    ManagementStrategy getManagementStrategy();
974
975    /**
976     * Sets the management strategy to use
977     *
978     * @param strategy the management strategy
979     */
980    void setManagementStrategy(ManagementStrategy strategy);
981
982    /**
983     * Disables using JMX as {@link org.apache.camel.spi.ManagementStrategy}.
984     * <p/>
985     * <b>Important:</b> This method must be called <b>before</b> the {@link CamelContext} is started.
986     *
987     * @throws IllegalStateException is thrown if the {@link CamelContext} is not in stopped state.
988     */
989    void disableJMX() throws IllegalStateException;
990
991    /**
992     * Gets the inflight repository
993     *
994     * @return the repository
995     */
996    InflightRepository getInflightRepository();
997
998    /**
999     * Sets a custom inflight repository to use
1000     *
1001     * @param repository the repository
1002     */
1003    void setInflightRepository(InflightRepository repository);
1004
1005    /**
1006     * Gets the application CamelContext class loader which may be helpful for running camel in other containers
1007     *
1008     * @return the application CamelContext class loader
1009     */
1010    ClassLoader getApplicationContextClassLoader();
1011
1012    /**
1013     * Sets the application CamelContext class loader
1014     *
1015     * @param classLoader the class loader
1016     */
1017    void setApplicationContextClassLoader(ClassLoader classLoader);
1018
1019    /**
1020     * Gets the current shutdown strategy
1021     *
1022     * @return the strategy
1023     */
1024    ShutdownStrategy getShutdownStrategy();
1025
1026    /**
1027     * Sets a custom shutdown strategy
1028     *
1029     * @param shutdownStrategy the custom strategy
1030     */
1031    void setShutdownStrategy(ShutdownStrategy shutdownStrategy);
1032
1033    /**
1034     * Gets the current {@link org.apache.camel.spi.ExecutorServiceManager}
1035     *
1036     * @return the manager
1037     */
1038    ExecutorServiceManager getExecutorServiceManager();
1039
1040    /**
1041     * Sets a custom {@link org.apache.camel.spi.ExecutorServiceManager}
1042     *
1043     * @param executorServiceManager the custom manager
1044     */
1045    void setExecutorServiceManager(ExecutorServiceManager executorServiceManager);
1046
1047    /**
1048     * Gets the current {@link org.apache.camel.spi.MessageHistoryFactory}
1049     *
1050     * @return the factory
1051     */
1052    MessageHistoryFactory getMessageHistoryFactory();
1053
1054    /**
1055     * Sets a custom {@link org.apache.camel.spi.MessageHistoryFactory}
1056     *
1057     * @param messageHistoryFactory the custom factory
1058     */
1059    void setMessageHistoryFactory(MessageHistoryFactory messageHistoryFactory);
1060
1061    /**
1062     * Gets the current {@link Debugger}
1063     *
1064     * @return the debugger
1065     */
1066    Debugger getDebugger();
1067
1068    /**
1069     * Sets a custom {@link Debugger}
1070     *
1071     * @param debugger the debugger
1072     */
1073    void setDebugger(Debugger debugger);
1074
1075    /**
1076     * Gets the current {@link UuidGenerator}
1077     *
1078     * @return the uuidGenerator
1079     */
1080    UuidGenerator getUuidGenerator();
1081    
1082    /**
1083     * Sets a custom {@link UuidGenerator} (should only be set once) 
1084     *
1085     * @param uuidGenerator the UUID Generator
1086     */
1087    void setUuidGenerator(UuidGenerator uuidGenerator);
1088
1089    /**
1090     * Whether to load custom type converters by scanning classpath.
1091     * This is used for backwards compatibility with Camel 2.x.
1092     * Its recommended to migrate to use fast type converter loading
1093     * by setting <tt>@Converter(loader = true)</tt> on your custom
1094     * type converter classes.
1095     */
1096    Boolean isLoadTypeConverters();
1097
1098    /**
1099     * Whether to load custom type converters by scanning classpath.
1100     * This is used for backwards compatibility with Camel 2.x.
1101     * Its recommended to migrate to use fast type converter loading
1102     * by setting <tt>@Converter(loader = true)</tt> on your custom
1103     * type converter classes.
1104     *
1105     * @param loadTypeConverters whether to load custom type converters using classpath scanning.
1106     */
1107    void setLoadTypeConverters(Boolean loadTypeConverters);
1108
1109    /**
1110     * Whether or not type converter statistics is enabled.
1111     * <p/>
1112     * By default the type converter utilization statistics is disabled.
1113     * <b>Notice:</b> If enabled then there is a slight performance impact under very heavy load.
1114     *
1115     * @return <tt>true</tt> if enabled, <tt>false</tt> if disabled (default).
1116     */
1117    Boolean isTypeConverterStatisticsEnabled();
1118
1119    /**
1120     * Sets whether or not type converter statistics is enabled.
1121     * <p/>
1122     * By default the type converter utilization statistics is disabled.
1123     * <b>Notice:</b> If enabled then there is a slight performance impact under very heavy load.
1124     * <p/>
1125     * You can enable/disable the statistics at runtime using the
1126     * {@link org.apache.camel.spi.TypeConverterRegistry#getStatistics()#setTypeConverterStatisticsEnabled(Boolean)} method,
1127     * or from JMX on the {@link org.apache.camel.api.management.mbean.ManagedTypeConverterRegistryMBean} mbean.
1128     *
1129     * @param typeConverterStatisticsEnabled <tt>true</tt> to enable, <tt>false</tt> to disable
1130     */
1131    void setTypeConverterStatisticsEnabled(Boolean typeConverterStatisticsEnabled);
1132
1133    /**
1134     * Whether or not <a href="http://www.slf4j.org/api/org/slf4j/MDC.html">MDC</a> logging is being enabled.
1135     *
1136     * @return <tt>true</tt> if MDC logging is enabled
1137     */
1138    Boolean isUseMDCLogging();
1139
1140    /**
1141     * Set whether <a href="http://www.slf4j.org/api/org/slf4j/MDC.html">MDC</a> is enabled.
1142     *
1143     * @param useMDCLogging <tt>true</tt> to enable MDC logging, <tt>false</tt> to disable
1144     */
1145    void setUseMDCLogging(Boolean useMDCLogging);
1146
1147    /**
1148     * Whether to enable using data type on Camel messages.
1149     * <p/>
1150     * Data type are automatic turned on if one ore more routes has been explicit configured with input and output types.
1151     * Otherwise data type is default off.
1152     *
1153     * @return <tt>true</tt> if data type is enabled
1154     */
1155    Boolean isUseDataType();
1156
1157    /**
1158     * Whether to enable using data type on Camel messages.
1159     * <p/>
1160     * Data type are automatic turned on if one ore more routes has been explicit configured with input and output types.
1161     * Otherwise data type is default off.
1162     *
1163     * @param  useDataType <tt>true</tt> to enable data type on Camel messages.
1164     */
1165    void setUseDataType(Boolean useDataType);
1166
1167    /**
1168     * Whether or not breadcrumb is enabled.
1169     *
1170     * @return <tt>true</tt> if breadcrumb is enabled
1171     */
1172    Boolean isUseBreadcrumb();
1173
1174    /**
1175     * Set whether breadcrumb is enabled.
1176     *
1177     * @param useBreadcrumb <tt>true</tt> to enable breadcrumb, <tt>false</tt> to disable
1178     */
1179    void setUseBreadcrumb(Boolean useBreadcrumb);
1180
1181    /**
1182     * Gets the {@link StreamCachingStrategy} to use.
1183     */
1184    StreamCachingStrategy getStreamCachingStrategy();
1185
1186    /**
1187     * Sets a custom {@link StreamCachingStrategy} to use.
1188     */
1189    void setStreamCachingStrategy(StreamCachingStrategy streamCachingStrategy);
1190
1191    /**
1192     * Gets the {@link org.apache.camel.spi.RuntimeEndpointRegistry} to use, or <tt>null</tt> if none is in use.
1193     */
1194    RuntimeEndpointRegistry getRuntimeEndpointRegistry();
1195
1196    /**
1197     * Sets a custom {@link org.apache.camel.spi.RuntimeEndpointRegistry} to use.
1198     */
1199    void setRuntimeEndpointRegistry(RuntimeEndpointRegistry runtimeEndpointRegistry);
1200
1201    /**
1202     * Returns the {@link ReloadStrategy} if in use.
1203     *
1204     * @return the strategy, or <tt>null</tt> if none has been configured.
1205     */
1206    ReloadStrategy getReloadStrategy();
1207
1208    /**
1209     * Sets a custom {@link ReloadStrategy} to be used
1210     */
1211    void setReloadStrategy(ReloadStrategy reloadStrategy);
1212
1213    /**
1214     * Sets the global SSL context parameters.
1215     */
1216    void setSSLContextParameters(SSLContextParameters sslContextParameters);
1217
1218    /**
1219     * Gets the global SSL context parameters if configured.
1220     */
1221    SSLContextParameters getSSLContextParameters();
1222
1223    /**
1224     * Gets the {@link HeadersMapFactory} to use.
1225     */
1226    HeadersMapFactory getHeadersMapFactory();
1227
1228    /**
1229     * Sets a custom {@link HeadersMapFactory} to be used.
1230     */
1231    void setHeadersMapFactory(HeadersMapFactory factory);
1232
1233}