org.apache.camel.impl
Class DefaultCamelContext

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.impl.DefaultCamelContext
All Implemented Interfaces:
CamelContext, Service

public class DefaultCamelContext
extends ServiceSupport
implements CamelContext, Service

Represents the context used to configure routes and the policies to use.

Version:
$Revision: 41272 $

Constructor Summary
DefaultCamelContext()
           
DefaultCamelContext(Context jndiContext)
          Creates the CamelContext using the given JNDI context as the registry
DefaultCamelContext(Registry registry)
          Creates the CamelContext using the given registry
 
Method Summary
 void addComponent(String componentName, Component component)
          Adds a component to the context.
 void addRouteDefinitions(Collection<RouteType> routeDefinitions)
          Adds a collection of route definitions to the context
 void addRoutes(Collection<Route> routes)
          Adds a collection of routes to this context
 void addRoutes(RouteBuilder 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
 Endpoint addSingletonEndpoint(String uri, Endpoint endpoint)
          Adds the endpoint to the context using the given URI.
protected  Endpoint convertBeanToEndpoint(String uri, Object bean)
          Attempt to convert the bean from a Registry to an endpoint using some kind of transformation or wrapper
protected  ComponentResolver createComponentResolver()
          Lazily create a default implementation
protected  Endpoint createEndpoint(String uri)
          A pluggable strategy to allow an endpoint to be created without requiring a component to be its factory, such as for looking up the URI inside some Registry
protected  ExchangeConverter createExchangeConverter()
          Lazily create a default implementation
protected  Injector createInjector()
          Lazily create a default implementation
protected  Registry createRegistry()
          Lazily create a default implementation
protected  TypeConverter createTypeConverter()
          Lazily create a default implementation
protected  void doStart()
           
protected  void doStop()
           
protected  void forceLazyInitialization()
          Lets force some lazy initialization to occur upfront before we start any components and create routes
 Component getComponent(String name)
          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.
 ComponentResolver getComponentResolver()
           
 Endpoint getEndpoint(String uri)
          Resolves the given URI to an Endpoint.
<T extends Endpoint>
T
getEndpoint(String name, Class<T> endpointType)
          Resolves the given URI to an Endpoint of the specified type.
 ExchangeConverter getExchangeConverter()
          Returns the converter of exchanges from one type to another
 Injector getInjector()
          Returns the injector used to instantiate objects by type
 LanguageResolver getLanguageResolver()
           
 LifecycleStrategy getLifecycleStrategy()
          Returns the lifecycle strategy used to handle lifecycle notification
 String getName()
          Gets the name of the this context.
 Component getOrCreateComponent(String componentName, Callable<Component> factory)
          Gets the a previously added component by name or lazily creates the component using the factory Callback.
 Registry getRegistry()
          Returns the registry used to lookup components by name and type such as the Spring ApplicationContext, JNDI or the OSGi Service Registry
 List<RouteType> getRouteDefinitions()
          Returns a list of the current route definitions
 List<Route> getRoutes()
          Returns the current routes in this context
 Collection<Endpoint> getSingletonEndpoints()
          Returns the collection of all registered singleton endpoints.
 TypeConverter getTypeConverter()
          Returns the type converter used to coerce types from one type to another
 boolean isAutoCreateComponents()
           
 Component removeComponent(String componentName)
          Removes a previously added component.
 Endpoint removeSingletonEndpoint(String uri)
          Removes the singleton endpoint with the given URI
 Language resolveLanguage(String language)
          Resolves a language for creating expressions
 void setAutoCreateComponents(boolean autoCreateComponents)
           
 void setComponentResolver(ComponentResolver componentResolver)
           
 void setExchangeConverter(ExchangeConverter exchangeConverter)
           
 void setInjector(Injector injector)
           
 void setLanguageResolver(LanguageResolver languageResolver)
           
 void setLifecycleStrategy(LifecycleStrategy lifecycleStrategy)
           
 void setName(String name)
          Sets the name of the this context.
 void setRegistry(Registry registry)
           
 void setRoutes(List<Route> routes)
          Sets the routes for this context, replacing any current routes
 void setTypeConverter(TypeConverter typeConverter)
           
protected  boolean shouldStartRoutes()
          Should we start newly added routes?
protected  void startRouteDefinitions(Collection<RouteType> list)
           
protected  void startRoutes(Collection<Route> routeList)
           
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, getThreadName, isRunAllowed, isStarted, isStarting, isStopped, isStopping, nextThreadCounter, removeChildService, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Constructor Detail

DefaultCamelContext

public DefaultCamelContext()

DefaultCamelContext

public DefaultCamelContext(Context jndiContext)
Creates the CamelContext using the given JNDI context as the registry

Parameters:
jndiContext -

DefaultCamelContext

public DefaultCamelContext(Registry registry)
Creates the CamelContext using the given registry

Method Detail

getName

public String getName()
Description copied from interface: CamelContext
Gets the name of the this context.

Specified by:
getName in interface CamelContext

setName

public void setName(String name)
Sets the name of the this context.


addComponent

public void addComponent(String componentName,
                         Component component)
Description copied from interface: CamelContext
Adds a component to the context.

Specified by:
addComponent in interface CamelContext

getComponent

public Component getComponent(String name)
Description copied from interface: CamelContext
Gets a component from the context by name.

Specified by:
getComponent in interface CamelContext

getComponent

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

Specified by:
getComponent in interface CamelContext

removeComponent

public Component removeComponent(String componentName)
Description copied from interface: CamelContext
Removes a previously added component.

Specified by:
removeComponent in interface CamelContext
Returns:
the previously added component or null if it had not been previously added.

getOrCreateComponent

public Component getOrCreateComponent(String componentName,
                                      Callable<Component> factory)
Description copied from interface: CamelContext
Gets the a previously added component by name or lazily creates the component using the factory Callback.

Specified by:
getOrCreateComponent in interface CamelContext
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

getSingletonEndpoints

public Collection<Endpoint> getSingletonEndpoints()
Description copied from interface: CamelContext
Returns the collection of all registered singleton endpoints.

Specified by:
getSingletonEndpoints in interface CamelContext

addSingletonEndpoint

public Endpoint addSingletonEndpoint(String uri,
                                     Endpoint endpoint)
                              throws Exception
Description copied from interface: CamelContext
Adds the endpoint to the context using the given URI. The endpoint will be registered as a singleton.

Specified by:
addSingletonEndpoint in interface CamelContext
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 to the context if there was already an endpoint for that URI
Throws:
Exception - if the new endpoint could not be started or the old endpoint could not be stopped

removeSingletonEndpoint

public Endpoint removeSingletonEndpoint(String uri)
                                 throws Exception
Description copied from interface: CamelContext
Removes the singleton endpoint with the given URI

Specified by:
removeSingletonEndpoint in interface CamelContext
Parameters:
uri - the URI to be used to remove
Returns:
the endpoint that was removed or null if there is no endpoint for this URI
Throws:
Exception - if endpoint could not be stopped

getEndpoint

public Endpoint getEndpoint(String uri)
Description copied from interface: CamelContext
Resolves the given URI to an Endpoint. If the URI has a singleton endpoint registered, then the singleton is returned. Otherwise, a new Endpoint is created and if the endpoint is a singleton it is registered as a singleton endpoint.

Specified by:
getEndpoint in interface CamelContext

getEndpoint

public <T extends Endpoint> T getEndpoint(String name,
                                          Class<T> endpointType)
Description copied from interface: CamelContext
Resolves the given URI to an Endpoint of the specified type. If the URI has a singleton endpoint registered, then the singleton is returned. Otherwise, a new Endpoint is created and if the endpoint is a singleton it is registered as a singleton endpoint.

Specified by:
getEndpoint in interface CamelContext

getRoutes

public List<Route> getRoutes()
Description copied from interface: CamelContext
Returns the current routes in this context

Specified by:
getRoutes in interface CamelContext

setRoutes

public void setRoutes(List<Route> routes)
Description copied from interface: CamelContext
Sets the routes for this context, replacing any current routes

Specified by:
setRoutes in interface CamelContext
Parameters:
routes - the new routes to use

addRoutes

public void addRoutes(Collection<Route> routes)
               throws Exception
Description copied from interface: CamelContext
Adds a collection of routes to this context

Specified by:
addRoutes in interface CamelContext
Parameters:
routes - the routes to add
Throws:
Exception

addRoutes

public void addRoutes(RouteBuilder builder)
               throws Exception
Description copied from interface: CamelContext
Adds a collection of routes to this context using the given builder to build them

Specified by:
addRoutes in interface CamelContext
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

public void addRouteDefinitions(Collection<RouteType> routeDefinitions)
                         throws Exception
Description copied from interface: CamelContext
Adds a collection of route definitions to the context

Specified by:
addRouteDefinitions in interface CamelContext
Throws:
Exception

addService

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

Throws:
Exception

resolveLanguage

public Language resolveLanguage(String language)
Description copied from interface: CamelContext
Resolves a language for creating expressions

Specified by:
resolveLanguage in interface CamelContext

getExchangeConverter

public ExchangeConverter getExchangeConverter()
Description copied from interface: CamelContext
Returns the converter of exchanges from one type to another

Specified by:
getExchangeConverter in interface CamelContext

setExchangeConverter

public void setExchangeConverter(ExchangeConverter exchangeConverter)

getTypeConverter

public TypeConverter getTypeConverter()
Description copied from interface: CamelContext
Returns the type converter used to coerce types from one type to another

Specified by:
getTypeConverter in interface CamelContext

setTypeConverter

public void setTypeConverter(TypeConverter typeConverter)

getInjector

public Injector getInjector()
Description copied from interface: CamelContext
Returns the injector used to instantiate objects by type

Specified by:
getInjector in interface CamelContext

setInjector

public void setInjector(Injector injector)

getComponentResolver

public ComponentResolver getComponentResolver()

setComponentResolver

public void setComponentResolver(ComponentResolver componentResolver)

getLanguageResolver

public LanguageResolver getLanguageResolver()

setLanguageResolver

public void setLanguageResolver(LanguageResolver languageResolver)

isAutoCreateComponents

public boolean isAutoCreateComponents()

setAutoCreateComponents

public void setAutoCreateComponents(boolean autoCreateComponents)

getRegistry

public Registry getRegistry()
Description copied from interface: CamelContext
Returns the registry used to lookup components by name and type such as the Spring ApplicationContext, JNDI or the OSGi Service Registry

Specified by:
getRegistry in interface CamelContext

setRegistry

public void setRegistry(Registry registry)

getLifecycleStrategy

public LifecycleStrategy getLifecycleStrategy()
Description copied from interface: CamelContext
Returns the lifecycle strategy used to handle lifecycle notification

Specified by:
getLifecycleStrategy in interface CamelContext

setLifecycleStrategy

public void setLifecycleStrategy(LifecycleStrategy lifecycleStrategy)

getRouteDefinitions

public List<RouteType> getRouteDefinitions()
Description copied from interface: CamelContext
Returns a list of the current route definitions

Specified by:
getRouteDefinitions in interface CamelContext

doStart

protected void doStart()
                throws Exception
Specified by:
doStart in class ServiceSupport
Throws:
Exception

startRouteDefinitions

protected void startRouteDefinitions(Collection<RouteType> list)
                              throws Exception
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Specified by:
doStop in class ServiceSupport
Throws:
Exception

startRoutes

protected void startRoutes(Collection<Route> routeList)
                    throws Exception
Throws:
Exception

forceLazyInitialization

protected void forceLazyInitialization()
Lets force some lazy initialization to occur upfront before we start any components and create routes


createExchangeConverter

protected ExchangeConverter createExchangeConverter()
Lazily create a default implementation


createTypeConverter

protected TypeConverter createTypeConverter()
Lazily create a default implementation


createInjector

protected Injector createInjector()
Lazily create a default implementation


createComponentResolver

protected ComponentResolver createComponentResolver()
Lazily create a default implementation


createRegistry

protected Registry createRegistry()
Lazily create a default implementation


createEndpoint

protected Endpoint createEndpoint(String uri)
A pluggable strategy to allow an endpoint to be created without requiring a component to be its factory, such as for looking up the URI inside some Registry

Parameters:
uri - the uri for the endpoint to be created
Returns:
the newly created endpoint or null if it could not be resolved

convertBeanToEndpoint

protected Endpoint convertBeanToEndpoint(String uri,
                                         Object bean)
Attempt to convert the bean from a Registry to an endpoint using some kind of transformation or wrapper

Parameters:
uri - the uri for the endpoint (and name in the registry)
bean - the bean to be converted to an endpoint, which will be not null
Returns:
a new endpoint

shouldStartRoutes

protected boolean shouldStartRoutes()
Should we start newly added routes?



Copyright © 2008 IONA Open Source Community. All Rights Reserved.