/**
*/
- protected ShardManager(Builder builder) {
+ protected ShardManager(AbstractBuilder<?> builder) {
this.cluster = builder.cluster;
this.configuration = builder.configuration;
return new Builder();
}
- public static class Builder {
+ public static abstract class AbstractBuilder<T extends AbstractBuilder<T>> {
private ClusterWrapper cluster;
private Configuration configuration;
private DatastoreContextFactory datastoreContextFactory;
private DatastoreSnapshot restoreFromSnapshot;
private volatile boolean sealed;
+ @SuppressWarnings("unchecked")
+ private T self() {
+ return (T) this;
+ }
+
protected void checkSealed() {
Preconditions.checkState(!sealed, "Builder is already sealed - further modifications are not allowed");
}
- public Builder cluster(ClusterWrapper cluster) {
+ public T cluster(ClusterWrapper cluster) {
checkSealed();
this.cluster = cluster;
- return this;
+ return self();
}
- public Builder configuration(Configuration configuration) {
+ public T configuration(Configuration configuration) {
checkSealed();
this.configuration = configuration;
- return this;
+ return self();
}
- public Builder datastoreContextFactory(DatastoreContextFactory datastoreContextFactory) {
+ public T datastoreContextFactory(DatastoreContextFactory datastoreContextFactory) {
checkSealed();
this.datastoreContextFactory = datastoreContextFactory;
- return this;
+ return self();
}
- public Builder waitTillReadyCountdownLatch(CountDownLatch waitTillReadyCountdownLatch) {
+ public T waitTillReadyCountdownLatch(CountDownLatch waitTillReadyCountdownLatch) {
checkSealed();
this.waitTillReadyCountdownLatch = waitTillReadyCountdownLatch;
- return this;
+ return self();
}
- public Builder primaryShardInfoCache(PrimaryShardInfoFutureCache primaryShardInfoCache) {
+ public T primaryShardInfoCache(PrimaryShardInfoFutureCache primaryShardInfoCache) {
checkSealed();
this.primaryShardInfoCache = primaryShardInfoCache;
- return this;
+ return self();
}
- public Builder restoreFromSnapshot(DatastoreSnapshot restoreFromSnapshot) {
+ public T restoreFromSnapshot(DatastoreSnapshot restoreFromSnapshot) {
checkSealed();
this.restoreFromSnapshot = restoreFromSnapshot;
- return this;
+ return self();
}
protected void verify() {
}
}
+ public static class Builder extends AbstractBuilder<Builder> {
+ }
+
private void findPrimary(final String shardName, final FindPrimaryResponseHandler handler) {
Timeout findPrimaryTimeout = new Timeout(datastoreContextFactory.getBaseDatastoreContext().
getShardInitializationTimeout().duration().$times(2));