Migrate most of CDS to use java.util.Optional 07/83007/6
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Jul 2019 14:25:37 +0000 (16:25 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Jul 2019 17:08:44 +0000 (19:08 +0200)
This picks up some stragglers, updating them to not use Guava's
Optional.

Change-Id: Id6e4c27e5bd55f19058e87f04473b859922bd441
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
14 files changed:
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DefaultShardDataTreeChangeListenerPublisher.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeChangeListenerPublisher.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeChangeListenerPublisherActorProxy.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeChangePublisherActor.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/AbstractEntityOwnerChangeListener.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.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/AbstractShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeCohortIntegrationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContextTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardRecoveryCoordinatorTest.java

index 7865fdf..720aadb 100644 (file)
@@ -7,8 +7,8 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
-import com.google.common.base.Optional;
 import java.util.Collection;
+import java.util.Optional;
 import java.util.function.Consumer;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.mdsal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration;
@@ -30,7 +30,7 @@ final class DefaultShardDataTreeChangeListenerPublisher extends AbstractDOMStore
     private static final Logger LOG = LoggerFactory.getLogger(DefaultShardDataTreeChangeListenerPublisher.class);
     private String logContext;
 
-    DefaultShardDataTreeChangeListenerPublisher(String logContext) {
+    DefaultShardDataTreeChangeListenerPublisher(final String logContext) {
         this.logContext = logContext;
     }
 
@@ -46,8 +46,8 @@ final class DefaultShardDataTreeChangeListenerPublisher extends AbstractDOMStore
     }
 
     @Override
-    protected void notifyListener(AbstractDOMDataTreeChangeListenerRegistration<?> registration,
-            Collection<DataTreeCandidate> changes) {
+    protected void notifyListener(final AbstractDOMDataTreeChangeListenerRegistration<?> registration,
+            final Collection<DataTreeCandidate> changes) {
         LOG.debug("{}: notifyListener: listener: {}", logContext, registration.getInstance());
         registration.getInstance().onDataTreeChanged(changes);
     }
@@ -58,9 +58,9 @@ final class DefaultShardDataTreeChangeListenerPublisher extends AbstractDOMStore
     }
 
     @Override
-    public void registerTreeChangeListener(YangInstanceIdentifier treeId, DOMDataTreeChangeListener listener,
-            Optional<DataTreeCandidate> initialState,
-            Consumer<ListenerRegistration<DOMDataTreeChangeListener>> onRegistration) {
+    public void registerTreeChangeListener(final YangInstanceIdentifier treeId,
+            final DOMDataTreeChangeListener listener, final Optional<DataTreeCandidate> initialState,
+            final Consumer<ListenerRegistration<DOMDataTreeChangeListener>> onRegistration) {
         registerTreeChangeListener(treeId, listener, onRegistration);
 
         if (initialState.isPresent()) {
@@ -70,8 +70,8 @@ final class DefaultShardDataTreeChangeListenerPublisher extends AbstractDOMStore
         }
     }
 
-    void registerTreeChangeListener(YangInstanceIdentifier treeId, DOMDataTreeChangeListener listener,
-            Consumer<ListenerRegistration<DOMDataTreeChangeListener>> onRegistration) {
+    void registerTreeChangeListener(final YangInstanceIdentifier treeId, final DOMDataTreeChangeListener listener,
+            final Consumer<ListenerRegistration<DOMDataTreeChangeListener>> onRegistration) {
         LOG.debug("{}: registerTreeChangeListener: path: {}, listener: {}", logContext, treeId, listener);
 
         AbstractDOMDataTreeChangeListenerRegistration<DOMDataTreeChangeListener> registration =
@@ -80,8 +80,8 @@ final class DefaultShardDataTreeChangeListenerPublisher extends AbstractDOMStore
         onRegistration.accept(registration);
     }
 
-    static void notifySingleListener(YangInstanceIdentifier treeId, DOMDataTreeChangeListener listener,
-            DataTreeCandidate state, String logContext) {
+    static void notifySingleListener(final YangInstanceIdentifier treeId, final DOMDataTreeChangeListener listener,
+            final DataTreeCandidate state, final String logContext) {
         LOG.debug("{}: notifySingleListener: path: {}, listener: {}", logContext, treeId, listener);
         DefaultShardDataTreeChangeListenerPublisher publisher =
                 new DefaultShardDataTreeChangeListenerPublisher(logContext);
index 5c94a8e..941ec2d 100644 (file)
@@ -11,7 +11,6 @@ import akka.actor.ActorRef;
 import akka.util.Timeout;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.MoreObjects;
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Stopwatch;
 import com.google.common.base.Verify;
@@ -33,6 +32,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Optional;
 import java.util.OptionalLong;
 import java.util.Queue;
 import java.util.SortedSet;
@@ -266,7 +266,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
         // delete everything first
         mod.delete(YangInstanceIdentifier.EMPTY);
 
-        final java.util.Optional<NormalizedNode<?, ?>> maybeNode = snapshot.getRootNode();
+        final Optional<NormalizedNode<?, ?>> maybeNode = snapshot.getRootNode();
         if (maybeNode.isPresent()) {
             // Add everything from the remote node back
             mod.write(YangInstanceIdentifier.EMPTY, maybeNode.get());
@@ -643,10 +643,8 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
     }
 
     Optional<DataTreeCandidate> readCurrentData() {
-        final java.util.Optional<NormalizedNode<?, ?>> currentState =
-                dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY);
-        return currentState.isPresent() ? Optional.of(DataTreeCandidates.fromNormalizedNode(
-            YangInstanceIdentifier.EMPTY, currentState.get())) : Optional.<DataTreeCandidate>absent();
+        return dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY)
+                .map(state -> DataTreeCandidates.fromNormalizedNode(YangInstanceIdentifier.EMPTY, state));
     }
 
     public void registerTreeChangeListener(final YangInstanceIdentifier path, final DOMDataTreeChangeListener listener,
@@ -675,7 +673,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
 
     @Override
     ShardDataTreeCohort finishTransaction(final ReadWriteShardDataTreeTransaction transaction,
-            final java.util.Optional<SortedSet<String>> participatingShardNames) {
+            final Optional<SortedSet<String>> participatingShardNames) {
         final DataTreeModification snapshot = transaction.getSnapshot();
         final TransactionIdentifier id = transaction.getIdentifier();
         LOG.debug("{}: readying transaction {}", logContext, id);
@@ -692,7 +690,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
     }
 
     public Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier path) {
-        return Optional.fromJavaUtil(dataTree.takeSnapshot().readNode(path));
+        return dataTree.takeSnapshot().readNode(path);
     }
 
     DataTreeSnapshot takeSnapshot() {
@@ -918,8 +916,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
         tempStack.forEach(queue::addFirst);
     }
 
-    private Collection<String> extractPrecedingShardNames(
-            final java.util.Optional<SortedSet<String>> participatingShardNames) {
+    private Collection<String> extractPrecedingShardNames(final Optional<SortedSet<String>> participatingShardNames) {
         return participatingShardNames.map((Function<SortedSet<String>, Collection<String>>)
             set -> set.headSet(shard.getShardName())).orElse(Collections.<String>emptyList());
     }
@@ -1086,7 +1083,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
 
     @Override
     ShardDataTreeCohort createReadyCohort(final TransactionIdentifier txId, final DataTreeModification mod,
-            final java.util.Optional<SortedSet<String>> participatingShardNames) {
+            final Optional<SortedSet<String>> participatingShardNames) {
         SimpleShardDataTreeCohort cohort = new SimpleShardDataTreeCohort(this, mod, txId,
                 cohortRegistry.createCohort(schemaContext, txId, shard::executeInSelf,
                         COMMIT_STEP_TIMEOUT), participatingShardNames);
@@ -1097,7 +1094,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
     // Exposed for ShardCommitCoordinator so it does not have deal with local histories (it does not care), this mimics
     // the newReadWriteTransaction()
     ShardDataTreeCohort newReadyCohort(final TransactionIdentifier txId, final DataTreeModification mod,
-            final java.util.Optional<SortedSet<String>> participatingShardNames) {
+            final Optional<SortedSet<String>> participatingShardNames) {
         if (txId.getHistoryId().getHistoryId() == 0) {
             return createReadyCohort(txId, mod, participatingShardNames);
         }
index ed4d1f8..d737b55 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.controller.cluster.datastore;
 import akka.actor.ActorContext;
 import akka.actor.ActorRef;
 import akka.actor.Props;
-import com.google.common.base.Optional;
+import java.util.Optional;
 import java.util.function.Consumer;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
@@ -26,14 +26,15 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 class ShardDataTreeChangeListenerPublisherActorProxy extends AbstractShardDataTreeNotificationPublisherActorProxy
         implements ShardDataTreeChangeListenerPublisher {
 
-    ShardDataTreeChangeListenerPublisherActorProxy(ActorContext actorContext, String actorName, String logContext) {
+    ShardDataTreeChangeListenerPublisherActorProxy(final ActorContext actorContext, final String actorName,
+        final String logContext) {
         super(actorContext, actorName, logContext);
     }
 
     @Override
-    public void registerTreeChangeListener(YangInstanceIdentifier treeId,
-            DOMDataTreeChangeListener listener, Optional<DataTreeCandidate> currentState,
-            Consumer<ListenerRegistration<DOMDataTreeChangeListener>> onRegistration) {
+    public void registerTreeChangeListener(final YangInstanceIdentifier treeId,
+            final DOMDataTreeChangeListener listener, final Optional<DataTreeCandidate> currentState,
+            final Consumer<ListenerRegistration<DOMDataTreeChangeListener>> onRegistration) {
         final ShardDataTreeChangePublisherActor.RegisterListener regMessage =
                 new ShardDataTreeChangePublisherActor.RegisterListener(treeId, listener, currentState, onRegistration);
         log.debug("{}: Sending {} to publisher actor {}", logContext(), regMessage, publisherActor());
index 927e39f..e099d0b 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.Props;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
+import java.util.Optional;
 import java.util.function.Consumer;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
@@ -59,10 +60,10 @@ public final class ShardDataTreeChangePublisherActor
         RegisterListener(final YangInstanceIdentifier path, final DOMDataTreeChangeListener listener,
                 final Optional<DataTreeCandidate> initialState,
                 final Consumer<ListenerRegistration<DOMDataTreeChangeListener>> onRegistration) {
-            this.path = Preconditions.checkNotNull(path);
-            this.listener = Preconditions.checkNotNull(listener);
-            this.initialState = Preconditions.checkNotNull(initialState);
-            this.onRegistration = Preconditions.checkNotNull(onRegistration);
+            this.path = requireNonNull(path);
+            this.listener = requireNonNull(listener);
+            this.initialState = requireNonNull(initialState);
+            this.onRegistration = requireNonNull(onRegistration);
         }
 
         @Override
index cf1fd43..25f1790 100644 (file)
@@ -5,14 +5,13 @@
  * 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.entityownership;
 
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNERS_PATH;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNER_QNAME;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_QNAME;
 
-import com.google.common.base.Optional;
+import java.util.Optional;
 import org.opendaylight.controller.cluster.datastore.ShardDataTree;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.EntityType;
@@ -25,7 +24,7 @@ public abstract class AbstractEntityOwnerChangeListener implements DOMDataTreeCh
             .node(ENTITY_OWNER_QNAME).build();
 
     void init(final ShardDataTree shardDataTree) {
-        shardDataTree.registerTreeChangeListener(EOS_PATH, this, Optional.absent(), noop -> { /* NOOP */ });
+        shardDataTree.registerTreeChangeListener(EOS_PATH, this, Optional.empty(), noop -> { /* NOOP */ });
     }
 
     protected static String extractOwner(final LeafNode<?> ownerLeaf) {
index a7be8c5..35ef06b 100644 (file)
@@ -5,17 +5,15 @@
  * 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.entityownership;
 
+import static java.util.Objects.requireNonNull;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.CANDIDATE_NAME_QNAME;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_ID_QNAME;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNERS_PATH;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_QNAME;
 
 import akka.actor.ActorRef;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -24,6 +22,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Optional;
 import org.opendaylight.controller.cluster.datastore.ShardDataTree;
 import org.opendaylight.controller.cluster.datastore.entityownership.messages.CandidateAdded;
 import org.opendaylight.controller.cluster.datastore.entityownership.messages.CandidateRemoved;
@@ -53,19 +52,19 @@ class CandidateListChangeListener implements DOMDataTreeChangeListener {
     private final ActorRef shard;
     private final Map<YangInstanceIdentifier, Collection<String>> currentCandidates = new HashMap<>();
 
-    CandidateListChangeListener(ActorRef shard, String logId) {
-        this.shard = Preconditions.checkNotNull(shard, "shard should not be null");
+    CandidateListChangeListener(final ActorRef shard, final String logId) {
+        this.shard = requireNonNull(shard, "shard should not be null");
         this.logId = logId;
     }
 
-    void init(ShardDataTree shardDataTree) {
+    void init(final ShardDataTree shardDataTree) {
         shardDataTree.registerTreeChangeListener(YangInstanceIdentifier.builder(ENTITY_OWNERS_PATH)
             .node(EntityType.QNAME).node(EntityType.QNAME).node(ENTITY_QNAME).node(ENTITY_QNAME)
-                .node(Candidate.QNAME).node(Candidate.QNAME).build(), this, Optional.absent(), noop -> { /* NOOP */ });
+                .node(Candidate.QNAME).node(Candidate.QNAME).build(), this, Optional.empty(), noop -> { /* NOOP */ });
     }
 
     @Override
-    public void onDataTreeChanged(Collection<DataTreeCandidate> changes) {
+    public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
         for (DataTreeCandidate change: changes) {
             DataTreeCandidateNode changeRoot = change.getRootNode();
             ModificationType type = changeRoot.getModificationType();
@@ -92,14 +91,15 @@ class CandidateListChangeListener implements DOMDataTreeChangeListener {
         }
     }
 
-    private Collection<String> addToCurrentCandidates(YangInstanceIdentifier entityId, String newCandidate) {
+    private Collection<String> addToCurrentCandidates(final YangInstanceIdentifier entityId,
+            final String newCandidate) {
         Collection<String> candidates = currentCandidates.computeIfAbsent(entityId, k -> new LinkedHashSet<>());
-
         candidates.add(newCandidate);
         return candidates;
     }
 
-    private Collection<String> removeFromCurrentCandidates(YangInstanceIdentifier entityId, String candidateToRemove) {
+    private Collection<String> removeFromCurrentCandidates(final YangInstanceIdentifier entityId,
+            final String candidateToRemove) {
         Collection<String> candidates = currentCandidates.get(entityId);
         if (candidates != null) {
             candidates.remove(candidateToRemove);
@@ -110,7 +110,7 @@ class CandidateListChangeListener implements DOMDataTreeChangeListener {
         return Collections.emptyList();
     }
 
-    private static YangInstanceIdentifier extractEntityPath(YangInstanceIdentifier candidatePath) {
+    private static YangInstanceIdentifier extractEntityPath(final YangInstanceIdentifier candidatePath) {
         List<PathArgument> newPathArgs = new ArrayList<>();
         for (PathArgument pathArg: candidatePath.getPathArguments()) {
             newPathArgs.add(pathArg);
index bb00f24..4fbd951 100644 (file)
@@ -30,7 +30,6 @@ import akka.cluster.ClusterEvent.CurrentClusterState;
 import akka.cluster.Member;
 import akka.cluster.MemberStatus;
 import akka.pattern.Patterns;
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
@@ -41,6 +40,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import org.opendaylight.controller.cluster.access.concepts.MemberName;
@@ -200,13 +200,13 @@ class EntityOwnershipShard extends Shard {
         getSender().tell(SuccessReply.INSTANCE, getSelf());
 
         searchForEntities((entityTypeNode, entityNode) -> {
-            java.util.Optional<DataContainerChild<?, ?>> possibleType = entityTypeNode.getChild(ENTITY_TYPE_NODE_ID);
+            Optional<DataContainerChild<?, ?>> possibleType = entityTypeNode.getChild(ENTITY_TYPE_NODE_ID);
             String entityType = possibleType.isPresent() ? possibleType.get().getValue().toString() : null;
             if (registerListener.getEntityType().equals(entityType)) {
                 final boolean hasOwner;
                 final boolean isOwner;
 
-                java.util.Optional<DataContainerChild<?, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID);
+                Optional<DataContainerChild<?, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID);
                 if (possibleOwner.isPresent()) {
                     isOwner = localMemberName.getName().equals(possibleOwner.get().getValue().toString());
                     hasOwner = true;
@@ -300,12 +300,12 @@ class EntityOwnershipShard extends Shard {
 
     private void notifyAllListeners() {
         searchForEntities((entityTypeNode, entityNode) -> {
-            java.util.Optional<DataContainerChild<?, ?>> possibleType = entityTypeNode.getChild(ENTITY_TYPE_NODE_ID);
+            Optional<DataContainerChild<?, ?>> possibleType = entityTypeNode.getChild(ENTITY_TYPE_NODE_ID);
             if (possibleType.isPresent()) {
                 final boolean hasOwner;
                 final boolean isOwner;
 
-                java.util.Optional<DataContainerChild<?, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID);
+                Optional<DataContainerChild<?, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID);
                 if (possibleOwner.isPresent()) {
                     isOwner = localMemberName.getName().equals(possibleOwner.get().getValue().toString());
                     hasOwner = true;
@@ -389,7 +389,7 @@ class EntityOwnershipShard extends Shard {
                     .node(entityTypeNode.getIdentifier()).node(ENTITY_NODE_ID).node(entityNode.getIdentifier())
                     .node(ENTITY_OWNER_NODE_ID).build();
 
-            java.util.Optional<String> possibleOwner =
+            Optional<String> possibleOwner =
                     entityNode.getChild(ENTITY_OWNER_NODE_ID).map(node -> node.getValue().toString());
             String newOwner = newOwner(possibleOwner.orElse(null), getCandidateNames(entityNode),
                     getEntityOwnerElectionStrategy(entityPath));
@@ -404,7 +404,7 @@ class EntityOwnershipShard extends Shard {
     }
 
     private void initializeDownPeerMemberNamesFromClusterState() {
-        java.util.Optional<Cluster> cluster = getRaftActorContext().getCluster();
+        Optional<Cluster> cluster = getRaftActorContext().getCluster();
         if (!cluster.isPresent()) {
             return;
         }
@@ -558,7 +558,7 @@ class EntityOwnershipShard extends Shard {
         LOG.debug("{}: Searching for entities owned by {}", persistenceId(), ownedBy);
 
         searchForEntities((entityTypeNode, entityNode) -> {
-            java.util.Optional<DataContainerChild<? extends PathArgument, ?>> possibleOwner =
+            Optional<DataContainerChild<? extends PathArgument, ?>> possibleOwner =
                     entityNode.getChild(ENTITY_OWNER_NODE_ID);
             String currentOwner = possibleOwner.isPresent() ? possibleOwner.get().getValue().toString() : "";
             if (ownedBy.contains(currentOwner)) {
@@ -599,8 +599,8 @@ class EntityOwnershipShard extends Shard {
             return;
         }
 
-        for (MapEntryNode entityType ((MapNode) possibleEntityTypes.get()).getValue()) {
-            java.util.Optional<DataContainerChild<?, ?>> possibleEntities = entityType.getChild(ENTITY_NODE_ID);
+        for (MapEntryNode entityType : ((MapNode) possibleEntityTypes.get()).getValue()) {
+            Optional<DataContainerChild<?, ?>> possibleEntities = entityType.getChild(ENTITY_NODE_ID);
             if (!possibleEntities.isPresent()) {
                 // shouldn't happen but handle anyway
                 continue;
@@ -669,11 +669,9 @@ class EntityOwnershipShard extends Shard {
     }
 
     private String getCurrentOwner(final YangInstanceIdentifier entityId) {
-        Optional<NormalizedNode<?, ?>> optionalEntityOwner = getDataStore().readNode(entityId.node(ENTITY_OWNER_QNAME));
-        if (optionalEntityOwner.isPresent()) {
-            return optionalEntityOwner.get().getValue().toString();
-        }
-        return null;
+        return getDataStore().readNode(entityId.node(ENTITY_OWNER_QNAME))
+                .map(owner -> owner.getValue().toString())
+                .orElse(null);
     }
 
     @FunctionalInterface
index 5ab402c..bad52b3 100644 (file)
@@ -505,7 +505,7 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
                         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..",
@@ -731,7 +731,7 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor {
                         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.",
index aaef33e..f425167 100644 (file)
@@ -291,7 +291,7 @@ public abstract class AbstractShardTest extends AbstractActorTest {
 
     public static NormalizedNode<?,?> readStore(final TestActorRef<? extends Shard> shard,
             final YangInstanceIdentifier id) {
-        return shard.underlyingActor().getDataStore().readNode(id).orNull();
+        return shard.underlyingActor().getDataStore().readNode(id).orElse(null);
     }
 
     public static NormalizedNode<?,?> readStore(final DataTree store, final YangInstanceIdentifier id) {
index ce02d6c..11462b2 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;
 
 import static org.junit.Assert.assertEquals;
@@ -24,12 +23,12 @@ import akka.actor.Address;
 import akka.actor.AddressFromURIString;
 import akka.cluster.Cluster;
 import akka.testkit.javadsl.TestKit;
-import com.google.common.base.Optional;
 import com.google.common.base.Throwables;
 import com.google.common.util.concurrent.FluentFuture;
 import com.typesafe.config.ConfigFactory;
 import java.math.BigInteger;
 import java.util.Collection;
+import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import org.junit.AfterClass;
@@ -113,7 +112,7 @@ public class DataTreeCohortIntegrationTest {
             kit.testWriteTransaction(dataStore, TestModel.TEST_PATH, node);
             verify(cohort).canCommit(any(Object.class), any(SchemaContext.class), candidateCapt.capture());
             assertDataTreeCandidate((DOMDataTreeCandidate) candidateCapt.getValue().iterator().next(), TEST_ID,
-                    ModificationType.WRITE, Optional.of(node), Optional.absent());
+                    ModificationType.WRITE, Optional.of(node), Optional.empty());
 
             reset(cohort);
             doReturn(PostCanCommitStep.NOOP_SUCCESSFUL_FUTURE).when(cohort).canCommit(any(Object.class),
@@ -201,7 +200,7 @@ public class DataTreeCohortIntegrationTest {
             verify(cohort).canCommit(any(Object.class), any(SchemaContext.class), candidateCapture.capture());
             assertDataTreeCandidate((DOMDataTreeCandidate) candidateCapture.getValue().iterator().next(),
                     new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, optimaPath), ModificationType.WRITE,
-                    Optional.of(optimaNode), Optional.absent());
+                    Optional.of(optimaNode), Optional.empty());
 
             // Write replace the cars container with 2 new car entries. The cohort should get invoked with 3
             // DOMDataTreeCandidates: once for each of the 2 new car entries (WRITE mod) and once for the deleted prior
@@ -224,15 +223,15 @@ public class DataTreeCohortIntegrationTest {
 
             assertDataTreeCandidate(findCandidate(candidateCapture, sportagePath), new DOMDataTreeIdentifier(
                     LogicalDatastoreType.CONFIGURATION, sportagePath), ModificationType.WRITE,
-                    Optional.of(sportageNode), Optional.absent());
+                    Optional.of(sportageNode), Optional.empty());
 
             assertDataTreeCandidate(findCandidate(candidateCapture, soulPath), new DOMDataTreeIdentifier(
                     LogicalDatastoreType.CONFIGURATION, soulPath), ModificationType.WRITE,
-                    Optional.of(soulNode), Optional.absent());
+                    Optional.of(soulNode), Optional.empty());
 
             assertDataTreeCandidate(findCandidate(candidateCapture, optimaPath), new DOMDataTreeIdentifier(
                     LogicalDatastoreType.CONFIGURATION, optimaPath), ModificationType.DELETE,
-                    Optional.absent(), Optional.of(optimaNode));
+                    Optional.empty(), Optional.of(optimaNode));
 
             // Delete the cars container - cohort should be invoked for the 2 deleted car entries.
 
@@ -249,11 +248,11 @@ public class DataTreeCohortIntegrationTest {
 
             assertDataTreeCandidate(findCandidate(candidateCapture, sportagePath), new DOMDataTreeIdentifier(
                     LogicalDatastoreType.CONFIGURATION, sportagePath), ModificationType.DELETE,
-                    Optional.absent(), Optional.of(sportageNode));
+                    Optional.empty(), Optional.of(sportageNode));
 
             assertDataTreeCandidate(findCandidate(candidateCapture, soulPath), new DOMDataTreeIdentifier(
                     LogicalDatastoreType.CONFIGURATION, soulPath), ModificationType.DELETE,
-                    Optional.absent(), Optional.of(soulNode));
+                    Optional.empty(), Optional.of(soulNode));
 
         }
     }
index 3364fc3..9d920b5 100644 (file)
@@ -14,8 +14,8 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
 import akka.actor.ActorSelection;
-import com.google.common.base.Optional;
 import com.google.common.util.concurrent.SettableFuture;
+import java.util.Optional;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -112,11 +112,10 @@ public class LocalTransactionContextTest {
     @Test
     public void testReady() {
         final LocalThreePhaseCommitCohort mockCohort = mock(LocalThreePhaseCommitCohort.class);
-        doReturn(akka.dispatch.Futures.successful(null)).when(mockCohort).initiateCoordinatedCommit(
-                java.util.Optional.empty());
+        doReturn(akka.dispatch.Futures.successful(null)).when(mockCohort).initiateCoordinatedCommit(Optional.empty());
         doReturn(mockCohort).when(mockReadySupport).onTransactionReady(readWriteTransaction, null);
 
-        Future<ActorSelection> future = localTransactionContext.readyTransaction(null, java.util.Optional.empty());
+        Future<ActorSelection> future = localTransactionContext.readyTransaction(null, Optional.empty());
         assertTrue(future.isCompleted());
 
         verify(mockReadySupport).onTransactionReady(readWriteTransaction, null);
@@ -172,10 +171,9 @@ public class LocalTransactionContextTest {
 
     private void doReadyWithExpectedError(final RuntimeException expError) {
         LocalThreePhaseCommitCohort mockCohort = mock(LocalThreePhaseCommitCohort.class);
-        doReturn(akka.dispatch.Futures.successful(null)).when(mockCohort).initiateCoordinatedCommit(
-                java.util.Optional.empty());
+        doReturn(akka.dispatch.Futures.successful(null)).when(mockCohort).initiateCoordinatedCommit(Optional.empty());
         doReturn(mockCohort).when(mockReadySupport).onTransactionReady(readWriteTransaction, expError);
 
-        localTransactionContext.readyTransaction(null, java.util.Optional.empty());
+        localTransactionContext.readyTransaction(null, Optional.empty());
     }
 }
index 814f907..35cb8ed 100644 (file)
@@ -176,7 +176,7 @@ public class ShardDataTreeTest extends AbstractTest {
 
         DOMDataTreeChangeListener listener = mock(DOMDataTreeChangeListener.class);
         shardDataTree.registerTreeChangeListener(CarsModel.CAR_LIST_PATH.node(CarsModel.CAR_QNAME), listener,
-            com.google.common.base.Optional.absent(), noop -> { });
+            Optional.empty(), noop -> { });
 
         addCar(shardDataTree, "optima");
 
index 39285f9..142af6f 100644 (file)
@@ -5,15 +5,14 @@
  * 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;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import com.google.common.base.Optional;
 import java.io.IOException;
+import java.util.Optional;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;

©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.