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