org.apache.camel
Interface CamelContext

All Superinterfaces:
RuntimeConfiguration, Service
All Known Implementing Classes:
DefaultCamelContext, GaeDefaultCamelContext, GaeSpringCamelContext, GuiceCamelContext, OsgiDefaultCamelContext, OsgiSpringCamelContext, SpringCamelContext

public interface CamelContext
extends Service, RuntimeConfiguration

Interface used to represent the context used to configure routes and the policies to use during message exchanges between endpoints.

Version:
$Revision: 17082 $

Method Summary
 void addComponent(String componentName, Component component)
          Adds a component to the context.
 Endpoint addEndpoint(String uri, Endpoint endpoint)
          Adds the endpoint to the context using the given URI.
 void addInterceptStrategy(InterceptStrategy interceptStrategy)
          Adds the given interceptor strategy
 void addLifecycleStrategy(LifecycleStrategy lifecycleStrategy)
          Adds the given lifecycle strategy to be used.
 void addRegisterEndpointCallback(EndpointStrategy strategy)
          Registers a callback to allow you to do custom logic when an Endpoint is about to be registered to the CamelContext endpoint registry.
 void addRouteDefinitions(Collection<RouteDefinition> routeDefinitions)
          Adds a collection of route definitions to the context
 void addRoutes(RoutesBuilder builder)
          Adds a collection of routes to this context using the given builder to build them
 void addService(Object object)
          Adds a service, starting it so that it will be stopped with this context
 ConsumerTemplate createConsumerTemplate()
          Creates a new ConsumerTemplate.
 ProducerTemplate createProducerTemplate()
          Creates a new ProducerTemplate.
 void disableJMX()
          Disables using JMX as ManagementStrategy.
 ClassLoader getApplicationContextClassLoader()
          Gets the the application context class loader which may be helpful for running camel in other containers
 ClassResolver getClassResolver()
          Returns the class resolver to be used for loading/lookup of classes.
 Component getComponent(String componentName)
          Gets a component from the context by name.
<T extends Component>
T
getComponent(String name, Class<T> componentType)
          Gets a component from the context by name and specifying the expected type of component.
 List<String> getComponentNames()
          Gets a readonly list of names of the components currently registered
 DataFormatResolver getDataFormatResolver()
          Gets the current data format resolver
 Map<String,DataFormatDefinition> getDataFormats()
          Gets the data formats that can be referenced in the routes.
 FactoryFinder getDefaultFactoryFinder()
          Gets the default FactoryFinder which will be used for the loading the factory class from META-INF
 InterceptStrategy getDefaultTracer()
          Gets the default tracer
 Endpoint getEndpoint(String uri)
          Resolves the given name to an Endpoint of the specified type.
<T extends Endpoint>
T
getEndpoint(String name, Class<T> endpointType)
          Resolves the given name to an Endpoint of the specified type.
 Map<String,Endpoint> getEndpointMap()
          Returns a new Map containing all of the active endpoints with the key of the map being their unique key.
 Collection<Endpoint> getEndpoints()
          Returns the collection of all registered endpoints.
 Collection<Endpoint> getEndpoints(String uri)
          Deprecated. not used will be removed in Camel 2.3.
 ErrorHandlerBuilder getErrorHandlerBuilder()
          Gets the default error handler builder which is inherited by the routes
 FactoryFinder getFactoryFinder(String path)
          Gets the FactoryFinder which will be used for the loading the factory class from META-INF in the given path
 InflightRepository getInflightRepository()
          Gets the inflight repository
 Injector getInjector()
          Returns the injector used to instantiate objects by type
 List<InterceptStrategy> getInterceptStrategies()
          Gets the interceptor strategies
 List<String> getLanguageNames()
          Gets a readonly list with the names of the languages currently registered.
 List<LifecycleStrategy> getLifecycleStrategies()
          Returns the lifecycle strategies used to handle lifecycle notifications
 ManagementStrategy getManagementStrategy()
          Gets the management strategy
 String getName()
          Gets the name of the this context.
 NodeIdFactory getNodeIdFactory()
          Gets the node id factory
 Component getOrCreateComponent(String componentName, Callable<Component> factory)
          Deprecated. will be removed in Camel 2.3.
 PackageScanClassResolver getPackageScanClassResolver()
          Returns the package scanning class resolver
 ServicePool<Endpoint,Producer> getProducerServicePool()
          Gets the service pool for Producer pooling.
 Map<String,String> getProperties()
          Gets the properties that can be referenced in the camel context
 Registry getRegistry()
          Returns the registry used to lookup components by name and type such as the Spring ApplicationContext, JNDI or the OSGi Service Registry
 RouteDefinition getRouteDefinition(String id)
          Gets the route definition with the given id
 List<RouteDefinition> getRouteDefinitions()
          Returns a list of the current route definitions
 List<Route> getRoutes()
          Returns the current routes in this context
 ServiceStatus getRouteStatus(RouteDefinition route)
          Deprecated. will be removed in Camel 2.3.
 ServiceStatus getRouteStatus(String routeId)
          Returns the current status of the given route
 ShutdownStrategy getShutdownStrategy()
          Gets the current shutdown strategy
 Collection<Endpoint> getSingletonEndpoints()
          Deprecated. not used will be removed in Camel 2.3.
 TypeConverter getTypeConverter()
          Returns the type converter used to coerce types from one type to another
 TypeConverterRegistry getTypeConverterRegistry()
          Returns the type converter registry where type converters can be added or looked up
 String getVersion()
          Gets the version of the this context.
 Component hasComponent(String componentName)
          Is the given component already registered?
 Endpoint hasEndpoint(String uri)
          Is the given endpoint already registered?
 boolean hasService(Object object)
          Has the given service already been added?
 Component removeComponent(String componentName)
          Removes a previously added component.
 Collection<Endpoint> removeEndpoints(String uri)
          Deprecated. not used will be removed in Camel 2.3.
 void removeRouteDefinitions(Collection<RouteDefinition> routeDefinitions)
          Removes a collection of route definitions from the context - stopping any previously running routes if any of them are actively running
 DataFormat resolveDataFormat(String name)
          Resolve a data format given its name
 DataFormatDefinition resolveDataFormatDefinition(String name)
          Resolve a data format definition given its name
 Language resolveLanguage(String language)
          Resolves a language for creating expressions
 void setApplicationContextClassLoader(ClassLoader classLoader)
          Sets the application context class loader
 void setClassResolver(ClassResolver resolver)
          Sets the class resolver to be use
 void setDataFormatResolver(DataFormatResolver dataFormatResolver)
          Sets a custom data format resolver
 void setDataFormats(Map<String,DataFormatDefinition> dataFormats)
          Sets the data formats that can be referenced in the routes.
 void setErrorHandlerBuilder(ErrorHandlerBuilder errorHandlerBuilder)
          Sets the default error handler builder which is inherited by the routes
 void setFactoryFinderResolver(FactoryFinderResolver resolver)
          Sets the factory finder resolver to use.
 void setInflightRepository(InflightRepository repository)
          Sets a custom inflight repository to use
 void setManagementStrategy(ManagementStrategy strategy)
          Sets the management strategy to use
 void setNodeIdFactory(NodeIdFactory factory)
          Uses a custom node id factory when generating auto assigned ids to the nodes in the route definitions
 void setPackageScanClassResolver(PackageScanClassResolver resolver)
          Sets the package scanning class resolver to use
 void setProducerServicePool(ServicePool<Endpoint,Producer> servicePool)
          Sets a pluggable service pool to use for Producer pooling.
 void setProperties(Map<String,String> properties)
          Sets the properties that can be referenced in the camel context
 void setShutdownStrategy(ShutdownStrategy shutdownStrategy)
          Sets a custom shutdown strategy
 void startRoute(RouteDefinition route)
          Starts the given route if it has been previously stopped
 void startRoute(String routeId)
          Starts the given route if it has been previously stopped
 void stopRoute(RouteDefinition route)
          Stops the given route.
 void stopRoute(String routeId)
          Stops the given route.
 
Methods inherited from interface org.apache.camel.Service
start, stop
 
Methods inherited from interface org.apache.camel.RuntimeConfiguration
getDelayer, getShutdownRoute, getShutdownRunningTask, isAutoStartup, isHandleFault, isStreamCaching, isTracing, setAutoStartup, setDelayer, setHandleFault, setShutdownRoute, setShutdownRunningTask, setStreamCaching, setTracing
 

Method Detail

getName

String getName()
Gets the name of the this context.

Returns:
the name

getVersion

String getVersion()
Gets the version of the this context.

Returns:
the version

addService

void addService(Object object)
                throws Exception
Adds a service, starting it so that it will be stopped with this context

Parameters:
object - the service
Throws:
Exception - can be thrown when starting the service

hasService

boolean hasService(Object object)
Has the given service already been added?

Parameters:
object - the service
Returns:
true if already added, false if not.

addComponent

void addComponent(String componentName,
                  Component component)
Adds a component to the context.

Parameters:
componentName - the name the component is registered as
component - the component

hasComponent

Component hasComponent(String componentName)
Is the given component already registered?

Parameters:
componentName - the name of the component
Returns:
the registered Component or null if not registered

getComponent

Component getComponent(String componentName)
Gets a component from the context by name.

Parameters:
componentName - the name of the component
Returns:
the component

getComponent

<T extends Component> T getComponent(String name,
                                     Class<T> componentType)
Gets a component from the context by name and specifying the expected type of component.

Parameters:
name - the name to lookup
componentType - the expected type
Returns:
the component

getComponentNames

List<String> getComponentNames()
Gets a readonly list of names of the components currently registered

Returns:
a readonly list with the names of the the components

removeComponent

Component removeComponent(String componentName)
Removes a previously added component.

Parameters:
componentName - the component name to remove
Returns:
the previously added component or null if it had not been previously added.

getOrCreateComponent

@Deprecated
Component getOrCreateComponent(String componentName,
                                          Callable<Component> factory)
Deprecated. will be removed in Camel 2.3.

Gets the a previously added component by name or lazily creates the component using the factory Callback.

Parameters:
componentName - the name of the component
factory - used to create a new component instance if the component was not previously added.
Returns:
the component

getEndpoint

Endpoint getEndpoint(String uri)
Resolves the given name to an Endpoint of the specified type. If the name has a singleton endpoint registered, then the singleton is returned. Otherwise, a new Endpoint is created and registered.

Parameters:
uri - the URI of the endpoint
Returns:
the endpoint

getEndpoint

<T extends Endpoint> T getEndpoint(String name,
                                   Class<T> endpointType)
Resolves the given name to an Endpoint of the specified type. If the name has a singleton endpoint registered, then the singleton is returned. Otherwise, a new Endpoint is created and registered.

Parameters:
name - the name of the endpoint
endpointType - the expected type
Returns:
the endpoint

getEndpoints

Collection<Endpoint> getEndpoints()
Returns the collection of all registered endpoints.

Returns:
all endpoints

getEndpointMap

Map<String,Endpoint> getEndpointMap()
Returns a new Map containing all of the active endpoints with the key of the map being their unique key.

Returns:
map of active endpoints

hasEndpoint

Endpoint hasEndpoint(String uri)
Is the given endpoint already registered?

Parameters:
uri - the URI of the endpoint
Returns:
the registered endpoint or null if not registered

getEndpoints

@Deprecated
Collection<Endpoint> getEndpoints(String uri)
Deprecated. not used will be removed in Camel 2.3.

Returns the collection of all registered endpoints for a uri or an empty collection. For a singleton endpoint the collection will contain exactly one element.

Parameters:
uri - the URI of the endpoints
Returns:
collection of endpoints

getSingletonEndpoints

@Deprecated
Collection<Endpoint> getSingletonEndpoints()
Deprecated. not used will be removed in Camel 2.3.

Returns the collection of all registered singleton endpoints.

Returns:
all the singleton endpoints

addEndpoint

Endpoint addEndpoint(String uri,
                     Endpoint endpoint)
                     throws Exception
Adds the endpoint to the context using the given URI.

Parameters:
uri - the URI to be used to resolve this endpoint
endpoint - the endpoint to be added to the context
Returns:
the old endpoint that was previously registered or null if none was registered
Throws:
Exception - if the new endpoint could not be started or the old endpoint could not be stopped

removeEndpoints

@Deprecated
Collection<Endpoint> removeEndpoints(String uri)
                                     throws Exception
Deprecated. not used will be removed in Camel 2.3.

Removes all endpoints with the given URI

Parameters:
uri - the URI to be used to remove
Returns:
a collection of endpoints removed or null if there are no endpoints for this URI
Throws:
Exception - if at least one endpoint could not be stopped

addRegisterEndpointCallback

void addRegisterEndpointCallback(EndpointStrategy strategy)
Registers a callback to allow you to do custom logic when an Endpoint is about to be registered to the CamelContext endpoint registry.

When a callback is added it will be executed on the already registered endpoints allowing you to catch-up

Parameters:
strategy - callback to be invoked

getRouteDefinitions

List<RouteDefinition> getRouteDefinitions()
Returns a list of the current route definitions

Returns:
list of the current route definitions

getRouteDefinition

RouteDefinition getRouteDefinition(String id)
Gets the route definition with the given id

Parameters:
id - id of the route
Returns:
the route definition or null if not found

getRoutes

List<Route> getRoutes()
Returns the current routes in this context

Returns:
the current routes

addRoutes

void addRoutes(RoutesBuilder builder)
               throws Exception
Adds a collection of routes to this context using the given builder to build them

Parameters:
builder - the builder which will create the routes and add them to this context
Throws:
Exception - if the routes could not be created for whatever reason

addRouteDefinitions

void addRouteDefinitions(Collection<RouteDefinition> routeDefinitions)
                         throws Exception
Adds a collection of route definitions to the context

Parameters:
routeDefinitions - the route definitions to add
Throws:
Exception - if the route definition could not be created for whatever reason

removeRouteDefinitions

void removeRouteDefinitions(Collection<RouteDefinition> routeDefinitions)
                            throws Exception
Removes a collection of route definitions from the context - stopping any previously running routes if any of them are actively running

Parameters:
routeDefinitions - route definitions
Throws:
Exception - if the route definition could not be removed for whatever reason

startRoute

void startRoute(RouteDefinition route)
                throws Exception
Starts the given route if it has been previously stopped

Parameters:
route - the route to start
Throws:
Exception - is thrown if the route could not be started for whatever reason

startRoute

void startRoute(String routeId)
                throws Exception
Starts the given route if it has been previously stopped

Parameters:
routeId - the route id
Throws:
Exception - is thrown if the route could not be started for whatever reason

stopRoute

void stopRoute(RouteDefinition route)
               throws Exception
Stops the given route. It will remain in the list of route definitions return by getRouteDefinitions() unless you use the removeRouteDefinitions(java.util.Collection)

Parameters:
route - the route to stop
Throws:
Exception - is thrown if the route could not be stopped for whatever reason

stopRoute

void stopRoute(String routeId)
               throws Exception
Stops the given route. It will remain in the list of route definitions return by getRouteDefinitions() unless you use the removeRouteDefinitions(java.util.Collection)

Parameters:
routeId - the route id
Throws:
Exception - is thrown if the route could not be stopped for whatever reason

getRouteStatus

ServiceStatus getRouteStatus(String routeId)
Returns the current status of the given route

Parameters:
routeId - the route id
Returns:
the status for the route

getRouteStatus

@Deprecated
ServiceStatus getRouteStatus(RouteDefinition route)
Deprecated. will be removed in Camel 2.3.

Returns the current status of the given route

Parameters:
route - the route
Returns:
the status for the route

getTypeConverter

TypeConverter getTypeConverter()
Returns the type converter used to coerce types from one type to another

Returns:
the converter

getTypeConverterRegistry

TypeConverterRegistry getTypeConverterRegistry()
Returns the type converter registry where type converters can be added or looked up

Returns:
the type converter registry

getRegistry

Registry getRegistry()
Returns the registry used to lookup components by name and type such as the Spring ApplicationContext, JNDI or the OSGi Service Registry

Returns:
the registry

getInjector

Injector getInjector()
Returns the injector used to instantiate objects by type

Returns:
the injector

getLifecycleStrategies

List<LifecycleStrategy> getLifecycleStrategies()
Returns the lifecycle strategies used to handle lifecycle notifications

Returns:
the lifecycle strategies

addLifecycleStrategy

void addLifecycleStrategy(LifecycleStrategy lifecycleStrategy)
Adds the given lifecycle strategy to be used.

Parameters:
lifecycleStrategy - the strategy

resolveLanguage

Language resolveLanguage(String language)
Resolves a language for creating expressions

Parameters:
language - name of the language
Returns:
the resolved language

getLanguageNames

List<String> getLanguageNames()
Gets a readonly list with the names of the languages currently registered.

Returns:
a readonly list with the names of the the languages

createProducerTemplate

ProducerTemplate createProducerTemplate()
Creates a new ProducerTemplate.

See this FAQ before use: Why does Camel use too many threads with ProducerTemplate?

Returns:
the template

createConsumerTemplate

ConsumerTemplate createConsumerTemplate()
Creates a new ConsumerTemplate.

See this FAQ before use: Why does Camel use too many threads with ProducerTemplate? as it also applies for ConsumerTemplate.

Returns:
the template

addInterceptStrategy

void addInterceptStrategy(InterceptStrategy interceptStrategy)
Adds the given interceptor strategy

Parameters:
interceptStrategy - the strategy

getInterceptStrategies

List<InterceptStrategy> getInterceptStrategies()
Gets the interceptor strategies

Returns:
the list of current interceptor strategies

getErrorHandlerBuilder

ErrorHandlerBuilder getErrorHandlerBuilder()
Gets the default error handler builder which is inherited by the routes

Returns:
the builder

setErrorHandlerBuilder

void setErrorHandlerBuilder(ErrorHandlerBuilder errorHandlerBuilder)
Sets the default error handler builder which is inherited by the routes

Parameters:
errorHandlerBuilder - the builder

setDataFormats

void setDataFormats(Map<String,DataFormatDefinition> dataFormats)
Sets the data formats that can be referenced in the routes.

Parameters:
dataFormats - the data formats

getDataFormats

Map<String,DataFormatDefinition> getDataFormats()
Gets the data formats that can be referenced in the routes.

Returns:
the data formats available

resolveDataFormat

DataFormat resolveDataFormat(String name)
Resolve a data format given its name

Parameters:
name - the data format name or a reference to it in the Registry
Returns:
the resolved data format, or null if not found

resolveDataFormatDefinition

DataFormatDefinition resolveDataFormatDefinition(String name)
Resolve a data format definition given its name

Parameters:
name - the data format definition name or a reference to it in the Registry
Returns:
the resolved data format definition, or null if not found

getDataFormatResolver

DataFormatResolver getDataFormatResolver()
Gets the current data format resolver

Returns:
the resolver

setDataFormatResolver

void setDataFormatResolver(DataFormatResolver dataFormatResolver)
Sets a custom data format resolver

Parameters:
dataFormatResolver - the resolver

setProperties

void setProperties(Map<String,String> properties)
Sets the properties that can be referenced in the camel context

Parameters:
properties - properties

getProperties

Map<String,String> getProperties()
Gets the properties that can be referenced in the camel context

Returns:
the properties

getDefaultFactoryFinder

FactoryFinder getDefaultFactoryFinder()
Gets the default FactoryFinder which will be used for the loading the factory class from META-INF

Returns:
the default factory finder

setFactoryFinderResolver

void setFactoryFinderResolver(FactoryFinderResolver resolver)
Sets the factory finder resolver to use.

Parameters:
resolver - the factory finder resolver

getFactoryFinder

FactoryFinder getFactoryFinder(String path)
                               throws NoFactoryAvailableException
Gets the FactoryFinder which will be used for the loading the factory class from META-INF in the given path

Parameters:
path - the META-INF path
Returns:
the factory finder
Throws:
NoFactoryAvailableException - is thrown if a factory could not be found

getClassResolver

ClassResolver getClassResolver()
Returns the class resolver to be used for loading/lookup of classes.

Returns:
the resolver

getPackageScanClassResolver

PackageScanClassResolver getPackageScanClassResolver()
Returns the package scanning class resolver

Returns:
the resolver

setClassResolver

void setClassResolver(ClassResolver resolver)
Sets the class resolver to be use

Parameters:
resolver - the resolver

setPackageScanClassResolver

void setPackageScanClassResolver(PackageScanClassResolver resolver)
Sets the package scanning class resolver to use

Parameters:
resolver - the resolver

setProducerServicePool

void setProducerServicePool(ServicePool<Endpoint,Producer> servicePool)
Sets a pluggable service pool to use for Producer pooling.

Parameters:
servicePool - the pool

getProducerServicePool

ServicePool<Endpoint,Producer> getProducerServicePool()
Gets the service pool for Producer pooling.

Returns:
the service pool

setNodeIdFactory

void setNodeIdFactory(NodeIdFactory factory)
Uses a custom node id factory when generating auto assigned ids to the nodes in the route definitions

Parameters:
factory - custom factory to use

getNodeIdFactory

NodeIdFactory getNodeIdFactory()
Gets the node id factory

Returns:
the node id factory

getManagementStrategy

ManagementStrategy getManagementStrategy()
Gets the management strategy

Returns:
the management strategy

setManagementStrategy

void setManagementStrategy(ManagementStrategy strategy)
Sets the management strategy to use

Parameters:
strategy - the management strategy

getDefaultTracer

InterceptStrategy getDefaultTracer()
Gets the default tracer

Returns:
the default tracer

disableJMX

void disableJMX()
Disables using JMX as ManagementStrategy.


getInflightRepository

InflightRepository getInflightRepository()
Gets the inflight repository

Returns:
the repository

setInflightRepository

void setInflightRepository(InflightRepository repository)
Sets a custom inflight repository to use

Parameters:
repository - the repository

getApplicationContextClassLoader

ClassLoader getApplicationContextClassLoader()
Gets the the application context class loader which may be helpful for running camel in other containers

Returns:
the application context class loader

setApplicationContextClassLoader

void setApplicationContextClassLoader(ClassLoader classLoader)
Sets the application context class loader

Parameters:
classLoader - the class loader

getShutdownStrategy

ShutdownStrategy getShutdownStrategy()
Gets the current shutdown strategy

Returns:
the strategy

setShutdownStrategy

void setShutdownStrategy(ShutdownStrategy shutdownStrategy)
Sets a custom shutdown strategy

Parameters:
shutdownStrategy - the custom strategy


Copyright © 2007-2010 IONA Open Source Community. All Rights Reserved.