Class GemfireBeanFactoryLocator
java.lang.Object
org.springframework.data.gemfire.support.GemfireBeanFactoryLocator
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
public class GemfireBeanFactoryLocator
extends Object
implements BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean
The
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.- Author:
- Costin Leau, John Blum
- See Also:
-
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,
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 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 to construct a new, initialized instance ofGemfireBeanFactoryLocator
.static GemfireBeanFactoryLocator
newBeanFactoryLocator
(BeanFactory beanFactory, String associatedBeanName) Factory method to construct a new, initialized instance ofGemfireBeanFactoryLocator
with the given default SpringBeanFactory
and associated Spring bean name.protected static void
registerAliases
(Set<String> names, BeanFactory beanFactory) Registers all the provided names for given SpringBeanFactory
.protected static BeanFactory
resolveBeanFactory
(String beanFactoryKey) Resolves theBeanFactory
mapped to the givenbeanFactoryKey
.protected static BeanFactory
Resolves a single SpringBeanFactory
from the mapping of registered bean factories.void
setBeanFactory
(BeanFactory beanFactory) void
setBeanName
(String name) protected static boolean
unregisterAliases
(Set<String> names) Removes all SpringBeanFactory
associations/mappings for the givenSet
of names.Attempts to use a single, existing SpringBeanFactory
from the registry based on thesetBeanName(String)
beanName} property.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
-
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 to construct a new, initialized instance ofGemfireBeanFactoryLocator
.- Returns:
- a new, initialized instance of the
GemfireBeanFactoryLocator
. - See Also:
-
newBeanFactoryLocator
public static GemfireBeanFactoryLocator newBeanFactoryLocator(BeanFactory beanFactory, String associatedBeanName) Factory method to construct a new, initialized instance ofGemfireBeanFactoryLocator
with the given default SpringBeanFactory
and associated Spring bean name.- Parameters:
beanFactory
- reference to theBeanFactory
used to resolve Spring bean references.associatedBeanName
-String
contain the name of the Spring bean associated with the SpringBeanFactory
.- Returns:
- a new, initialized instance of
GemfireBeanFactoryLocator
with the given default SpringBeanFactory
and associated Spring bean name. - See Also:
-
resolveBeanFactory
Resolves theBeanFactory
mapped to the givenbeanFactoryKey
.- Parameters:
beanFactoryKey
-String
value containing the 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:
-
resolveSingleBeanFactory
Resolves a single SpringBeanFactory
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 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, or no Springbean factories
.- See Also:
-
registerAliases
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:
-
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 interfaceInitializingBean
-
destroy
public void destroy()- Specified by:
destroy
in interfaceDisposableBean
-
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:
-
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
- Specified by:
setBeanFactory
in interfaceBeanFactoryAware
-
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:
-
setBeanName
- Specified by:
setBeanName
in interfaceBeanNameAware
-
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:
-