public class GemfireBeanFactoryLocator extends Object implements BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean
GemfireBeanFactoryLocator class stores a reference to the Spring
ApplicationContext / BeanFactory needed to auto-wire
user application GemFire objects implementing the Declarable interface
and defined in GemFire'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 when the useBeanFactoryLocator property
is set, and used internally by bothe the WiringDeclarableSupport and LazyWiringDeclarableSupport
SDG classes.LazyWiringDeclarableSupport,
WiringDeclarableSupport| Modifier and Type | Class and Description |
|---|---|
protected static class |
GemfireBeanFactoryLocator.BeanFactoryReference
Reference holder storing a reference to a Spring
BeanFactory. |
| Modifier and Type | Field and Description |
|---|---|
protected static ConcurrentMap<String,BeanFactory> |
BEAN_FACTORIES |
protected org.slf4j.Logger |
logger |
| Constructor and Description |
|---|
GemfireBeanFactoryLocator() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
static void |
clear()
Cleans up all
BeanFactory references tracked by this locator. |
void |
destroy() |
protected String |
getAssociatedBeanName()
Gets the name of the Spring bean associated with the Spring
BeanFactory that possibly created the bean. |
protected Set<String> |
getAssociatedBeanNameWithAliases()
Returns a
Set of all names and aliases assigned to the Spring bean that is associated with
the Spring BeanFactory. |
protected 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. |
static GemfireBeanFactoryLocator |
newBeanFactoryLocator()
Factory method to construct a new, initialized instance of
GemfireBeanFactoryLocator. |
static GemfireBeanFactoryLocator |
newBeanFactoryLocator(BeanFactory beanFactory,
String associatedBeanName)
Factory method to construct a new, initialized instance of
GemfireBeanFactoryLocator with the given
default Spring BeanFactory and associated Spring bean name. |
protected static void |
registerAliases(Set<String> names,
BeanFactory beanFactory)
Registers all the provided names for given Spring
BeanFactory. |
protected static BeanFactory |
resolveBeanFactory(String beanFactoryKey)
Resolves the
BeanFactory mapped to the given beanFactoryKey. |
protected static BeanFactory |
resolveSingleBeanFactory()
Resolves a single Spring
BeanFactory from the mapping of registered bean factories. |
void |
setBeanFactory(BeanFactory beanFactory) |
void |
setBeanName(String name) |
protected static boolean |
unregisterAliases(Set<String> names)
Removes all Spring
BeanFactory associations/mappings for the given Set of names. |
BeanFactory |
useBeanFactory()
Attempts to use a single, existing Spring
BeanFactory from the registry based on
the setBeanName(String) beanName} property. |
BeanFactory |
useBeanFactory(String beanFactoryKey)
Attempts to use the Spring
BeanFactory idenified by the given beanFactoryKey. |
GemfireBeanFactoryLocator |
withBeanName(String beanName)
Builder method to set the bean name used by this locator to lookup a Spring
BeanFactory. |
protected static final ConcurrentMap<String,BeanFactory> BEAN_FACTORIES
protected final org.slf4j.Logger logger
public static void clear()
BeanFactory references tracked by this locator.public static GemfireBeanFactoryLocator newBeanFactoryLocator()
GemfireBeanFactoryLocator.GemfireBeanFactoryLocator.GemfireBeanFactoryLocator,
GemfireBeanFactoryLocator(),
afterPropertiesSet()public static GemfireBeanFactoryLocator newBeanFactoryLocator(BeanFactory beanFactory, String associatedBeanName)
GemfireBeanFactoryLocator with the given
default Spring BeanFactory and associated Spring bean name.beanFactory - reference to the BeanFactory used to resolve Spring bean references.associatedBeanName - String contain the name of the Spring bean associated with
the Spring BeanFactory.GemfireBeanFactoryLocator with the given default
Spring BeanFactory and associated Spring bean name.BeanFactory,
GemfireBeanFactoryLocator,
GemfireBeanFactoryLocator(),
setBeanFactory(BeanFactory),
setBeanName(String),
afterPropertiesSet()protected static BeanFactory resolveBeanFactory(String beanFactoryKey)
BeanFactory mapped to the given beanFactoryKey.beanFactoryKey - String value containing the key used to lookup the BeanFactory.BeanFactory mapped to the given key.IllegalArgumentException - if a Spring BeanFactory could not be found
for the given beanFactoryKey.BeanFactoryprotected static BeanFactory resolveSingleBeanFactory()
BeanFactory from the mapping of registered bean factories.
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.BeanFactory from the registry.IllegalStateException - if the registry contains more than 1, or no
Spring bean factories.BeanFactoryprotected static void registerAliases(Set<String> names, BeanFactory beanFactory)
BeanFactory.names - Set of names and aliases to associate with the Spring BeanFactory.beanFactory - reference to the Spring BeanFactory.IllegalArgumentException - if BeanFactory is null.IllegalStateException - if one of the provided names is already associated with
an existing, other than given, Spring BeanFactory.BeanFactory,
BeanFactoryprotected static boolean unregisterAliases(Set<String> names)
BeanFactory associations/mappings for the given Set of names.names - Set of names identifying the associations/mappings to remove.public void afterPropertiesSet()
afterPropertiesSet in interface InitializingBeanpublic void destroy()
destroy in interface DisposableBeanpublic BeanFactory useBeanFactory()
BeanFactory from the registry based on
the setBeanName(String) beanName} property.BeanFactory from the registry.IllegalArgumentException - if more than Spring BeanFactory is registered.IllegalStateException - if the BeanFactory with the associated
beanName is not found.BeanFactory,
getAssociatedBeanName(),
useBeanFactory(String)public BeanFactory useBeanFactory(String beanFactoryKey)
BeanFactory idenified by the given beanFactoryKey.beanFactoryKey - String containing the key used to lookup the Spring BeanFactory.BeanFactory for the given beanFactoryKey.IllegalArgumentException - if a Spring BeanFactory could not be found for beanFactoryKey.IllegalStateException - if useBeanFactoryLocator was not configured.BeanFactory,
GemfireBeanFactoryLocator.BeanFactoryReference.newBeanFactoryReference(BeanFactory),
resolveBeanFactory(String),
resolveSingleBeanFactory()public void setBeanFactory(BeanFactory beanFactory)
setBeanFactory in interface BeanFactoryAwareprotected BeanFactory getBeanFactory()
BeanFactory managed by this GemfireBeanFactoryLocator instance;
Might be null if this GemfireBeanFactoryLocator is just used to lookup
an existing BeanFactory reference.BeanFactory reference.BeanFactorypublic void setBeanName(String name)
setBeanName in interface BeanNameAwareprotected String getAssociatedBeanName()
BeanFactory that possibly created the bean.String containing the name of the Spring bean associated with the Spring BeanFactory.setBeanFactory(BeanFactory)protected Set<String> getAssociatedBeanNameWithAliases()
Set of all names and aliases assigned to the Spring bean that is associated with
the Spring BeanFactory.Set containing all the names and aliases assigned to the Spring bean associated with
the Spring BeanFactory.setBeanName(String)public GemfireBeanFactoryLocator withBeanName(String beanName)
BeanFactory.beanName - String containing the bean name to set on this locator.GemfireBeanFactoryLocator.setBeanName(String)Copyright © 2011–2020 Pivotal Software, Inc.. All rights reserved.