Fix modernization issues
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / registry / gossip / BucketStoreActor.java
index 02e8770337f0dbb407fed53bb08d98ecec6d38a4..b494256d500f2fe53f2660c3216ce503a4b09d91 100644 (file)
@@ -5,9 +5,11 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.remote.rpc.registry.gossip;
 
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Verify.verify;
+import static java.util.Objects.requireNonNull;
 import static org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreAccess.Singletons.GET_ALL_BUCKETS;
 import static org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreAccess.Singletons.GET_BUCKET_VERSIONS;
 
@@ -25,8 +27,6 @@ import akka.persistence.SaveSnapshotSuccess;
 import akka.persistence.SnapshotOffer;
 import akka.persistence.SnapshotSelectionCriteria;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Verify;
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.SetMultimap;
@@ -37,7 +37,7 @@ import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.function.Consumer;
 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedPersistentActorWithMetering;
-import org.opendaylight.controller.remote.rpc.RemoteRpcProviderConfig;
+import org.opendaylight.controller.remote.rpc.RemoteOpsProviderConfig;
 
 /**
  * A store that syncs its data across nodes in the cluster.
@@ -72,7 +72,7 @@ public abstract class BucketStoreActor<T extends BucketData<T>> extends
      */
     private final SetMultimap<ActorRef, Address> watchedActors = HashMultimap.create(1, 1);
 
-    private final RemoteRpcProviderConfig config;
+    private final RemoteOpsProviderConfig config;
     private final String persistenceId;
 
     /**
@@ -88,10 +88,10 @@ public abstract class BucketStoreActor<T extends BucketData<T>> extends
     private Integer incarnation;
     private boolean persisting;
 
-    protected BucketStoreActor(final RemoteRpcProviderConfig config, final String persistenceId, final T initialData) {
-        this.config = Preconditions.checkNotNull(config);
-        this.initialData = Preconditions.checkNotNull(initialData);
-        this.persistenceId = Preconditions.checkNotNull(persistenceId);
+    protected BucketStoreActor(final RemoteOpsProviderConfig config, final String persistenceId, final T initialData) {
+        this.config = requireNonNull(config);
+        this.initialData = requireNonNull(initialData);
+        this.persistenceId = requireNonNull(persistenceId);
     }
 
     static ExecuteInActor getBucketsByMembersMessage(final Collection<Address> members) {
@@ -106,6 +106,14 @@ public abstract class BucketStoreActor<T extends BucketData<T>> extends
         return actor -> actor.updateRemoteBuckets(buckets);
     }
 
+    static ExecuteInActor getLocalDataMessage() {
+        return actor -> actor.getSender().tell(actor.getLocalData(), actor.getSelf());
+    }
+
+    static ExecuteInActor getRemoteBucketsMessage() {
+        return actor -> actor.getSender().tell(ImmutableMap.copyOf(actor.getRemoteBuckets()), actor.getSelf());
+    }
+
     public final T getLocalData() {
         return getLocalBucket().getData();
     }
@@ -172,7 +180,7 @@ public abstract class BucketStoreActor<T extends BucketData<T>> extends
         } else if (message instanceof SaveSnapshotSuccess) {
             LOG.debug("{}: got command: {}", persistenceId(), message);
             SaveSnapshotSuccess saved = (SaveSnapshotSuccess)message;
-            deleteSnapshots(new SnapshotSelectionCriteria(saved.metadata().sequenceNr(),
+            deleteSnapshots(new SnapshotSelectionCriteria(scala.Long.MaxValue(),
                     saved.metadata().timestamp() - 1, 0L, 0L));
             persisting = false;
             unstash();
@@ -183,7 +191,7 @@ public abstract class BucketStoreActor<T extends BucketData<T>> extends
     }
 
     @Override
-    protected final void handleRecover(final Object message) throws Exception {
+    protected final void handleRecover(final Object message) {
         if (message instanceof RecoveryCompleted) {
             if (incarnation != null) {
                 incarnation = incarnation + 1;
@@ -204,7 +212,7 @@ public abstract class BucketStoreActor<T extends BucketData<T>> extends
         }
     }
 
-    protected final RemoteRpcProviderConfig getConfig() {
+    protected final RemoteOpsProviderConfig getConfig() {
         return config;
     }
 
@@ -216,7 +224,7 @@ public abstract class BucketStoreActor<T extends BucketData<T>> extends
         if (bumpIncarnation) {
             LOG.debug("Version wrapped. incrementing incarnation");
 
-            Verify.verify(incarnation < Integer.MAX_VALUE, "Ran out of incarnations, cannot continue");
+            verify(incarnation < Integer.MAX_VALUE, "Ran out of incarnations, cannot continue");
             incarnation = incarnation + 1;
 
             persisting = true;
@@ -369,7 +377,7 @@ public abstract class BucketStoreActor<T extends BucketData<T>> extends
             versions.remove(addr);
             final Bucket<T> bucket = remoteBuckets.remove(addr);
             if (bucket != null) {
-                LOG.debug("Source actor dead, removing bucket {} from ", bucket, addr);
+                LOG.debug("Source actor dead, removing bucket {} from {}", bucket, addr);
                 onBucketRemoved(addr, bucket);
             }
         }
@@ -381,7 +389,7 @@ public abstract class BucketStoreActor<T extends BucketData<T>> extends
     }
 
     private LocalBucket<T> getLocalBucket() {
-        Preconditions.checkState(localBucket != null, "Attempted to access local bucket before recovery completed");
+        checkState(localBucket != null, "Attempted to access local bucket before recovery completed");
         return localBucket;
     }
 }