Bug 8424: Don't output data tree and tree candidates wih debug
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / ConnectClientSuccess.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.access.commands;
9
10 import akka.actor.ActorRef;
11 import akka.actor.ActorSelection;
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects.ToStringHelper;
14 import com.google.common.base.Preconditions;
15 import com.google.common.collect.ImmutableList;
16 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
17 import java.util.List;
18 import java.util.Optional;
19 import javax.annotation.Nonnull;
20 import org.opendaylight.controller.cluster.access.ABIVersion;
21 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
22 import org.opendaylight.controller.cluster.access.concepts.RequestSuccess;
23 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
24
25 /**
26  * Successful reply to an {@link ConnectClientRequest}. Client actor which initiated this connection should use
27  * the version reported via {@link #getVersion()} of this message to communicate with this backend. Should this backend
28  * fail, the client can try accessing the provided alternates.
29  *
30  * @author Robert Varga
31  */
32 @Beta
33 public final class ConnectClientSuccess extends RequestSuccess<ClientIdentifier, ConnectClientSuccess> {
34     private static final long serialVersionUID = 1L;
35
36     @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class "
37             + "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class "
38             + "aren't serialized. FindBugs does not recognize this.")
39     private final List<ActorSelection> alternates;
40
41     @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "See justification above.")
42     private final DataTree dataTree;
43     private final ActorRef backend;
44     private final int maxMessages;
45
46     ConnectClientSuccess(final ClientIdentifier target, final long sequence, final ActorRef backend,
47         final List<ActorSelection> alternates, final Optional<DataTree> dataTree, final int maxMessages) {
48         super(target, sequence);
49         this.backend = Preconditions.checkNotNull(backend);
50         this.alternates = ImmutableList.copyOf(alternates);
51         this.dataTree = dataTree.orElse(null);
52         Preconditions.checkArgument(maxMessages > 0, "Maximum messages has to be positive, not %s", maxMessages);
53         this.maxMessages = maxMessages;
54     }
55
56     public ConnectClientSuccess(@Nonnull final ClientIdentifier target, final long sequence,
57             @Nonnull final ActorRef backend, @Nonnull final List<ActorSelection> alternates,
58             @Nonnull final DataTree dataTree, final int maxMessages) {
59         this(target, sequence, backend, alternates, Optional.of(dataTree), maxMessages);
60     }
61
62     /**
63      * Return the list of known alternate backends. The client can use this list to perform recovery procedures.
64      *
65      * @return a list of known backend alternates
66      */
67     @Nonnull
68     public List<ActorSelection> getAlternates() {
69         return alternates;
70     }
71
72     @Nonnull
73     public ActorRef getBackend() {
74         return backend;
75     }
76
77     public Optional<DataTree> getDataTree() {
78         return Optional.ofNullable(dataTree);
79     }
80
81     public int getMaxMessages() {
82         return maxMessages;
83     }
84
85     @Override
86     protected ConnectClientSuccessProxyV1 externalizableProxy(final ABIVersion version) {
87         return new ConnectClientSuccessProxyV1(this);
88     }
89
90     @Override
91     protected ConnectClientSuccess cloneAsVersion(final ABIVersion version) {
92         return this;
93     }
94
95     @Override
96     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
97         return super.addToStringAttributes(toStringHelper).add("alternates", alternates)
98                 .add("dataTree present", getDataTree().isPresent()).add("maxMessages", maxMessages);
99     }
100 }

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