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