Skip to content

Commit cfc8802

Browse files
AMashenkovdevozerov
authored andcommitted
IGNITE-4564: All setters on public configuration now return "this" instance to allow convenient chaining. This closes apache#1449.
1 parent 44cf1d2 commit cfc8802

File tree

79 files changed

+3935
-710
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+3935
-710
lines changed

modules/aws/src/main/java/org/apache/ignite/spi/checkpoint/s3/S3CheckpointSpi.java

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.apache.ignite.spi.IgniteSpiAdapter;
5252
import org.apache.ignite.spi.IgniteSpiConfiguration;
5353
import org.apache.ignite.spi.IgniteSpiException;
54+
import org.apache.ignite.spi.IgniteSpiMBeanAdapter;
5455
import org.apache.ignite.spi.IgniteSpiMultipleInstancesSupport;
5556
import org.apache.ignite.spi.IgniteSpiThread;
5657
import org.apache.ignite.spi.checkpoint.CheckpointListener;
@@ -122,7 +123,7 @@
122123
* @see org.apache.ignite.spi.checkpoint.CheckpointSpi
123124
*/
124125
@IgniteSpiMultipleInstancesSupport(true)
125-
public class S3CheckpointSpi extends IgniteSpiAdapter implements CheckpointSpi, S3CheckpointSpiMBean {
126+
public class S3CheckpointSpi extends IgniteSpiAdapter implements CheckpointSpi {
126127
/** Logger. */
127128
@SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"})
128129
@LoggerResource
@@ -169,7 +170,7 @@ public class S3CheckpointSpi extends IgniteSpiAdapter implements CheckpointSpi,
169170
*
170171
* @return S3 bucket name to use.
171172
*/
172-
@Override public String getBucketName() {
173+
public String getBucketName() {
173174
return bucketName;
174175
}
175176

@@ -178,7 +179,7 @@ public class S3CheckpointSpi extends IgniteSpiAdapter implements CheckpointSpi,
178179
*
179180
* @return S3 access key.
180181
*/
181-
@Override public String getAccessKey() {
182+
public String getAccessKey() {
182183
return cred.getAWSAccessKeyId();
183184
}
184185

@@ -196,7 +197,7 @@ public String getSecretAccessKey() {
196197
*
197198
* @return HTTP proxy host.
198199
*/
199-
@Override public String getProxyHost() {
200+
public String getProxyHost() {
200201
return cfg.getProxyHost();
201202
}
202203

@@ -205,7 +206,7 @@ public String getSecretAccessKey() {
205206
*
206207
* @return HTTP proxy port.
207208
*/
208-
@Override public int getProxyPort() {
209+
public int getProxyPort() {
209210
return cfg.getProxyPort();
210211
}
211212

@@ -214,7 +215,7 @@ public String getSecretAccessKey() {
214215
*
215216
* @return HTTP proxy user name.
216217
*/
217-
@Override public String getProxyUsername() {
218+
public String getProxyUsername() {
218219
return cfg.getProxyUsername();
219220
}
220221

@@ -231,10 +232,13 @@ public String getProxyPassword() {
231232
* Sets bucket name suffix.
232233
*
233234
* @param bucketNameSuffix Bucket name suffix.
235+
* @return {@code this} for chaining.
234236
*/
235237
@IgniteSpiConfiguration(optional = true)
236-
public void setBucketNameSuffix(String bucketNameSuffix) {
238+
public S3CheckpointSpi setBucketNameSuffix(String bucketNameSuffix) {
237239
this.bucketNameSuffix = bucketNameSuffix;
240+
241+
return this;
238242
}
239243

240244
/**
@@ -243,10 +247,13 @@ public void setBucketNameSuffix(String bucketNameSuffix) {
243247
* For details refer to Amazon S3 API reference.
244248
*
245249
* @param cfg Amazon client configuration.
250+
* @return {@code this} for chaining.
246251
*/
247252
@IgniteSpiConfiguration(optional = true)
248-
public void setClientConfiguration(ClientConfiguration cfg) {
253+
public S3CheckpointSpi setClientConfiguration(ClientConfiguration cfg) {
249254
this.cfg = cfg;
255+
256+
return this;
250257
}
251258

252259
/**
@@ -255,10 +262,13 @@ public void setClientConfiguration(ClientConfiguration cfg) {
255262
* For details refer to Amazon S3 API reference.
256263
*
257264
* @param cred AWS credentials.
265+
* @return {@code this} for chaining.
258266
*/
259267
@IgniteSpiConfiguration(optional = false)
260-
public void setAwsCredentials(AWSCredentials cred) {
268+
public S3CheckpointSpi setAwsCredentials(AWSCredentials cred) {
261269
this.cred = cred;
270+
271+
return this;
262272
}
263273

264274
/** {@inheritDoc} */
@@ -351,7 +361,7 @@ public void setAwsCredentials(AWSCredentials cred) {
351361

352362
timeoutWrk.start();
353363

354-
registerMBean(igniteInstanceName, this, S3CheckpointSpiMBean.class);
364+
registerMBean(igniteInstanceName, new S3CheckpointSpiMBeanImpl(this), S3CheckpointSpiMBean.class);
355365

356366
// Ack ok start.
357367
if (log.isDebugEnabled())
@@ -569,6 +579,13 @@ boolean hasKey(String key) throws AmazonClientException {
569579
this.lsnr = lsnr;
570580
}
571581

582+
/** {@inheritDoc} */
583+
@Override public S3CheckpointSpi setName(String name) {
584+
super.setName(name);
585+
586+
return this;
587+
}
588+
572589
/** {@inheritDoc} */
573590
@Override public String toString() {
574591
return S.toString(S3CheckpointSpi.class, this);
@@ -702,4 +719,39 @@ public void remove(String key) {
702719
return S.toString(S3TimeoutWorker.class, this);
703720
}
704721
}
722+
723+
/**
724+
* MBean implementation for S3CheckpointSpi.
725+
*/
726+
private class S3CheckpointSpiMBeanImpl extends IgniteSpiMBeanAdapter implements S3CheckpointSpiMBean {
727+
/** {@inheritDoc} */
728+
S3CheckpointSpiMBeanImpl(IgniteSpiAdapter spiAdapter) {
729+
super(spiAdapter);
730+
}
731+
732+
/** {@inheritDoc} */
733+
@Override public String getBucketName() {
734+
return S3CheckpointSpi.this.getBucketName();
735+
}
736+
737+
/** {@inheritDoc} */
738+
@Override public String getAccessKey() {
739+
return S3CheckpointSpi.this.getAccessKey();
740+
}
741+
742+
/** {@inheritDoc} */
743+
@Override public String getProxyHost() {
744+
return S3CheckpointSpi.this.getProxyHost();
745+
}
746+
747+
/** {@inheritDoc} */
748+
@Override public int getProxyPort() {
749+
return S3CheckpointSpi.this.getProxyPort();
750+
}
751+
752+
/** {@inheritDoc} */
753+
@Override public String getProxyUsername() {
754+
return S3CheckpointSpi.this.getProxyUsername();
755+
}
756+
}
705757
}

modules/aws/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/s3/TcpDiscoveryS3IpFinder.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,13 @@ private AmazonS3Client createAmazonS3Client() {
308308
* Sets bucket name for IP finder.
309309
*
310310
* @param bucketName Bucket name.
311+
* @return {@code this} for chaining.
311312
*/
312313
@IgniteSpiConfiguration(optional = false)
313-
public void setBucketName(String bucketName) {
314+
public TcpDiscoveryS3IpFinder setBucketName(String bucketName) {
314315
this.bucketName = bucketName;
316+
317+
return this;
315318
}
316319

317320
/**
@@ -320,10 +323,13 @@ public void setBucketName(String bucketName) {
320323
* For details refer to Amazon S3 API reference.
321324
*
322325
* @param cfg Amazon client configuration.
326+
* @return {@code this} for chaining.
323327
*/
324328
@IgniteSpiConfiguration(optional = true)
325-
public void setClientConfiguration(ClientConfiguration cfg) {
329+
public TcpDiscoveryS3IpFinder setClientConfiguration(ClientConfiguration cfg) {
326330
this.cfg = cfg;
331+
332+
return this;
327333
}
328334

329335
/**
@@ -332,10 +338,13 @@ public void setClientConfiguration(ClientConfiguration cfg) {
332338
* For details refer to Amazon S3 API reference.
333339
*
334340
* @param cred AWS credentials.
341+
* @return {@code this} for chaining.
335342
*/
336343
@IgniteSpiConfiguration(optional = false)
337-
public void setAwsCredentials(AWSCredentials cred) {
344+
public TcpDiscoveryS3IpFinder setAwsCredentials(AWSCredentials cred) {
338345
this.cred = cred;
346+
347+
return this;
339348
}
340349

341350
/**
@@ -344,10 +353,20 @@ public void setAwsCredentials(AWSCredentials cred) {
344353
* For details refer to Amazon S3 API reference.
345354
*
346355
* @param credProvider AWS credentials provider.
356+
* @return {@code this} for chaining.
347357
*/
348358
@IgniteSpiConfiguration(optional = false)
349-
public void setAwsCredentialsProvider(AWSCredentialsProvider credProvider) {
359+
public TcpDiscoveryS3IpFinder setAwsCredentialsProvider(AWSCredentialsProvider credProvider) {
350360
this.credProvider = credProvider;
361+
362+
return this;
363+
}
364+
365+
/** {@inheritDoc} */
366+
@Override public TcpDiscoveryS3IpFinder setShared(boolean shared) {
367+
super.setShared(shared);
368+
369+
return this;
351370
}
352371

353372
/** {@inheritDoc} */

modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
3737
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
3838
import org.apache.ignite.internal.util.typedef.F;
39+
import org.apache.ignite.internal.util.typedef.internal.S;
3940
import org.apache.ignite.internal.util.typedef.internal.U;
4041
import org.apache.ignite.spi.IgniteSpiConfiguration;
4142
import org.apache.ignite.spi.IgniteSpiException;
@@ -230,10 +231,13 @@ public TcpDiscoveryCloudIpFinder() {
230231
* ComputeService section contains names of all supported providers.
231232
*
232233
* @param provider Provider name.
234+
* @return {@code this} for chaining.
233235
*/
234236
@IgniteSpiConfiguration(optional = false)
235-
public void setProvider(String provider) {
237+
public TcpDiscoveryCloudIpFinder setProvider(String provider) {
236238
this.provider = provider;
239+
240+
return this;
237241
}
238242

239243
/**
@@ -244,10 +248,13 @@ public void setProvider(String provider) {
244248
* what is used as an identity for a particular cloud platform.
245249
*
246250
* @param identity Identity to use during authentication on the cloud.
251+
* @return {@code this} for chaining.
247252
*/
248253
@IgniteSpiConfiguration(optional = false)
249-
public void setIdentity(String identity) {
254+
public TcpDiscoveryCloudIpFinder setIdentity(String identity) {
250255
this.identity = identity;
256+
257+
return this;
251258
}
252259

253260
/**
@@ -258,10 +265,13 @@ public void setIdentity(String identity) {
258265
* what is used as an credential for a particular cloud platform.
259266
*
260267
* @param credential Credential to use during authentication on the cloud.
268+
* @return {@code this} for chaining.
261269
*/
262270
@IgniteSpiConfiguration(optional = true)
263-
public void setCredential(String credential) {
271+
public TcpDiscoveryCloudIpFinder setCredential(String credential) {
264272
this.credential = credential;
273+
274+
return this;
265275
}
266276

267277
/**
@@ -275,10 +285,13 @@ public void setCredential(String credential) {
275285
* what is used as an credential for a particular cloud platform.
276286
*
277287
* @param credentialPath Path to the credential to use during authentication on the cloud.
288+
* @return {@code this} for chaining.
278289
*/
279290
@IgniteSpiConfiguration(optional = true)
280-
public void setCredentialPath(String credentialPath) {
291+
public TcpDiscoveryCloudIpFinder setCredentialPath(String credentialPath) {
281292
this.credentialPath = credentialPath;
293+
294+
return this;
282295
}
283296

284297
/**
@@ -291,13 +304,14 @@ public void setCredentialPath(String credentialPath) {
291304
* providers a call to this method is redundant.
292305
*
293306
* @param zones Zones where VMs are located or null if to take every zone into account.
307+
* @return {@code this} for chaining.
294308
*/
295309
@IgniteSpiConfiguration(optional = true)
296-
public void setZones(Collection<String> zones) {
297-
if (F.isEmpty(zones))
298-
return;
310+
public TcpDiscoveryCloudIpFinder setZones(Collection<String> zones) {
311+
if (!F.isEmpty(zones))
312+
this.zones = new TreeSet<>(zones);
299313

300-
this.zones = new TreeSet<>(zones);
314+
return this;
301315
}
302316

303317
/**
@@ -310,13 +324,14 @@ public void setZones(Collection<String> zones) {
310324
* providers a call to this method is redundant.
311325
*
312326
* @param regions Regions where VMs are located or null if to check every region a provider has.
327+
* @return {@code this} for chaining.
313328
*/
314329
@IgniteSpiConfiguration(optional = true)
315-
public void setRegions(Collection<String> regions) {
316-
if (F.isEmpty(regions))
317-
return;
330+
public TcpDiscoveryCloudIpFinder setRegions(Collection<String> regions) {
331+
if (!F.isEmpty(regions))
332+
this.regions = new TreeSet<>(regions);
318333

319-
this.regions = new TreeSet<>(regions);
334+
return this;
320335
}
321336

322337
/**
@@ -452,4 +467,16 @@ private String keysSetToStr(Set<String> set) {
452467

453468
return builder.toString();
454469
}
470+
471+
/** {@inheritDoc} */
472+
@Override public TcpDiscoveryCloudIpFinder setShared(boolean shared) {
473+
super.setShared(shared);
474+
475+
return this;
476+
}
477+
478+
/** {@inheritDoc} */
479+
@Override public String toString() {
480+
return S.toString(TcpDiscoveryCloudIpFinder.class, this);
481+
}
455482
}

modules/core/src/main/java/org/apache/ignite/binary/BinaryBasicIdMapper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,12 @@ public boolean isLowerCase() {
114114
* Sets whether to use strings in lower case or not.
115115
*
116116
* @param isLowerCase Whether to use strings in lower case or not.
117+
* @return {@code this} for chaining.
117118
*/
118-
public void setLowerCase(boolean isLowerCase) {
119+
public BinaryBasicIdMapper setLowerCase(boolean isLowerCase) {
119120
this.isLowerCase = isLowerCase;
121+
122+
return this;
120123
}
121124

122125
/**

modules/core/src/main/java/org/apache/ignite/binary/BinaryBasicNameMapper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ public boolean isSimpleName() {
5858
* Sets whether to use simple name of class or not.
5959
*
6060
* @param isSimpleName Whether to use simple name of class or not.
61+
* @return {@code this} for chaining.
6162
*/
62-
public void setSimpleName(boolean isSimpleName) {
63+
public BinaryBasicNameMapper setSimpleName(boolean isSimpleName) {
6364
this.isSimpleName = isSimpleName;
65+
66+
return this;
6467
}
6568

6669
/** {@inheritDoc} */

0 commit comments

Comments
 (0)