33
33
import org .springframework .data .gemfire .util .ArrayUtils ;
34
34
import org .springframework .data .gemfire .util .CollectionUtils ;
35
35
import org .springframework .lang .NonNull ;
36
+ import org .springframework .lang .Nullable ;
36
37
import org .springframework .util .Assert ;
37
38
import org .springframework .util .StringUtils ;
38
39
39
40
/**
40
- * Spring {@link FactoryBean} used to configure and initialize (bootstrap) an Apache Geode or Pivotal GemFire
41
- * {@link Locator} using the {@link LocatorLauncher} class.
41
+ * Spring {@link FactoryBean} used to configure, bootstrap and initialize an Apache Geode {@link Locator}
42
+ * using the {@link LocatorLauncher} class.
42
43
*
43
44
* @author John Blum
44
45
* @see java.util.Properties
48
49
* @see org.springframework.beans.factory.InitializingBean
49
50
* @see org.springframework.data.gemfire.config.annotation.LocatorConfigurer
50
51
* @see org.springframework.data.gemfire.support.AbstractFactoryBeanSupport
52
+ * @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator
51
53
* @since 2.2.0
52
54
*/
53
55
@ SuppressWarnings ("unused" )
@@ -156,7 +158,7 @@ protected void initializeBeanFactoryLocator() {
156
158
}
157
159
}
158
160
159
- protected LocatorLauncher .Builder newLocatorLauncherBuilder () {
161
+ protected @ NonNull LocatorLauncher .Builder newLocatorLauncherBuilder () {
160
162
return new LocatorLauncher .Builder ();
161
163
}
162
164
@@ -168,11 +170,11 @@ protected LocatorLauncher postProcess(LocatorLauncher locatorLauncher) {
168
170
return locatorLauncher ;
169
171
}
170
172
171
- public Locator getLocator () {
173
+ public @ Nullable Locator getLocator () {
172
174
return this .locator ;
173
175
}
174
176
175
- public LocatorLauncher getLocatorLauncher () {
177
+ public @ Nullable LocatorLauncher getLocatorLauncher () {
176
178
return this .locatorLauncher ;
177
179
}
178
180
@@ -194,7 +196,7 @@ public LocatorLauncher getLocatorLauncher() {
194
196
return locator != null ? locator .getClass () : Locator .class ;
195
197
}
196
198
197
- public void setBindAddress (String bindAddress ) {
199
+ public void setBindAddress (@ Nullable String bindAddress ) {
198
200
this .bindAddress = bindAddress ;
199
201
}
200
202
@@ -208,7 +210,7 @@ public Optional<String> getBindAddress() {
208
210
return this .compositeLocatorConfigurer ;
209
211
}
210
212
211
- public void setGemFireProperties (Properties gemfireProperties ) {
213
+ public void setGemFireProperties (@ Nullable Properties gemfireProperties ) {
212
214
this .gemfireProperties = gemfireProperties ;
213
215
}
214
216
@@ -221,7 +223,7 @@ public void setGemFireProperties(Properties gemfireProperties) {
221
223
return this .gemfireProperties ;
222
224
}
223
225
224
- public void setHostnameForClients (String hostnameForClients ) {
226
+ public void setHostnameForClients (@ Nullable String hostnameForClients ) {
225
227
this .hostnameForClients = hostnameForClients ;
226
228
}
227
229
@@ -239,7 +241,7 @@ public void setLocatorConfigurers(List<LocatorConfigurer> locatorConfigurers) {
239
241
Optional .ofNullable (locatorConfigurers ).ifPresent (this .locatorConfigurers ::addAll );
240
242
}
241
243
242
- public void setLocators (String locators ) {
244
+ public void setLocators (@ Nullable String locators ) {
243
245
this .locators = locators ;
244
246
}
245
247
@@ -249,15 +251,15 @@ public Optional<String> getLocators() {
249
251
.filter (StringUtils ::hasText );
250
252
}
251
253
252
- public void setLogLevel (String logLevel ) {
254
+ public void setLogLevel (@ Nullable String logLevel ) {
253
255
this .logLevel = logLevel ;
254
256
}
255
257
256
- public String getLogLevel () {
258
+ public @ NonNull String getLogLevel () {
257
259
return StringUtils .hasText (this .logLevel ) ? this .logLevel : DEFAULT_LOG_LEVEL ;
258
260
}
259
261
260
- public void setName (String name ) {
262
+ public void setName (@ Nullable String name ) {
261
263
this .name = name ;
262
264
}
263
265
@@ -267,14 +269,20 @@ public Optional<String> getName() {
267
269
.filter (StringUtils ::hasText );
268
270
}
269
271
270
- public void setPort (Integer port ) {
272
+ public void setPort (@ NonNull Integer port ) {
273
+ this .port = assertPort (nullSafePort (port ));
274
+ }
271
275
276
+ private int assertPort (@ NonNull int port ) {
272
277
Assert .isTrue (port >= 0 && port < 65536 , String .format ("Network port [%d] is not valid" , port ));
278
+ return port ;
279
+ }
273
280
274
- this .port = port ;
281
+ private int nullSafePort (@ Nullable Integer port ) {
282
+ return port != null ? port : DEFAULT_PORT ;
275
283
}
276
284
277
- public Integer getPort () {
285
+ public @ NonNull Integer getPort () {
278
286
return this .port ;
279
287
}
280
288
0 commit comments