Refactor DataStore readiness tracking
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / shardmanager / AbstractShardManagerCreator.java
index 4dd409e85e1d0624df16df2c5519df7241fe24ce..d28734bca3dff55792d3c2f433f6e2838b0291e1 100644 (file)
@@ -7,9 +7,11 @@
  */
 package org.opendaylight.controller.cluster.datastore.shardmanager;
 
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.Props;
-import com.google.common.base.Preconditions;
-import java.util.concurrent.CountDownLatch;
+import com.google.common.util.concurrent.SettableFuture;
 import org.opendaylight.controller.cluster.datastore.AbstractDataStore;
 import org.opendaylight.controller.cluster.datastore.ClusterWrapper;
 import org.opendaylight.controller.cluster.datastore.DatastoreContextFactory;
@@ -18,11 +20,11 @@ import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot
 import org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache;
 
 public abstract class AbstractShardManagerCreator<T extends AbstractShardManagerCreator<T>> {
+    private SettableFuture<Void> readinessFuture;
     private ClusterWrapper cluster;
     private Configuration configuration;
     private DatastoreContextFactory datastoreContextFactory;
     private AbstractDataStore distributedDataStore;
-    private CountDownLatch waitTillReadyCountDownLatch;
     private PrimaryShardInfoFutureCache primaryShardInfoCache;
     private DatastoreSnapshot restoreFromSnapshot;
     private volatile boolean sealed;
@@ -37,14 +39,14 @@ public abstract class AbstractShardManagerCreator<T extends AbstractShardManager
     }
 
     protected final void checkSealed() {
-        Preconditions.checkState(!sealed, "Builder is already sealed - further modifications are not allowed");
+        checkState(!sealed, "Builder is already sealed - further modifications are not allowed");
     }
 
     ClusterWrapper getCluster() {
         return cluster;
     }
 
-    public T cluster(ClusterWrapper newCluster) {
+    public T cluster(final ClusterWrapper newCluster) {
         checkSealed();
         this.cluster = newCluster;
         return self();
@@ -54,7 +56,7 @@ public abstract class AbstractShardManagerCreator<T extends AbstractShardManager
         return configuration;
     }
 
-    public T configuration(Configuration newConfiguration) {
+    public T configuration(final Configuration newConfiguration) {
         checkSealed();
         this.configuration = newConfiguration;
         return self();
@@ -66,7 +68,7 @@ public abstract class AbstractShardManagerCreator<T extends AbstractShardManager
 
     public T datastoreContextFactory(final DatastoreContextFactory newDatastoreContextFactory) {
         checkSealed();
-        this.datastoreContextFactory = Preconditions.checkNotNull(newDatastoreContextFactory);
+        this.datastoreContextFactory = requireNonNull(newDatastoreContextFactory);
         return self();
     }
 
@@ -74,19 +76,19 @@ public abstract class AbstractShardManagerCreator<T extends AbstractShardManager
         return distributedDataStore;
     }
 
-    public T distributedDataStore(final AbstractDataStore distributedDataStore) {
+    public T distributedDataStore(final AbstractDataStore newDistributedDataStore) {
         checkSealed();
-        this.distributedDataStore = distributedDataStore;
+        this.distributedDataStore = newDistributedDataStore;
         return self();
     }
 
-    CountDownLatch getWaitTillReadyCountDownLatch() {
-        return waitTillReadyCountDownLatch;
+    SettableFuture<Void> getReadinessFuture() {
+        return readinessFuture;
     }
 
-    public T waitTillReadyCountDownLatch(CountDownLatch newWaitTillReadyCountDownLatch) {
+    public T readinessFuture(final SettableFuture<Void> newReadinessFuture) {
         checkSealed();
-        this.waitTillReadyCountDownLatch = newWaitTillReadyCountDownLatch;
+        this.readinessFuture = newReadinessFuture;
         return self();
     }
 
@@ -94,7 +96,7 @@ public abstract class AbstractShardManagerCreator<T extends AbstractShardManager
         return primaryShardInfoCache;
     }
 
-    public T primaryShardInfoCache(PrimaryShardInfoFutureCache newPrimaryShardInfoCache) {
+    public T primaryShardInfoCache(final PrimaryShardInfoFutureCache newPrimaryShardInfoCache) {
         checkSealed();
         this.primaryShardInfoCache = newPrimaryShardInfoCache;
         return self();
@@ -104,7 +106,7 @@ public abstract class AbstractShardManagerCreator<T extends AbstractShardManager
         return restoreFromSnapshot;
     }
 
-    public T restoreFromSnapshot(DatastoreSnapshot newRestoreFromSnapshot) {
+    public T restoreFromSnapshot(final DatastoreSnapshot newRestoreFromSnapshot) {
         checkSealed();
         this.restoreFromSnapshot = newRestoreFromSnapshot;
         return self();
@@ -112,12 +114,12 @@ public abstract class AbstractShardManagerCreator<T extends AbstractShardManager
 
     protected void verify() {
         sealed = true;
-        Preconditions.checkNotNull(cluster, "cluster should not be null");
-        Preconditions.checkNotNull(configuration, "configuration should not be null");
-        Preconditions.checkNotNull(datastoreContextFactory, "datastoreContextFactory should not be null");
-        Preconditions.checkNotNull(distributedDataStore, "distributedDataStore should not be null");
-        Preconditions.checkNotNull(waitTillReadyCountDownLatch, "waitTillReadyCountdownLatch should not be null");
-        Preconditions.checkNotNull(primaryShardInfoCache, "primaryShardInfoCache should not be null");
+        requireNonNull(cluster, "cluster should not be null");
+        requireNonNull(configuration, "configuration should not be null");
+        requireNonNull(datastoreContextFactory, "datastoreContextFactory should not be null");
+        requireNonNull(distributedDataStore, "distributedDataStore should not be null");
+        requireNonNull(readinessFuture, "readinessFuture should not be null");
+        requireNonNull(primaryShardInfoCache, "primaryShardInfoCache should not be null");
     }
 
     public Props props() {