From 3d8f5da25156aa5ca2a82c7bfa1c1abbd80e8d73 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 10 Jul 2019 15:20:33 +0200 Subject: [PATCH] Migrate ActorUtils to java.util.Optional This migrates ActorUtils to Java 8 Optional, updating its users. Change-Id: I0ec900d16bf44b2ab8ae48d8a72f2b63fa633312 Signed-off-by: Robert Varga --- .../admin/ClusterAdminRpcServiceTest.java | 6 +++--- .../cluster/datastore/utils/ActorUtils.java | 4 ++-- .../cluster/sharding/CDSShardAccessImpl.java | 2 +- .../DistributedShardedDOMDataTree.java | 2 +- .../cluster/sharding/ShardedDataTreeActor.java | 18 +++++++++--------- ...ibutedDataStoreRemotingIntegrationTest.java | 4 ++-- .../cluster/datastore/IntegrationTestKit.java | 4 ++-- .../cluster/datastore/MemberNode.java | 2 +- .../datastore/utils/ActorUtilsTest.java | 3 +-- .../sharding/CDSShardAccessImplTest.java | 2 +- 10 files changed, 23 insertions(+), 24 deletions(-) diff --git a/opendaylight/md-sal/sal-cluster-admin-impl/src/test/java/org/opendaylight/controller/cluster/datastore/admin/ClusterAdminRpcServiceTest.java b/opendaylight/md-sal/sal-cluster-admin-impl/src/test/java/org/opendaylight/controller/cluster/datastore/admin/ClusterAdminRpcServiceTest.java index cc70f7e673..cab3281c80 100644 --- a/opendaylight/md-sal/sal-cluster-admin-impl/src/test/java/org/opendaylight/controller/cluster/datastore/admin/ClusterAdminRpcServiceTest.java +++ b/opendaylight/md-sal/sal-cluster-admin-impl/src/test/java/org/opendaylight/controller/cluster/datastore/admin/ClusterAdminRpcServiceTest.java @@ -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> optional = readFromStore.newReadOnlyTransaction() - .read(CarsModel.BASE_PATH).get(15, TimeUnit.SECONDS); + Optional> optional = readFromStore.newReadOnlyTransaction().read(CarsModel.BASE_PATH) + .get(15, TimeUnit.SECONDS); assertTrue("isPresent", optional.isPresent()); assertEquals("Data node", expCarsNode, optional.get()); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorUtils.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorUtils.java index a1efbf2d9b..3007e4b187 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorUtils.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorUtils.java @@ -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(); } /** diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/CDSShardAccessImpl.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/CDSShardAccessImpl.java index dc0fabfafb..300759532d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/CDSShardAccessImpl.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/CDSShardAccessImpl.java @@ -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; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java index b9019f0f4d..11db817522 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java @@ -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; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java index 5317a04c66..5ab402ce59 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java @@ -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() { @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() { @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( diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java index 0fb3a41c7d..04217d1944 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java @@ -637,7 +637,7 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest { initDatastoresWithCars("testReadyLocalTransactionForwardedToLeader"); followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorUtils(), "cars"); - final com.google.common.base.Optional carsFollowerShard = + final Optional 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 carsFollowerShard = + final Optional carsFollowerShard = followerDistributedDataStore.getActorUtils().findLocalShard("cars"); assertTrue("Cars follower shard found", carsFollowerShard.isPresent()); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java index b483be873f..8dded6dd8d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java @@ -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 shardReply = actorUtils.findLocalShard(shardName); + Optional 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 shardReply = actorUtils.findLocalShard(shardName); + Optional shardReply = actorUtils.findLocalShard(shardName); if (!shardReply.isPresent()) { return; } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/MemberNode.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/MemberNode.java index 60cc13b6c1..35ddd7e779 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/MemberNode.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/MemberNode.java @@ -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; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorUtilsTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorUtilsTest.java index 919b49f305..b4f725a3c4 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorUtilsTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorUtilsTest.java @@ -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; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/CDSShardAccessImplTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/CDSShardAccessImplTest.java index 9470682985..3c7e8cd187 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/CDSShardAccessImplTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/CDSShardAccessImplTest.java @@ -21,7 +21,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import akka.actor.ActorRef; import akka.dispatch.Futures; -import com.google.common.base.Optional; +import java.util.Optional; import java.util.concurrent.TimeUnit; import org.junit.Before; import org.junit.Test; -- 2.36.6