Migrate ActorUtils to java.util.Optional 01/83001/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Jul 2019 13:20:33 +0000 (15:20 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Jul 2019 14:59:52 +0000 (16:59 +0200)
This migrates ActorUtils to Java 8 Optional, updating its users.

Change-Id: I0ec900d16bf44b2ab8ae48d8a72f2b63fa633312
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-cluster-admin-impl/src/test/java/org/opendaylight/controller/cluster/datastore/admin/ClusterAdminRpcServiceTest.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorUtils.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/CDSShardAccessImpl.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/MemberNode.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorUtilsTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/CDSShardAccessImplTest.java

index cc70f7e..cab3281 100644 (file)
@@ -26,7 +26,6 @@ import akka.actor.ActorRef;
 import akka.actor.PoisonPill;
 import akka.actor.Status.Success;
 import akka.cluster.Cluster;
-import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
@@ -44,6 +43,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import org.apache.commons.lang3.SerializationUtils;
@@ -454,8 +454,8 @@ public class ClusterAdminRpcServiceTest {
 
     private static void readCarsNodeAndVerify(final AbstractDataStore readFromStore,
             final NormalizedNode<?, ?> expCarsNode) throws Exception {
-        java.util.Optional<NormalizedNode<?, ?>> optional = readFromStore.newReadOnlyTransaction()
-                .read(CarsModel.BASE_PATH).get(15, TimeUnit.SECONDS);
+        Optional<NormalizedNode<?, ?>> optional = readFromStore.newReadOnlyTransaction().read(CarsModel.BASE_PATH)
+                .get(15, TimeUnit.SECONDS);
         assertTrue("isPresent", optional.isPresent());
         assertEquals("Data node", expCarsNode, optional.get());
     }
index a1efbf2..3007e4b 100644 (file)
@@ -21,9 +21,9 @@ import akka.pattern.Patterns;
 import akka.util.Timeout;
 import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.Timer;
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
+import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import org.opendaylight.controller.cluster.access.concepts.MemberName;
@@ -266,7 +266,7 @@ public class ActorUtils {
             return Optional.of(found.getPath());
         }
 
-        return Optional.absent();
+        return Optional.empty();
     }
 
     /**
index dc0fabf..3007595 100644 (file)
@@ -18,8 +18,8 @@ import akka.dispatch.Futures;
 import akka.dispatch.Mapper;
 import akka.dispatch.OnComplete;
 import akka.util.Timeout;
-import com.google.common.base.Optional;
 import java.util.Collection;
+import java.util.Optional;
 import java.util.concurrent.CompletionStage;
 import java.util.concurrent.ConcurrentHashMap;
 import org.opendaylight.controller.cluster.datastore.exceptions.LocalShardNotFoundException;
index b9019f0..11db817 100644 (file)
@@ -20,7 +20,6 @@ import akka.dispatch.Mapper;
 import akka.dispatch.OnComplete;
 import akka.pattern.Patterns;
 import akka.util.Timeout;
-import com.google.common.base.Optional;
 import com.google.common.base.Throwables;
 import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.ForwardingObject;
@@ -40,6 +39,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.CompletionStage;
 import java.util.concurrent.ExecutionException;
index 5317a04..5ab402c 100644 (file)
@@ -25,7 +25,6 @@ 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;
@@ -33,6 +32,7 @@ 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;
@@ -436,7 +436,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 {
@@ -453,7 +453,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());
@@ -525,7 +525,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(
@@ -587,7 +587,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());
@@ -624,7 +624,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",
@@ -638,7 +638,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(
@@ -667,7 +667,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());
@@ -713,7 +713,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(
index 0fb3a41..04217d1 100644 (file)
@@ -637,7 +637,7 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
         initDatastoresWithCars("testReadyLocalTransactionForwardedToLeader");
         followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorUtils(), "cars");
 
-        final com.google.common.base.Optional<ActorRef> carsFollowerShard =
+        final Optional<ActorRef> carsFollowerShard =
                 followerDistributedDataStore.getActorUtils().findLocalShard("cars");
         assertTrue("Cars follower shard found", carsFollowerShard.isPresent());
 
@@ -704,7 +704,7 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
         initDatastoresWithCars("testForwardedReadyTransactionForwardedToLeader");
         followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorUtils(), "cars");
 
-        final com.google.common.base.Optional<ActorRef> carsFollowerShard =
+        final Optional<ActorRef> carsFollowerShard =
                 followerDistributedDataStore.getActorUtils().findLocalShard("cars");
         assertTrue("Cars follower shard found", carsFollowerShard.isPresent());
 
index b483be8..8dded6d 100644 (file)
@@ -251,7 +251,7 @@ public class IntegrationTestKit extends ShardTestKit {
         ActorRef shard = null;
         for (int i = 0; i < 20 * 5 && shard == null; i++) {
             Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
-            com.google.common.base.Optional<ActorRef> shardReply = actorUtils.findLocalShard(shardName);
+            Optional<ActorRef> shardReply = actorUtils.findLocalShard(shardName);
             if (shardReply.isPresent()) {
                 shard = shardReply.get();
             }
@@ -263,7 +263,7 @@ public class IntegrationTestKit extends ShardTestKit {
         for (int i = 0; i < 20 * 5 ; i++) {
             LOG.debug("Waiting for shard down {}", shardName);
             Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
-            com.google.common.base.Optional<ActorRef> shardReply = actorUtils.findLocalShard(shardName);
+            Optional<ActorRef> shardReply = actorUtils.findLocalShard(shardName);
             if (!shardReply.isPresent()) {
                 return;
             }
index 60cc13b..35ddd7e 100644 (file)
@@ -17,7 +17,6 @@ import akka.cluster.Cluster;
 import akka.cluster.ClusterEvent.CurrentClusterState;
 import akka.cluster.Member;
 import akka.cluster.MemberStatus;
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Stopwatch;
 import com.google.common.collect.Sets;
@@ -25,6 +24,7 @@ import com.google.common.util.concurrent.Uninterruptibles;
 import com.typesafe.config.Config;
 import com.typesafe.config.ConfigFactory;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import org.opendaylight.controller.cluster.access.concepts.MemberName;
index 919b49f..b4f725a 100644 (file)
@@ -5,7 +5,6 @@
  * 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.datastore.utils;
 
 import static org.junit.Assert.assertEquals;
@@ -30,13 +29,13 @@ import akka.japi.Creator;
 import akka.testkit.TestActorRef;
 import akka.testkit.javadsl.TestKit;
 import akka.util.Timeout;
-import com.google.common.base.Optional;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import com.typesafe.config.ConfigFactory;
 import java.time.Duration;
 import java.util.Arrays;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 import org.junit.Assert;
 import org.junit.Test;

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.