Bump versions to 4.0.0-SNAPSHOT
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / ShardedDataTreeActor.java
index 679055fa2fd3fd79d243b7214603870279ca3bff..52c3d25faa18ef1de438d06e0c468f05998bf1a0 100644 (file)
@@ -5,9 +5,10 @@
  * 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.cluster.sharding;
 
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.ActorRef;
 import akka.actor.ActorSelection;
 import akka.actor.ActorSystem;
@@ -26,20 +27,19 @@ import akka.cluster.Member;
 import akka.dispatch.OnComplete;
 import akka.pattern.Patterns;
 import akka.util.Timeout;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
 import org.opendaylight.controller.cluster.access.concepts.MemberName;
 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedPersistentActor;
-import org.opendaylight.controller.cluster.datastore.AbstractDataStore;
 import org.opendaylight.controller.cluster.datastore.ClusterWrapper;
+import org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface;
 import org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration;
 import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
 import org.opendaylight.controller.cluster.datastore.utils.ClusterUtils;
@@ -74,6 +74,7 @@ import scala.concurrent.duration.FiniteDuration;
  * Actor that tracks currently open producers/shards on remote nodes and handles notifications of remote
  * nodes of newly open producers/shards on the local node.
  */
+@Deprecated(forRemoval = true)
 public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
 
     private static final Logger LOG = LoggerFactory.getLogger(ShardedDataTreeActor.class);
@@ -90,8 +91,8 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
     // for calls that need specific actor context tied to a datastore use the one provided in the DistributedDataStore
     private final ActorUtils actorUtils;
     private final ShardingServiceAddressResolver resolver;
-    private final AbstractDataStore distributedConfigDatastore;
-    private final AbstractDataStore distributedOperDatastore;
+    private final DistributedDataStoreInterface distributedConfigDatastore;
+    private final DistributedDataStoreInterface distributedOperDatastore;
     private final int lookupTaskMaxRetries;
 
     private final Map<DOMDataTreeIdentifier, ActorProducerRegistration> idToProducer = new HashMap<>();
@@ -312,13 +313,13 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
 
         final DOMDataTreeIdentifier prefix = message.getPrefix();
 
-        final ActorUtils context = prefix.getDatastoreType() == LogicalDatastoreType.CONFIGURATION
+        final ActorUtils utils = prefix.getDatastoreType() == LogicalDatastoreType.CONFIGURATION
                         ? distributedConfigDatastore.getActorUtils() : distributedOperDatastore.getActorUtils();
 
         // schedule a notification task for the reply
         actorSystem.scheduler().scheduleOnce(SHARD_LOOKUP_TASK_INTERVAL,
                 new ShardCreationLookupTask(actorSystem, getSender(), clusterWrapper,
-                        context, shardingService, prefix, lookupTaskMaxRetries), actorSystem.dispatcher());
+                        utils, shardingService, prefix, lookupTaskMaxRetries), actorSystem.dispatcher());
     }
 
     private void onPrefixShardCreated(final PrefixShardCreated message) {
@@ -437,7 +438,7 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
 
             localShardFuture.onComplete(new OnComplete<ActorRef>() {
                 @Override
-                public void onComplete(Throwable throwable, ActorRef actorRef) {
+                public void onComplete(final Throwable throwable, final ActorRef actorRef) {
                     if (throwable != null) {
                         tryReschedule(throwable);
                     } else {
@@ -454,7 +455,7 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
         }
 
         @Override
-        void reschedule(int retries) {
+        void reschedule(final int retries) {
             LOG.debug("Local backend for shard[{}] not found, try: {}, rescheduling..", toLookup, retries);
             system.scheduler().scheduleOnce(
                     SHARD_LOOKUP_TASK_INTERVAL, ShardCreationLookupTask.this, system.dispatcher());
@@ -499,14 +500,14 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
 
             final Future<Object> ask = Patterns.ask(shard, FindLeader.INSTANCE, context.getOperationTimeout());
 
-            ask.onComplete(new OnComplete<Object>() {
+            ask.onComplete(new OnComplete<>() {
                 @Override
                 public void onComplete(final Throwable throwable, final Object findLeaderReply) {
                     if (throwable != null) {
                         tryReschedule(throwable);
                     } else {
                         final FindLeaderReply findLeader = (FindLeaderReply) findLeaderReply;
-                        final java.util.Optional<String> leaderActor = findLeader.getLeaderActor();
+                        final Optional<String> leaderActor = findLeader.getLeaderActor();
                         if (leaderActor.isPresent()) {
                             // leader is found, backend seems ready, check if the frontend is ready
                             LOG.debug("{} - Leader for shard[{}] backend ready, starting frontend lookup..",
@@ -526,7 +527,7 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
         }
 
         @Override
-        void reschedule(int retries) {
+        void reschedule(final int retries) {
             LOG.debug("{} - Leader for shard[{}] backend not found on try: {}, retrying..",
                     clusterWrapper.getCurrentMemberName(), toLookup, retries);
             system.scheduler().scheduleOnce(
@@ -576,7 +577,7 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
                 return false;
             }
 
-            if (YangInstanceIdentifier.EMPTY.equals(prefix.getRootIdentifier())) {
+            if (YangInstanceIdentifier.empty().equals(prefix.getRootIdentifier())) {
                 return true;
             }
 
@@ -588,7 +589,7 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
         }
 
         @Override
-        void reschedule(int retries) {
+        void reschedule(final int retries) {
             LOG.debug("Frontend for shard[{}] not found on try: {}, retrying..", toLookup, retries);
             system.scheduler().scheduleOnce(
                     SHARD_LOOKUP_TASK_INTERVAL, FrontendLookupTask.this, system.dispatcher());
@@ -625,7 +626,7 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
 
             localShardFuture.onComplete(new OnComplete<ActorRef>() {
                 @Override
-                public void onComplete(Throwable throwable, ActorRef actorRef) {
+                public void onComplete(final Throwable throwable, final ActorRef actorRef) {
                     if (throwable != null) {
                         //TODO Shouldn't we check why findLocalShard failed?
                         LOG.debug("Backend shard[{}] removal lookup successful notifying the registration future",
@@ -639,7 +640,7 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
         }
 
         @Override
-        void reschedule(int retries) {
+        void reschedule(final int retries) {
             LOG.debug("Backend shard[{}] removal lookup failed, shard is still present, try: {}, rescheduling..",
                     toLookup, retries);
             system.scheduler().scheduleOnce(
@@ -668,7 +669,7 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
         }
 
         @Override
-        void reschedule(int retries) {
+        void reschedule(final int retries) {
             LOG.debug("Local backend for prefix configuration shard not found, try: {}, rescheduling..", retries);
             system.scheduler().scheduleOnce(
                     SHARD_LOOKUP_TASK_INTERVAL, ConfigShardLookupTask.this, system.dispatcher());
@@ -714,7 +715,7 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
         }
 
         @Override
-        void reschedule(int retries) {
+        void reschedule(final int retries) {
             LOG.debug("{} - Leader for config shard not found on try: {}, retrying..",
                     clusterWrapper.getCurrentMemberName(), retries);
             system.scheduler().scheduleOnce(
@@ -725,14 +726,14 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
         public void run() {
             final Future<Object> ask = Patterns.ask(shard, FindLeader.INSTANCE, context.getOperationTimeout());
 
-            ask.onComplete(new OnComplete<Object>() {
+            ask.onComplete(new OnComplete<>() {
                 @Override
                 public void onComplete(final Throwable throwable, final Object findLeaderReply) {
                     if (throwable != null) {
                         tryReschedule(throwable);
                     } else {
                         final FindLeaderReply findLeader = (FindLeaderReply) findLeaderReply;
-                        final java.util.Optional<String> leaderActor = findLeader.getLeaderActor();
+                        final Optional<String> leaderActor = findLeader.getLeaderActor();
                         if (leaderActor.isPresent()) {
                             // leader is found, backend seems ready, check if the frontend is ready
                             LOG.debug("{} - Leader for config shard is ready. Ending lookup.",
@@ -750,8 +751,8 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
     public static class ShardedDataTreeActorCreator {
 
         private DistributedShardedDOMDataTree shardingService;
-        private AbstractDataStore distributedConfigDatastore;
-        private AbstractDataStore distributedOperDatastore;
+        private DistributedDataStoreInterface distributedConfigDatastore;
+        private DistributedDataStoreInterface distributedOperDatastore;
         private ActorSystem actorSystem;
         private ClusterWrapper cluster;
         private int maxRetries;
@@ -783,22 +784,22 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
             return cluster;
         }
 
-        public AbstractDataStore getDistributedConfigDatastore() {
+        public DistributedDataStoreInterface getDistributedConfigDatastore() {
             return distributedConfigDatastore;
         }
 
         public ShardedDataTreeActorCreator setDistributedConfigDatastore(
-                final AbstractDataStore distributedConfigDatastore) {
+                final DistributedDataStoreInterface distributedConfigDatastore) {
             this.distributedConfigDatastore = distributedConfigDatastore;
             return this;
         }
 
-        public AbstractDataStore getDistributedOperDatastore() {
+        public DistributedDataStoreInterface getDistributedOperDatastore() {
             return distributedOperDatastore;
         }
 
         public ShardedDataTreeActorCreator setDistributedOperDatastore(
-                final AbstractDataStore distributedOperDatastore) {
+                final DistributedDataStoreInterface distributedOperDatastore) {
             this.distributedOperDatastore = distributedOperDatastore;
             return this;
         }
@@ -813,11 +814,11 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
         }
 
         private void verify() {
-            Preconditions.checkNotNull(shardingService);
-            Preconditions.checkNotNull(actorSystem);
-            Preconditions.checkNotNull(cluster);
-            Preconditions.checkNotNull(distributedConfigDatastore);
-            Preconditions.checkNotNull(distributedOperDatastore);
+            requireNonNull(shardingService);
+            requireNonNull(actorSystem);
+            requireNonNull(cluster);
+            requireNonNull(distributedConfigDatastore);
+            requireNonNull(distributedOperDatastore);
         }
 
         public Props props() {