Class GemfireBeanFactoryLocator

java.lang.Object
org.springframework.data.gemfire.support.GemfireBeanFactoryLocator
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean

public class GemfireBeanFactoryLocator extends Object implements org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean
The GemfireBeanFactoryLocator class stores a reference to the Spring ApplicationContext / BeanFactory needed to auto-wire user application Apache Geode objects implementing the Declarable interface and defined in Apache Geode's native configuration format (e.g. cache.xml. In most cases, a developer does not need to use this class directly as it is registered by the CacheFactoryBean or LocatorFactoryBean when the useBeanFactoryLocator property is set, and used internally by both the WiringDeclarableSupport and LazyWiringDeclarableSupport SDG classes.
See Also:
  • Field Details

    • BEAN_FACTORIES

      protected static final ConcurrentMap<String,org.springframework.beans.factory.BeanFactory> BEAN_FACTORIES
    • logger

      protected final org.slf4j.Logger logger
  • Constructor Details

    • GemfireBeanFactoryLocator

      public GemfireBeanFactoryLocator()
  • Method Details

    • clear

      public static void clear()
      Cleans up all BeanFactory references tracked by this locator.
    • newBeanFactoryLocator

      @NonNull public static GemfireBeanFactoryLocator newBeanFactoryLocator()
      Factory method used to construct a new instance of GemfireBeanFactoryLocator. The afterPropertiesSet() will be called after construction to initialize this locator.
      Returns:
      a new, initialized instance of the GemfireBeanFactoryLocator.
      See Also:
    • newBeanFactoryLocator

      @NonNull public static GemfireBeanFactoryLocator newBeanFactoryLocator(org.springframework.beans.factory.BeanFactory beanFactory, String associatedBeanName)
      Factory method used to construct a new instance of GemfireBeanFactoryLocator initialized with the given, default Spring BeanFactory and associated Spring bean name. The afterPropertiesSet() will be called after construction to initialize this locator.
      Parameters:
      beanFactory - reference to the Spring BeanFactory used to resolve Spring bean references.
      associatedBeanName - String containing the name of the Spring bean associated with the Spring BeanFactory.
      Returns:
      a new GemfireBeanFactoryLocator initialized with the given, default Spring BeanFactory and associated Spring bean name.
      See Also:
    • resolveBeanFactory

      @Nullable protected static org.springframework.beans.factory.BeanFactory resolveBeanFactory(@NonNull String beanFactoryKey)
      Resolves the BeanFactory mapped to the given beanFactoryKey.
      Parameters:
      beanFactoryKey - String containing a key used to lookup the BeanFactory.
      Returns:
      the BeanFactory mapped to the given key.
      Throws:
      IllegalArgumentException - if a Spring BeanFactory could not be found for the given beanFactoryKey.
      See Also:
      • BeanFactory
    • resolveSingleBeanFactory

      @Nullable protected static org.springframework.beans.factory.BeanFactory resolveSingleBeanFactory()
      Resolves a single Spring BeanFactory from the mapping of registered BeanFactories. This class method is synchronized because it contains a "compound action", even though separate actions are performed on a ConcurrentMap, the actions are not independent and therefore must operate atomically.
      Returns:
      a single Spring BeanFactory from the registry.
      Throws:
      IllegalStateException - if the registry contains more than 1 registered Spring BeanFactory, or no Spring BeanFactories.
      See Also:
      • BeanFactory
    • registerAliases

      protected static void registerAliases(Set<String> names, org.springframework.beans.factory.BeanFactory beanFactory)
      Registers all the provided names for given Spring BeanFactory.
      Parameters:
      names - Set of names and aliases to associate with the Spring BeanFactory.
      beanFactory - reference to the Spring BeanFactory.
      Throws:
      IllegalArgumentException - if BeanFactory is null.
      IllegalStateException - if one of the provided names is already associated with an existing, other than given, Spring BeanFactory.
      See Also:
      • BeanFactory
      • BeanFactory
    • unregisterAliases

      protected static boolean unregisterAliases(Set<String> names)
      Removes all Spring BeanFactory associations/mappings for the given Set of names.
      Parameters:
      names - Set of names identifying the associations/mappings to remove.
      Returns:
      a boolean value indicating whether all associations/mappings were removed successfully.
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
    • useBeanFactory

      public org.springframework.beans.factory.BeanFactory useBeanFactory()
      Attempts to use a single, existing Spring BeanFactory from the registry based on the setBeanName(String) beanName} property.
      Returns:
      the single Spring BeanFactory from the registry.
      Throws:
      IllegalArgumentException - if more than Spring BeanFactory is registered.
      IllegalStateException - if the BeanFactory with the associated beanName is not found.
      See Also:
    • useBeanFactory

      public org.springframework.beans.factory.BeanFactory useBeanFactory(String beanFactoryKey)
      Attempts to use the Spring BeanFactory idenified by the given beanFactoryKey.
      Parameters:
      beanFactoryKey - String containing the key used to lookup the Spring BeanFactory.
      Returns:
      the Spring BeanFactory for the given beanFactoryKey.
      Throws:
      IllegalArgumentException - if a Spring BeanFactory could not be found for beanFactoryKey.
      IllegalStateException - if useBeanFactoryLocator was not configured.
      See Also:
    • setBeanFactory

      public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
    • getBeanFactory

      protected org.springframework.beans.factory.BeanFactory getBeanFactory()
      Returns a reference to the BeanFactory managed by this GemfireBeanFactoryLocator instance; Might be null if this GemfireBeanFactoryLocator is just used to lookup an existing BeanFactory reference.
      Returns:
      the managed BeanFactory reference.
      See Also:
      • BeanFactory
    • setBeanName

      public void setBeanName(String name)
      Specified by:
      setBeanName in interface org.springframework.beans.factory.BeanNameAware
    • getAssociatedBeanName

      protected String getAssociatedBeanName()
      Gets the name of the Spring bean associated with the Spring BeanFactory that possibly created the bean.
      Returns:
      a String containing the name of the Spring bean associated with the Spring BeanFactory.
      See Also:
    • getAssociatedBeanNameWithAliases

      protected Set<String> getAssociatedBeanNameWithAliases()
      Returns a Set of all names and aliases assigned to the Spring bean that is associated with the Spring BeanFactory.
      Returns:
      a Set containing all the names and aliases assigned to the Spring bean associated with the Spring BeanFactory.
      See Also:
    • withBeanName

      public GemfireBeanFactoryLocator withBeanName(String beanName)
      Builder method to set the bean name used by this locator to lookup a Spring BeanFactory.
      Parameters:
      beanName - String containing the bean name to set on this locator.
      Returns:
      this GemfireBeanFactoryLocator.
      See Also: