15
15
*/
16
16
package org .springframework .data .gemfire ;
17
17
18
- import static org .springframework .data .gemfire .util .ArrayUtils .nullSafeArray ;
19
- import static org .springframework .data .gemfire .util .CollectionUtils .nullSafeIterable ;
20
-
21
18
import java .util .ArrayList ;
22
19
import java .util .Arrays ;
23
20
import java .util .List ;
32
29
import org .springframework .beans .factory .InitializingBean ;
33
30
import org .springframework .data .gemfire .config .annotation .LocatorConfigurer ;
34
31
import org .springframework .data .gemfire .support .AbstractFactoryBeanSupport ;
32
+ import org .springframework .data .gemfire .support .GemfireBeanFactoryLocator ;
33
+ import org .springframework .data .gemfire .util .ArrayUtils ;
35
34
import org .springframework .data .gemfire .util .CollectionUtils ;
36
- import org .springframework .lang .Nullable ;
35
+ import org .springframework .lang .NonNull ;
37
36
import org .springframework .util .Assert ;
38
37
import org .springframework .util .StringUtils ;
39
38
@@ -57,8 +56,10 @@ public class LocatorFactoryBean extends AbstractFactoryBeanSupport<Locator> impl
57
56
public static final int DEFAULT_PORT = 10334 ;
58
57
59
58
public static final String DEFAULT_LOG_LEVEL = GemFireProperties .LOG_LEVEL .getDefaultValueAsString ();
60
- private static final String LOCATORS_PROPERTY = GemFireProperties .LOCATORS .toString ();
61
- public static final String LOG_LEVEL_PROPERTY = GemFireProperties .LOG_LEVEL .toString ();
59
+ private static final String LOCATORS_PROPERTY = GemFireProperties .LOCATORS .getName ();
60
+ public static final String LOG_LEVEL_PROPERTY = GemFireProperties .LOG_LEVEL .getName ();
61
+
62
+ private boolean useBeanFactoryLocator = false ;
62
63
63
64
private Integer port = DEFAULT_PORT ;
64
65
@@ -82,16 +83,22 @@ public class LocatorFactoryBean extends AbstractFactoryBeanSupport<Locator> impl
82
83
83
84
@ Override
84
85
public void afterPropertiesSet () throws Exception {
85
- applyLocatorConfigurers (getCompositeLocatorConfigurer ());
86
+
87
+ applyLocatorConfigurers ();
88
+ initializeBeanFactoryLocator ();
86
89
init ();
87
90
}
88
91
92
+ protected void applyLocatorConfigurers () {
93
+ applyLocatorConfigurers (getCompositeLocatorConfigurer ());
94
+ }
95
+
89
96
protected void applyLocatorConfigurers (LocatorConfigurer ... locatorConfigurers ) {
90
- applyLocatorConfigurers (Arrays .asList (nullSafeArray (locatorConfigurers , LocatorConfigurer .class )));
97
+ applyLocatorConfigurers (Arrays .asList (ArrayUtils . nullSafeArray (locatorConfigurers , LocatorConfigurer .class )));
91
98
}
92
99
93
100
protected void applyLocatorConfigurers (Iterable <LocatorConfigurer > locatorConfigurers ) {
94
- StreamSupport .stream (nullSafeIterable (locatorConfigurers ).spliterator (), false )
101
+ StreamSupport .stream (CollectionUtils . nullSafeIterable (locatorConfigurers ).spliterator (), false )
95
102
.forEach (locatorConfigurer -> locatorConfigurer .configure (getBeanName (), this ));
96
103
}
97
104
@@ -142,6 +149,13 @@ protected LocatorLauncher.Builder configureGemfireProperties(LocatorLauncher.Bui
142
149
return locatorBuilder ;
143
150
}
144
151
152
+ protected void initializeBeanFactoryLocator () {
153
+
154
+ if (isUseBeanFactoryLocator ()) {
155
+ GemfireBeanFactoryLocator .newBeanFactoryLocator (getBeanFactory (), getBeanName ());
156
+ }
157
+ }
158
+
145
159
protected LocatorLauncher .Builder newLocatorLauncherBuilder () {
146
160
return new LocatorLauncher .Builder ();
147
161
}
@@ -162,8 +176,8 @@ public LocatorLauncher getLocatorLauncher() {
162
176
return this .locatorLauncher ;
163
177
}
164
178
165
- @ Nullable @ Override
166
- public Locator getObject () throws Exception {
179
+ @ Override
180
+ public @ NonNull Locator getObject () throws Exception {
167
181
168
182
Locator locator = getLocator ();
169
183
@@ -172,8 +186,8 @@ public Locator getObject() throws Exception {
172
186
return locator ;
173
187
}
174
188
175
- @ Nullable @ Override
176
- public Class <?> getObjectType () {
189
+ @ Override
190
+ public @ NonNull Class <?> getObjectType () {
177
191
178
192
Locator locator = getLocator ();
179
193
@@ -190,15 +204,15 @@ public Optional<String> getBindAddress() {
190
204
.filter (StringUtils ::hasText );
191
205
}
192
206
193
- public LocatorConfigurer getCompositeLocatorConfigurer () {
207
+ public @ NonNull LocatorConfigurer getCompositeLocatorConfigurer () {
194
208
return this .compositeLocatorConfigurer ;
195
209
}
196
210
197
211
public void setGemFireProperties (Properties gemfireProperties ) {
198
212
this .gemfireProperties = gemfireProperties ;
199
213
}
200
214
201
- public Properties getGemFireProperties () {
215
+ public @ NonNull Properties getGemFireProperties () {
202
216
203
217
if (this .gemfireProperties == null ) {
204
218
this .gemfireProperties = new Properties ();
@@ -218,7 +232,7 @@ public Optional<String> getHostnameForClients() {
218
232
}
219
233
220
234
public void setLocatorConfigurers (LocatorConfigurer ... locatorConfigurers ) {
221
- setLocatorConfigurers (Arrays .asList (nullSafeArray (locatorConfigurers , LocatorConfigurer .class )));
235
+ setLocatorConfigurers (Arrays .asList (ArrayUtils . nullSafeArray (locatorConfigurers , LocatorConfigurer .class )));
222
236
}
223
237
224
238
public void setLocatorConfigurers (List <LocatorConfigurer > locatorConfigurers ) {
@@ -263,4 +277,12 @@ public void setPort(Integer port) {
263
277
public Integer getPort () {
264
278
return this .port ;
265
279
}
280
+
281
+ public void setUseBeanFactoryLocator (boolean useBeanFactoryLocator ) {
282
+ this .useBeanFactoryLocator = useBeanFactoryLocator ;
283
+ }
284
+
285
+ public boolean isUseBeanFactoryLocator () {
286
+ return this .useBeanFactoryLocator ;
287
+ }
266
288
}
0 commit comments