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:
-
BeanFactory
BeanFactoryAware
BeanNameAware
DisposableBean
InitializingBean
LazyWiringDeclarableSupport
WiringDeclarableSupport
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Reference holder storing a reference to a SpringBeanFactory
. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final ConcurrentMap<String,
org.springframework.beans.factory.BeanFactory> protected final org.slf4j.Logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
static void
clear()
Cleans up allBeanFactory
references tracked by this locator.void
destroy()
protected String
Gets the name of the Spring bean associated with the SpringBeanFactory
that possibly created the bean.Returns aSet
of all names and aliases assigned to the Spring bean that is associated with the SpringBeanFactory
.protected org.springframework.beans.factory.BeanFactory
Returns a reference to theBeanFactory
managed by thisGemfireBeanFactoryLocator
instance; Might be null if thisGemfireBeanFactoryLocator
is just used to lookup an existingBeanFactory
reference.static GemfireBeanFactoryLocator
Factory method used to construct a new instance ofGemfireBeanFactoryLocator
.static GemfireBeanFactoryLocator
newBeanFactoryLocator
(org.springframework.beans.factory.BeanFactory beanFactory, String associatedBeanName) Factory method used to construct a new instance ofGemfireBeanFactoryLocator
initialized with the given, default SpringBeanFactory
and associated Springbean name
.protected static void
registerAliases
(Set<String> names, org.springframework.beans.factory.BeanFactory beanFactory) Registers all the provided names for given SpringBeanFactory
.protected static org.springframework.beans.factory.BeanFactory
resolveBeanFactory
(String beanFactoryKey) Resolves theBeanFactory
mapped to the givenbeanFactoryKey
.protected static org.springframework.beans.factory.BeanFactory
Resolves a single SpringBeanFactory
from the mapping of registeredBeanFactories
.void
setBeanFactory
(org.springframework.beans.factory.BeanFactory beanFactory) void
setBeanName
(String name) protected static boolean
unregisterAliases
(Set<String> names) Removes all SpringBeanFactory
associations/mappings for the givenSet
of names.org.springframework.beans.factory.BeanFactory
Attempts to use a single, existing SpringBeanFactory
from the registry based on thesetBeanName(String)
beanName} property.org.springframework.beans.factory.BeanFactory
useBeanFactory
(String beanFactoryKey) Attempts to use the SpringBeanFactory
idenified by the givenbeanFactoryKey
.withBeanName
(String beanName) Builder method to set the bean name used by this locator to lookup a SpringBeanFactory
.
-
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 allBeanFactory
references tracked by this locator. -
newBeanFactoryLocator
Factory method used to construct a new instance ofGemfireBeanFactoryLocator
. TheafterPropertiesSet()
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 ofGemfireBeanFactoryLocator
initialized with the given, default SpringBeanFactory
and associated Springbean name
. TheafterPropertiesSet()
will be called after construction to initialize this locator.- Parameters:
beanFactory
- reference to the SpringBeanFactory
used to resolve Spring bean references.associatedBeanName
-String
containing the name of the Spring bean associated with the SpringBeanFactory
.- Returns:
- a new
GemfireBeanFactoryLocator
initialized with the given, default SpringBeanFactory
and associated Springbean name
. - See Also:
-
resolveBeanFactory
@Nullable protected static org.springframework.beans.factory.BeanFactory resolveBeanFactory(@NonNull String beanFactoryKey) Resolves theBeanFactory
mapped to the givenbeanFactoryKey
.- Parameters:
beanFactoryKey
-String
containing a key used to lookup theBeanFactory
.- Returns:
- the
BeanFactory
mapped to the given key. - Throws:
IllegalArgumentException
- if a SpringBeanFactory
could not be found for the givenbeanFactoryKey
.- See Also:
-
BeanFactory
-
resolveSingleBeanFactory
@Nullable protected static org.springframework.beans.factory.BeanFactory resolveSingleBeanFactory()Resolves a single SpringBeanFactory
from the mapping of registeredBeanFactories
. This class method is synchronized because it contains a "compound action", even though separate actions are performed on aConcurrentMap
, 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 SpringBeanFactory
, or no SpringBeanFactories
.- See Also:
-
BeanFactory
-
registerAliases
protected static void registerAliases(Set<String> names, org.springframework.beans.factory.BeanFactory beanFactory) Registers all the provided names for given SpringBeanFactory
.- Parameters:
names
-Set
of names and aliases to associate with the SpringBeanFactory
.beanFactory
- reference to the SpringBeanFactory
.- Throws:
IllegalArgumentException
- ifBeanFactory
is null.IllegalStateException
- if one of the provided names is already associated with an existing, other than given, SpringBeanFactory
.- See Also:
-
BeanFactory
BeanFactory
-
unregisterAliases
Removes all SpringBeanFactory
associations/mappings for the givenSet
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 interfaceorg.springframework.beans.factory.InitializingBean
-
destroy
public void destroy()- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
-
useBeanFactory
public org.springframework.beans.factory.BeanFactory useBeanFactory()Attempts to use a single, existing SpringBeanFactory
from the registry based on thesetBeanName(String)
beanName} property.- Returns:
- the single Spring
BeanFactory
from the registry. - Throws:
IllegalArgumentException
- if more than SpringBeanFactory
is registered.IllegalStateException
- if theBeanFactory
with the associatedbeanName
is not found.- See Also:
-
BeanFactory
getAssociatedBeanName()
useBeanFactory(String)
-
useBeanFactory
Attempts to use the SpringBeanFactory
idenified by the givenbeanFactoryKey
.- Parameters:
beanFactoryKey
-String
containing the key used to lookup the SpringBeanFactory
.- Returns:
- the Spring
BeanFactory
for the givenbeanFactoryKey
. - Throws:
IllegalArgumentException
- if a SpringBeanFactory
could not be found forbeanFactoryKey
.IllegalStateException
- if useBeanFactoryLocator was not configured.- See Also:
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) - Specified by:
setBeanFactory
in interfaceorg.springframework.beans.factory.BeanFactoryAware
-
getBeanFactory
protected org.springframework.beans.factory.BeanFactory getBeanFactory()Returns a reference to theBeanFactory
managed by thisGemfireBeanFactoryLocator
instance; Might be null if thisGemfireBeanFactoryLocator
is just used to lookup an existingBeanFactory
reference.- Returns:
- the managed
BeanFactory
reference. - See Also:
-
BeanFactory
-
setBeanName
- Specified by:
setBeanName
in interfaceorg.springframework.beans.factory.BeanNameAware
-
getAssociatedBeanName
Gets the name of the Spring bean associated with the SpringBeanFactory
that possibly created the bean.- Returns:
- a
String
containing the name of the Spring bean associated with the SpringBeanFactory
. - See Also:
-
getAssociatedBeanNameWithAliases
Returns aSet
of all names and aliases assigned to the Spring bean that is associated with the SpringBeanFactory
.- Returns:
- a
Set
containing all the names and aliases assigned to the Spring bean associated with the SpringBeanFactory
. - See Also:
-
withBeanName
Builder method to set the bean name used by this locator to lookup a SpringBeanFactory
.- Parameters:
beanName
-String
containing the bean name to set on this locator.- Returns:
- this
GemfireBeanFactoryLocator
. - See Also:
-