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.CamelContextAwareThe defaultRegistrywhich supports using a given first-choice repository to lookup the beans, such as Spring, JNDI, OSGi etc. And to use a secondarySimpleRegistryas 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.CamelContextcamelContextprotected org.apache.camel.spi.RegistryfallbackRegistryprotected ThreadLocal<org.apache.camel.spi.BeanRepository>localRepositoryprotected booleanlocalRepositoryEnabledprotected List<org.apache.camel.spi.BeanRepository>repositoriesprotected org.apache.camel.spi.RegistrysupplierRegistry
-
Constructor Summary
Constructors Constructor Description DefaultRegistry()Creates a default registry that usesSimpleRegistryas the fallback registry.DefaultRegistry(Collection<org.apache.camel.spi.BeanRepository> repositories)Creates a registry that uses the givenBeanRepositoryas first choice bean repository to lookup beans.DefaultRegistry(org.apache.camel.spi.BeanRepository... repositories)Creates a registry that uses the givenBeanRepositoryas first choice bean repository to lookup beans.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind(String id, Class<?> type, Object bean)voidbind(String id, Class<?> type, Supplier<Object> bean)voidbindAsPrototype(String id, Class<?> type, Supplier<Object> bean)protected voiddoStop()<T> Set<T>findByType(Class<T> type)<T> Map<String,T>findByTypeWithName(Class<T> type)org.apache.camel.CamelContextgetCamelContext()org.apache.camel.spi.RegistrygetFallbackRegistry()Gets the fallbackRegistryorg.apache.camel.spi.BeanRepositorygetLocalBeanRepository()List<org.apache.camel.spi.BeanRepository>getRepositories()Gets the bean repositories.org.apache.camel.spi.RegistrygetSupplierRegistry()Gets the supplierRegistryObjectlookupByName(String name)<T> TlookupByNameAndType(String name, Class<T> type)voidsetCamelContext(org.apache.camel.CamelContext camelContext)voidsetFallbackRegistry(org.apache.camel.spi.Registry fallbackRegistry)To use a customRegistryas fallback.voidsetLocalBeanRepository(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.voidsetSupplierRegistry(org.apache.camel.spi.Registry supplierRegistry)To use a customRegistryfor suppliers.voidunbind(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 usesSimpleRegistryas 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 givenBeanRepositoryas first choice bean repository to lookup beans. Will fallback and useSimpleRegistryas 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 givenBeanRepositoryas first choice bean repository to lookup beans. Will fallback and useSimpleRegistryas 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:
setLocalBeanRepositoryin interfaceorg.apache.camel.spi.LocalBeanRepositoryAware
-
getLocalBeanRepository
public org.apache.camel.spi.BeanRepository getLocalBeanRepository()
- Specified by:
getLocalBeanRepositoryin 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 customRegistryas 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 customRegistryfor suppliers.
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()
- Specified by:
getCamelContextin interfaceorg.apache.camel.CamelContextAware
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext camelContext)
- Specified by:
setCamelContextin 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:
bindin 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:
bindin 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:
bindAsPrototypein interfaceorg.apache.camel.spi.Registry- Throws:
org.apache.camel.RuntimeCamelException
-
unbind
public void unbind(String id)
- Specified by:
unbindin interfaceorg.apache.camel.spi.Registry
-
lookupByName
public Object lookupByName(String name)
- Specified by:
lookupByNamein interfaceorg.apache.camel.spi.BeanRepository
-
lookupByNameAndType
public <T> T lookupByNameAndType(String name, Class<T> type)
- Specified by:
lookupByNameAndTypein interfaceorg.apache.camel.spi.BeanRepository
-
findByTypeWithName
public <T> Map<String,T> findByTypeWithName(Class<T> type)
- Specified by:
findByTypeWithNamein interfaceorg.apache.camel.spi.BeanRepository
-
findByType
public <T> Set<T> findByType(Class<T> type)
- Specified by:
findByTypein interfaceorg.apache.camel.spi.BeanRepository
-
-