Bump upstream SNAPSHOTS
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / ConnectClientSuccess.java
index c2302598e339b03101767603f94d81059759d060..8f16d61e349433a158db6065ebfad351536e0e87 100644 (file)
@@ -7,19 +7,22 @@
  */
 package org.opendaylight.controller.cluster.access.commands;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.ActorRef;
 import akka.actor.ActorSelection;
 import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.List;
 import java.util.Optional;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.controller.cluster.access.ABIVersion;
 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.RequestSuccess;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
+import org.opendaylight.yangtools.yang.data.tree.api.ReadOnlyDataTree;
 
 /**
  * Successful reply to an {@link ConnectClientRequest}. Client actor which initiated this connection should use
@@ -32,22 +35,30 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 public final class ConnectClientSuccess extends RequestSuccess<ClientIdentifier, ConnectClientSuccess> {
     private static final long serialVersionUID = 1L;
 
-    private final List<ActorSelection> alternates;
-    private final DataTree dataTree;
-    private final ActorRef backend;
+    @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class "
+            + "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class "
+            + "aren't serialized. FindBugs does not recognize this.")
+    private final @NonNull List<ActorSelection> alternates;
+
+    @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "See justification above.")
+    private final ReadOnlyDataTree dataTree;
+    private final @NonNull ActorRef backend;
+    private final int maxMessages;
 
-    ConnectClientSuccess(final ClientIdentifier target, final ActorRef backend, final List<ActorSelection> alternates,
-        final Optional<DataTree> dataTree) {
-        super(target);
-        this.backend = Preconditions.checkNotNull(backend);
+    ConnectClientSuccess(final ClientIdentifier target, final long sequence, final ActorRef backend,
+        final List<ActorSelection> alternates, final int maxMessages, final ReadOnlyDataTree dataTree) {
+        super(target, sequence);
+        this.backend = requireNonNull(backend);
         this.alternates = ImmutableList.copyOf(alternates);
-        this.dataTree = dataTree.orElse(null);
+        this.dataTree = dataTree;
+        checkArgument(maxMessages > 0, "Maximum messages has to be positive, not %s", maxMessages);
+        this.maxMessages = maxMessages;
     }
 
-    public ConnectClientSuccess(final @Nonnull ClientIdentifier target, final @Nonnull ActorRef backend,
-            final @Nonnull List<ActorSelection> alternates,
-            final @Nonnull DataTree dataTree) {
-        this(target, backend, alternates, Optional.of(dataTree));
+    public ConnectClientSuccess(final @NonNull ClientIdentifier target, final long sequence,
+            final @NonNull ActorRef backend, final @NonNull List<ActorSelection> alternates,
+            final @NonNull ReadOnlyDataTree dataTree, final int maxMessages) {
+        this(target, sequence, backend, alternates, maxMessages, requireNonNull(dataTree));
     }
 
     /**
@@ -55,18 +66,22 @@ public final class ConnectClientSuccess extends RequestSuccess<ClientIdentifier,
      *
      * @return a list of known backend alternates
      */
-    public @Nonnull List<ActorSelection> getAlternates() {
+    public @NonNull List<ActorSelection> getAlternates() {
         return alternates;
     }
 
-    public @Nonnull ActorRef getBackend() {
+    public @NonNull ActorRef getBackend() {
         return backend;
     }
 
-    public Optional<DataTree> getDataTree() {
+    public Optional<ReadOnlyDataTree> getDataTree() {
         return Optional.ofNullable(dataTree);
     }
 
+    public int getMaxMessages() {
+        return maxMessages;
+    }
+
     @Override
     protected ConnectClientSuccessProxyV1 externalizableProxy(final ABIVersion version) {
         return new ConnectClientSuccessProxyV1(this);
@@ -79,6 +94,7 @@ public final class ConnectClientSuccess extends RequestSuccess<ClientIdentifier,
 
     @Override
     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-        return super.addToStringAttributes(toStringHelper).add("alternates", alternates).add("dataTree", dataTree);
+        return super.addToStringAttributes(toStringHelper).add("alternates", alternates)
+                .add("dataTree present", getDataTree().isPresent()).add("maxMessages", maxMessages);
     }
 }