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 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.BeanFactory
,
BeanFactoryAware
,
BeanNameAware
,
DisposableBean
,
InitializingBean
,
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 used to construct a new instance of
GemfireBeanFactoryLocator . |
static GemfireBeanFactoryLocator |
newBeanFactoryLocator(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 . |
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 BeanFactories . |
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.@NonNull public static GemfireBeanFactoryLocator newBeanFactoryLocator()
GemfireBeanFactoryLocator
.
The afterPropertiesSet()
will be called after construction to initialize this locator.GemfireBeanFactoryLocator
.GemfireBeanFactoryLocator
,
GemfireBeanFactoryLocator()
,
afterPropertiesSet()
@NonNull public static GemfireBeanFactoryLocator newBeanFactoryLocator(BeanFactory beanFactory, String associatedBeanName)
GemfireBeanFactoryLocator
initialized with
the given, default Spring BeanFactory
and associated Spring bean name
.
The afterPropertiesSet()
will be called after construction to initialize this locator.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
.GemfireBeanFactoryLocator
initialized with the given, default Spring BeanFactory
and associated Spring bean name
.GemfireBeanFactoryLocator
,
BeanFactory
,
GemfireBeanFactoryLocator()
,
setBeanFactory(BeanFactory)
,
setBeanName(String)
,
afterPropertiesSet()
@Nullable protected static BeanFactory resolveBeanFactory(@NonNull String beanFactoryKey)
BeanFactory
mapped to the given beanFactoryKey
.beanFactoryKey
- String
containing a 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
.BeanFactory
@Nullable protected static BeanFactory resolveSingleBeanFactory()
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.BeanFactory
from the registry.IllegalStateException
- if the registry contains more than 1 registered Spring BeanFactory
,
or no Spring BeanFactories
.BeanFactory
protected 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
,
BeanFactory
protected 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 InitializingBean
public void destroy()
destroy
in interface DisposableBean
public 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 BeanFactoryAware
protected 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.BeanFactory
public void setBeanName(String name)
setBeanName
in interface BeanNameAware
protected 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–2023 Pivotal Software, Inc.. All rights reserved.