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 default
Registry
which supports using a given first-choice repository to lookup the beans, such as
Spring, JNDI, OSGi etc. And to use a secondary SimpleRegistry
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
FieldsModifier and TypeFieldDescriptionprotected org.apache.camel.CamelContext
protected org.apache.camel.spi.Registry
protected final ThreadLocal<org.apache.camel.spi.BeanRepository>
protected boolean
protected List<org.apache.camel.spi.BeanRepository>
protected org.apache.camel.spi.Registry
Fields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionvoid
void
void
bindAsPrototype
(String id, Class<?> type, Supplier<Object> bean) protected void
doStop()
<T> Set<T>
findByType
(Class<T> type) findByTypeWithName
(Class<T> type) org.apache.camel.CamelContext
org.apache.camel.spi.Registry
Gets the fallbackRegistry
org.apache.camel.spi.BeanRepository
List<org.apache.camel.spi.BeanRepository>
Gets the bean repositories.org.apache.camel.spi.Registry
Gets the supplierRegistry
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
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
Methods inherited from interface org.apache.camel.spi.BeanRepository
findSingleByType, unwrap
Methods inherited from interface org.apache.camel.spi.Registry
bind, wrap
Methods inherited from interface org.apache.camel.Service
build, close, init, start, stop
Methods inherited from interface org.apache.camel.ShutdownableService
shutdown
Methods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
Methods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Field Details
-
camelContext
protected org.apache.camel.CamelContext camelContext -
localRepository
-
localRepositoryEnabled
protected volatile boolean localRepositoryEnabled -
repositories
-
fallbackRegistry
protected org.apache.camel.spi.Registry fallbackRegistry -
supplierRegistry
protected org.apache.camel.spi.Registry supplierRegistry
-
-
Constructor Details
-
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
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 Details
-
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
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
- Specified by:
unbind
in interfaceorg.apache.camel.spi.Registry
-
lookupByName
- Specified by:
lookupByName
in interfaceorg.apache.camel.spi.BeanRepository
-
lookupByNameAndType
- Specified by:
lookupByNameAndType
in interfaceorg.apache.camel.spi.BeanRepository
-
findByTypeWithName
- Specified by:
findByTypeWithName
in interfaceorg.apache.camel.spi.BeanRepository
-
findByType
- Specified by:
findByType
in interfaceorg.apache.camel.spi.BeanRepository
-
doStop
- Overrides:
doStop
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-