Package org.apache.camel.support
Class DefaultRegistry
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.support.DefaultRegistry
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.CamelContextAware
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.BeanRepository
,org.apache.camel.spi.LocalBeanRepositoryAware
,org.apache.camel.spi.Registry
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
public class DefaultRegistry extends org.apache.camel.support.service.ServiceSupport implements org.apache.camel.spi.Registry, org.apache.camel.spi.LocalBeanRepositoryAware, org.apache.camel.CamelContextAware
The defaultRegistry
which supports using a given first-choice repository to lookup the beans, such as Spring, JNDI, OSGi etc. And to use a secondarySimpleRegistry
as the fallback repository to lookup and bind beans. Notice that beans in the fallback registry are not managed by the first-choice registry, so these beans may not support dependency injection and other features that the first-choice registry may offer.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.camel.CamelContext
camelContext
protected org.apache.camel.spi.Registry
fallbackRegistry
protected ThreadLocal<org.apache.camel.spi.BeanRepository>
localRepository
protected boolean
localRepositoryEnabled
protected List<org.apache.camel.spi.BeanRepository>
repositories
protected org.apache.camel.spi.Registry
supplierRegistry
-
Constructor Summary
Constructors Constructor Description DefaultRegistry()
Creates a default registry that usesSimpleRegistry
as the fallback registry.DefaultRegistry(Collection<org.apache.camel.spi.BeanRepository> repositories)
Creates a registry that uses the givenBeanRepository
as first choice bean repository to lookup beans.DefaultRegistry(org.apache.camel.spi.BeanRepository... repositories)
Creates a registry that uses the givenBeanRepository
as first choice bean repository to lookup beans.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bind(String id, Class<?> type, Object bean)
void
bind(String id, Class<?> type, Supplier<Object> bean)
void
bindAsPrototype(String id, Class<?> type, Supplier<Object> bean)
protected void
doStop()
<T> Set<T>
findByType(Class<T> type)
<T> Map<String,T>
findByTypeWithName(Class<T> type)
org.apache.camel.CamelContext
getCamelContext()
org.apache.camel.spi.Registry
getFallbackRegistry()
Gets the fallbackRegistry
org.apache.camel.spi.BeanRepository
getLocalBeanRepository()
List<org.apache.camel.spi.BeanRepository>
getRepositories()
Gets the bean repositories.org.apache.camel.spi.Registry
getSupplierRegistry()
Gets the supplierRegistry
Object
lookupByName(String name)
<T> T
lookupByNameAndType(String name, Class<T> type)
void
setCamelContext(org.apache.camel.CamelContext camelContext)
void
setFallbackRegistry(org.apache.camel.spi.Registry fallbackRegistry)
To use a customRegistry
as fallback.void
setLocalBeanRepository(org.apache.camel.spi.BeanRepository repository)
Sets a special local bean repository (ie thread local) that take precedence and will use first, if a bean exists.void
setSupplierRegistry(org.apache.camel.spi.Registry supplierRegistry)
To use a customRegistry
for suppliers.void
unbind(String id)
-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doInit, doLifecycleChange, doResume, doShutdown, doStart, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Field Detail
-
camelContext
protected org.apache.camel.CamelContext camelContext
-
localRepository
protected final ThreadLocal<org.apache.camel.spi.BeanRepository> localRepository
-
localRepositoryEnabled
protected volatile boolean localRepositoryEnabled
-
repositories
protected List<org.apache.camel.spi.BeanRepository> repositories
-
fallbackRegistry
protected org.apache.camel.spi.Registry fallbackRegistry
-
supplierRegistry
protected org.apache.camel.spi.Registry supplierRegistry
-
-
Constructor Detail
-
DefaultRegistry
public DefaultRegistry()
Creates a default registry that usesSimpleRegistry
as the fallback registry. The fallback registry can customized viasetFallbackRegistry(Registry)
.
-
DefaultRegistry
public DefaultRegistry(org.apache.camel.spi.BeanRepository... repositories)
Creates a registry that uses the givenBeanRepository
as first choice bean repository to lookup beans. Will fallback and useSimpleRegistry
as fallback registry if the beans cannot be found in the first choice bean repository. The fallback registry can customized viasetFallbackRegistry(Registry)
.- Parameters:
repositories
- the first choice repositories such as Spring, JNDI, OSGi etc.
-
DefaultRegistry
public DefaultRegistry(Collection<org.apache.camel.spi.BeanRepository> repositories)
Creates a registry that uses the givenBeanRepository
as first choice bean repository to lookup beans. Will fallback and useSimpleRegistry
as fallback registry if the beans cannot be found in the first choice bean repository. The fallback registry can customized viasetFallbackRegistry(Registry)
.- Parameters:
repositories
- the first choice repositories such as Spring, JNDI, OSGi etc.
-
-
Method Detail
-
setLocalBeanRepository
public void setLocalBeanRepository(org.apache.camel.spi.BeanRepository repository)
Sets a special local bean repository (ie thread local) that take precedence and will use first, if a bean exists.- Specified by:
setLocalBeanRepository
in interfaceorg.apache.camel.spi.LocalBeanRepositoryAware
-
getLocalBeanRepository
public org.apache.camel.spi.BeanRepository getLocalBeanRepository()
- Specified by:
getLocalBeanRepository
in interfaceorg.apache.camel.spi.LocalBeanRepositoryAware
-
getFallbackRegistry
public org.apache.camel.spi.Registry getFallbackRegistry()
Gets the fallbackRegistry
-
setFallbackRegistry
public void setFallbackRegistry(org.apache.camel.spi.Registry fallbackRegistry)
To use a customRegistry
as fallback.
-
getSupplierRegistry
public org.apache.camel.spi.Registry getSupplierRegistry()
Gets the supplierRegistry
-
setSupplierRegistry
public void setSupplierRegistry(org.apache.camel.spi.Registry supplierRegistry)
To use a customRegistry
for suppliers.
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()
- Specified by:
getCamelContext
in interfaceorg.apache.camel.CamelContextAware
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext camelContext)
- Specified by:
setCamelContext
in interfaceorg.apache.camel.CamelContextAware
-
getRepositories
public List<org.apache.camel.spi.BeanRepository> getRepositories()
Gets the bean repositories.- Returns:
- the bean repositories, or null if none are in use.
-
bind
public void bind(String id, Class<?> type, Object bean) throws org.apache.camel.RuntimeCamelException
- Specified by:
bind
in interfaceorg.apache.camel.spi.Registry
- Throws:
org.apache.camel.RuntimeCamelException
-
bind
public void bind(String id, Class<?> type, Supplier<Object> bean) throws org.apache.camel.RuntimeCamelException
- Specified by:
bind
in interfaceorg.apache.camel.spi.Registry
- Throws:
org.apache.camel.RuntimeCamelException
-
bindAsPrototype
public void bindAsPrototype(String id, Class<?> type, Supplier<Object> bean) throws org.apache.camel.RuntimeCamelException
- Specified by:
bindAsPrototype
in interfaceorg.apache.camel.spi.Registry
- Throws:
org.apache.camel.RuntimeCamelException
-
unbind
public void unbind(String id)
- Specified by:
unbind
in interfaceorg.apache.camel.spi.Registry
-
lookupByName
public Object lookupByName(String name)
- Specified by:
lookupByName
in interfaceorg.apache.camel.spi.BeanRepository
-
lookupByNameAndType
public <T> T lookupByNameAndType(String name, Class<T> type)
- Specified by:
lookupByNameAndType
in interfaceorg.apache.camel.spi.BeanRepository
-
findByTypeWithName
public <T> Map<String,T> findByTypeWithName(Class<T> type)
- Specified by:
findByTypeWithName
in interfaceorg.apache.camel.spi.BeanRepository
-
findByType
public <T> Set<T> findByType(Class<T> type)
- Specified by:
findByType
in interfaceorg.apache.camel.spi.BeanRepository
-
-