Class 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

      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  
      • 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

      Constructors 
      Constructor Description
      DefaultRegistry()
      Creates a default registry that uses SimpleRegistry as the fallback registry.
      DefaultRegistry​(Collection<org.apache.camel.spi.BeanRepository> repositories)
      Creates a registry that uses the given BeanRepository as first choice bean repository to lookup beans.
      DefaultRegistry​(org.apache.camel.spi.BeanRepository... repositories)
      Creates a registry that uses the given BeanRepository 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 fallback Registry
      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 supplier Registry
      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 custom Registry 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 custom Registry 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 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 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​(org.apache.camel.spi.BeanRepository... repositories)
        Creates a registry that uses the given BeanRepository as first choice bean repository to lookup beans. Will fallback and use SimpleRegistry as fallback registry if the beans cannot be found in the first choice bean repository. The fallback registry can customized via setFallbackRegistry(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 given BeanRepository as first choice bean repository to lookup beans. Will fallback and use SimpleRegistry as fallback registry if the beans cannot be found in the first choice bean repository. The fallback registry can customized via setFallbackRegistry(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 interface org.apache.camel.spi.LocalBeanRepositoryAware
      • getLocalBeanRepository

        public org.apache.camel.spi.BeanRepository getLocalBeanRepository()
        Specified by:
        getLocalBeanRepository in interface org.apache.camel.spi.LocalBeanRepositoryAware
      • getFallbackRegistry

        public org.apache.camel.spi.Registry getFallbackRegistry()
        Gets the fallback Registry
      • setFallbackRegistry

        public void setFallbackRegistry​(org.apache.camel.spi.Registry fallbackRegistry)
        To use a custom Registry as fallback.
      • getSupplierRegistry

        public org.apache.camel.spi.Registry getSupplierRegistry()
        Gets the supplier Registry
      • setSupplierRegistry

        public void setSupplierRegistry​(org.apache.camel.spi.Registry supplierRegistry)
        To use a custom Registry for suppliers.
      • getCamelContext

        public org.apache.camel.CamelContext getCamelContext()
        Specified by:
        getCamelContext in interface org.apache.camel.CamelContextAware
      • setCamelContext

        public void setCamelContext​(org.apache.camel.CamelContext camelContext)
        Specified by:
        setCamelContext in interface org.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 interface org.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 interface org.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 interface org.apache.camel.spi.Registry
        Throws:
        org.apache.camel.RuntimeCamelException
      • unbind

        public void unbind​(String id)
        Specified by:
        unbind in interface org.apache.camel.spi.Registry
      • lookupByName

        public Object lookupByName​(String name)
        Specified by:
        lookupByName in interface org.apache.camel.spi.BeanRepository
      • lookupByNameAndType

        public <T> T lookupByNameAndType​(String name,
                                         Class<T> type)
        Specified by:
        lookupByNameAndType in interface org.apache.camel.spi.BeanRepository
      • findByTypeWithName

        public <T> Map<String,​T> findByTypeWithName​(Class<T> type)
        Specified by:
        findByTypeWithName in interface org.apache.camel.spi.BeanRepository
      • findByType

        public <T> Set<T> findByType​(Class<T> type)
        Specified by:
        findByType in interface org.apache.camel.spi.BeanRepository
      • doStop

        protected void doStop()
                       throws Exception
        Overrides:
        doStop in class org.apache.camel.support.service.BaseService
        Throws:
        Exception