Do not leak DataTree from backend actor
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / PrimaryShardInfo.java
index bbeb1aa84bbe728ffe073e9a3cc5402161fde676..1ca06216dd1157a54727ae67c8c8124d2fc0bafa 100644 (file)
@@ -7,11 +7,12 @@
  */
 package org.opendaylight.controller.cluster.datastore.messages;
 
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.ActorSelection;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.ReadOnlyDataTree;
 
 /**
  * Local message DTO that contains information about the primary shard.
@@ -20,25 +21,41 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
  */
 public class PrimaryShardInfo {
     private final ActorSelection primaryShardActor;
-    private final Optional<DataTree> localShardDataTree;
+    private final short primaryShardVersion;
+    private final ReadOnlyDataTree localShardDataTree;
+
+    public PrimaryShardInfo(@NonNull ActorSelection primaryShardActor, short primaryShardVersion,
+            @NonNull ReadOnlyDataTree localShardDataTree) {
+        this.primaryShardActor = requireNonNull(primaryShardActor);
+        this.primaryShardVersion = primaryShardVersion;
+        this.localShardDataTree = requireNonNull(localShardDataTree);
+    }
 
-    public PrimaryShardInfo(@Nonnull ActorSelection primaryShardActor, @Nonnull Optional<DataTree> localShardDataTree) {
-        this.primaryShardActor = Preconditions.checkNotNull(primaryShardActor);
-        this.localShardDataTree = Preconditions.checkNotNull(localShardDataTree);
+    public PrimaryShardInfo(@NonNull ActorSelection primaryShardActor, short primaryShardVersion) {
+        this.primaryShardActor = requireNonNull(primaryShardActor);
+        this.primaryShardVersion = primaryShardVersion;
+        this.localShardDataTree = null;
     }
 
     /**
      * Returns an ActorSelection representing the primary shard actor.
      */
-    public @Nonnull ActorSelection getPrimaryShardActor() {
+    public @NonNull ActorSelection getPrimaryShardActor() {
         return primaryShardActor;
     }
 
+    /**
+     * Returns the version of the primary shard.
+     */
+    public short getPrimaryShardVersion() {
+        return primaryShardVersion;
+    }
+
     /**
      * Returns an Optional whose value contains the primary shard's DataTree if the primary shard is local
      * to the caller. Otherwise the Optional value is absent.
      */
-    public @Nonnull Optional<DataTree> getLocalShardDataTree() {
-        return localShardDataTree;
+    public @NonNull Optional<ReadOnlyDataTree> getLocalShardDataTree() {
+        return Optional.ofNullable(localShardDataTree);
     }
 }