Skip to content

Commit 60fcb0a

Browse files
committed
Refactor GemfireBeanFactoryLocator.
* Edit Javadoc. * Annotate API with Spring @nonnull and @nullable annotations. * Cleanup deprecations.
1 parent 308daee commit 60fcb0a

File tree

1 file changed

+44
-39
lines changed

1 file changed

+44
-39
lines changed

Diff for: spring-data-geode/src/main/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocator.java

+44-39
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.springframework.beans.factory.BeanNameAware;
3333
import org.springframework.beans.factory.DisposableBean;
3434
import org.springframework.beans.factory.InitializingBean;
35+
import org.springframework.lang.NonNull;
36+
import org.springframework.lang.Nullable;
3537
import org.springframework.util.Assert;
3638
import org.springframework.util.StringUtils;
3739

@@ -41,20 +43,24 @@
4143
/**
4244
* The {@link GemfireBeanFactoryLocator} class stores a reference to the Spring
4345
* {@link org.springframework.context.ApplicationContext} / {@link BeanFactory} needed to auto-wire
44-
* user application GemFire objects implementing the {@link org.apache.geode.cache.Declarable} interface
45-
* and defined in GemFire's native configuration format (e.g. {@literal cache.xml}.
46+
* user application Apache Geode objects implementing the {@link org.apache.geode.cache.Declarable} interface
47+
* and defined in Apache Geode's native configuration format (e.g. {@literal cache.xml}.
4648
*
47-
* In most cases, a developer does not need to use this class directly as it is registered by the
48-
* {@link org.springframework.data.gemfire.CacheFactoryBean} when the {@literal useBeanFactoryLocator} property
49-
* is set, and used internally by bothe the {@link WiringDeclarableSupport} and {@link LazyWiringDeclarableSupport}
50-
* SDG classes.
49+
* In most cases, a developer does not need to use this class directly as it is registered by
50+
* the {@link org.springframework.data.gemfire.CacheFactoryBean} or {@link org.springframework.data.gemfire.LocatorFactoryBean}
51+
* when the {@literal useBeanFactoryLocator} property is set, and used internally by both
52+
* the {@link WiringDeclarableSupport} and {@link LazyWiringDeclarableSupport} SDG classes.
5153
*
5254
* @author Costin Leau
5355
* @author John Blum
54-
* @see LazyWiringDeclarableSupport
55-
* @see WiringDeclarableSupport
56+
* @see org.springframework.beans.factory.BeanFactory
57+
* @see org.springframework.beans.factory.BeanFactoryAware
58+
* @see org.springframework.beans.factory.BeanNameAware
59+
* @see org.springframework.beans.factory.DisposableBean
60+
* @see org.springframework.beans.factory.InitializingBean
61+
* @see org.springframework.data.gemfire.support.LazyWiringDeclarableSupport
62+
* @see org.springframework.data.gemfire.support.WiringDeclarableSupport
5663
*/
57-
@SuppressWarnings("all")
5864
public class GemfireBeanFactoryLocator implements BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean {
5965

6066
// Bean alias/name <-> BeanFactory mapping
@@ -69,21 +75,23 @@ public class GemfireBeanFactoryLocator implements BeanFactoryAware, BeanNameAwar
6975
private String associatedBeanName;
7076

7177
/**
72-
* Cleans up all {@link BeanFactory} references tracked by this locator.
78+
* Cleans up all {@link BeanFactory} references tracked by this {@literal locator}.
7379
*/
7480
public static void clear() {
7581
BEAN_FACTORIES.clear();
7682
}
7783

7884
/**
79-
* Factory method to construct a new, initialized instance of {@link GemfireBeanFactoryLocator}.
85+
* Factory method used to construct a new instance of {@link GemfireBeanFactoryLocator}.
86+
*
87+
* The {@link #afterPropertiesSet()} will be called after construction to initialize this {@literal locator}.
8088
*
8189
* @return a new, initialized instance of the {@link GemfireBeanFactoryLocator}.
82-
* @see GemfireBeanFactoryLocator
83-
* @see #GemfireBeanFactoryLocator()
90+
* @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator
91+
* @see GemfireBeanFactoryLocator()
8492
* @see #afterPropertiesSet()
8593
*/
86-
public static GemfireBeanFactoryLocator newBeanFactoryLocator() {
94+
public static @NonNull GemfireBeanFactoryLocator newBeanFactoryLocator() {
8795

8896
GemfireBeanFactoryLocator beanFactoryLocator = new GemfireBeanFactoryLocator();
8997

@@ -93,22 +101,25 @@ public static GemfireBeanFactoryLocator newBeanFactoryLocator() {
93101
}
94102

95103
/**
96-
* Factory method to construct a new, initialized instance of {@link GemfireBeanFactoryLocator} with the given
97-
* default Spring {@link BeanFactory} and associated Spring bean name.
104+
* Factory method used to construct a new instance of {@link GemfireBeanFactoryLocator} initialized with
105+
* the given, default Spring {@link BeanFactory} and associated Spring {@link String bean name}.
106+
*
107+
* The {@link #afterPropertiesSet()} will be called after construction to initialize this {@literal locator}.
98108
*
99-
* @param beanFactory reference to the {@link BeanFactory} used to resolve Spring bean references.
100-
* @param associatedBeanName {@link String} contain the name of the Spring bean associated with
109+
* @param beanFactory reference to the Spring {@link BeanFactory} used to resolve Spring bean references.
110+
* @param associatedBeanName {@link String} containing the {@literal name} of the Spring bean associated with
101111
* the Spring {@link BeanFactory}.
102-
* @return a new, initialized instance of {@link GemfireBeanFactoryLocator} with the given default
103-
* Spring {@link BeanFactory} and associated Spring bean name.
112+
* @return a new {@link GemfireBeanFactoryLocator} initialized with the given, default Spring {@link BeanFactory}
113+
* and associated Spring {@link String bean name}.
114+
* @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator
104115
* @see org.springframework.beans.factory.BeanFactory
105-
* @see GemfireBeanFactoryLocator
106-
* @see #GemfireBeanFactoryLocator()
116+
* @see GemfireBeanFactoryLocator()
107117
* @see #setBeanFactory(BeanFactory)
108118
* @see #setBeanName(String)
109119
* @see #afterPropertiesSet()
110120
*/
111-
public static GemfireBeanFactoryLocator newBeanFactoryLocator(BeanFactory beanFactory, String associatedBeanName) {
121+
public static @NonNull GemfireBeanFactoryLocator newBeanFactoryLocator(BeanFactory beanFactory,
122+
String associatedBeanName) {
112123

113124
Assert.isTrue(beanFactory == null || StringUtils.hasText(associatedBeanName),
114125
"associatedBeanName must be specified when BeanFactory is not null");
@@ -123,15 +134,15 @@ public static GemfireBeanFactoryLocator newBeanFactoryLocator(BeanFactory beanFa
123134
}
124135

125136
/**
126-
* Resolves the {@link BeanFactory} mapped to the given {@code beanFactoryKey}.
137+
* Resolves the {@link BeanFactory} mapped to the given {@link String beanFactoryKey}.
127138
*
128-
* @param beanFactoryKey {@link String} value containing the key used to lookup the {@link BeanFactory}.
139+
* @param beanFactoryKey {@link String} containing a key used to lookup the {@link BeanFactory}.
129140
* @return the {@link BeanFactory} mapped to the given key.
130141
* @throws IllegalArgumentException if a Spring {@link BeanFactory} could not be found
131-
* for the given {@code beanFactoryKey}.
142+
* for the given {@link String beanFactoryKey}.
132143
* @see org.springframework.beans.factory.BeanFactory
133144
*/
134-
protected static BeanFactory resolveBeanFactory(String beanFactoryKey) {
145+
protected static @Nullable BeanFactory resolveBeanFactory(@NonNull String beanFactoryKey) {
135146

136147
BeanFactory beanFactory = BEAN_FACTORIES.get(beanFactoryKey);
137148

@@ -142,18 +153,18 @@ protected static BeanFactory resolveBeanFactory(String beanFactoryKey) {
142153
}
143154

144155
/**
145-
* Resolves a single Spring {@link BeanFactory} from the mapping of registered bean factories.
156+
* Resolves a single Spring {@link BeanFactory} from the mapping of registered {@link BeanFactory BeanFactories}.
146157
*
147158
* This class method is synchronized because it contains a "compound action", even though separate actions
148159
* are performed on a {@link ConcurrentMap}, the actions are not independent and therefore must operate
149160
* atomically.
150161
*
151162
* @return a single Spring {@link BeanFactory} from the registry.
152-
* @throws IllegalStateException if the registry contains more than 1, or no
153-
* Spring {@link BeanFactory bean factories}.
163+
* @throws IllegalStateException if the registry contains more than 1 registered Spring {@link BeanFactory},
164+
* or no Spring {@link BeanFactory BeanFactories}.
154165
* @see org.springframework.beans.factory.BeanFactory
155166
*/
156-
protected static synchronized BeanFactory resolveSingleBeanFactory() {
167+
protected static synchronized @Nullable BeanFactory resolveSingleBeanFactory() {
157168

158169
if (!BEAN_FACTORIES.isEmpty()) {
159170

@@ -173,7 +184,7 @@ protected static synchronized BeanFactory resolveSingleBeanFactory() {
173184

174185
Assert.state(allTheSameBeanFactory,
175186
String.format("BeanFactory key must be specified when more than one BeanFactory %s is registered",
176-
new TreeSet(BEAN_FACTORIES.keySet()).toString()));
187+
new TreeSet<>(BEAN_FACTORIES.keySet())));
177188

178189
return BEAN_FACTORIES.values().iterator().next();
179190
}
@@ -218,9 +229,6 @@ protected static synchronized boolean unregisterAliases(Set<String> names) {
218229
return BEAN_FACTORIES.keySet().removeAll(names);
219230
}
220231

221-
/**
222-
* @inheritDoc
223-
*/
224232
@Override
225233
public void afterPropertiesSet() {
226234

@@ -257,9 +265,6 @@ Set<String> resolveAndInitializeBeanNamesWithAliases(BeanFactory beanFactory) {
257265
return this.associatedBeanNameWithAliases;
258266
}
259267

260-
/**
261-
* @inheritDoc
262-
*/
263268
@Override
264269
public void destroy() {
265270
unregisterAliases(getAssociatedBeanNameWithAliases());
@@ -379,7 +384,7 @@ protected static class BeanFactoryReference {
379384
* @param beanFactory {@link BeanFactory} reference to store.
380385
* @return a new instance of {@link BeanFactoryReference} initialized with the given {@link BeanFactory}.
381386
* @see org.springframework.beans.factory.BeanFactory
382-
* @see #GemfireBeanFactoryLocator.BeanFactoryReference(BeanFactory)
387+
* @see GemfireBeanFactoryLocator.BeanFactoryReference(BeanFactory)
383388
*/
384389
protected static BeanFactoryReference newBeanFactoryReference(BeanFactory beanFactory) {
385390
return new BeanFactoryReference(beanFactory);

0 commit comments

Comments
 (0)