2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.access.commands;
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;
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.
30 * @author Robert Varga
33 public final class ConnectClientSuccess extends RequestSuccess<ClientIdentifier, ConnectClientSuccess> {
34 private static final long serialVersionUID = 1L;
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;
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;
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;
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);
63 * Return the list of known alternate backends. The client can use this list to perform recovery procedures.
65 * @return a list of known backend alternates
68 public List<ActorSelection> getAlternates() {
73 public ActorRef getBackend() {
77 public Optional<DataTree> getDataTree() {
78 return Optional.ofNullable(dataTree);
81 public int getMaxMessages() {
86 protected ConnectClientSuccessProxyV1 externalizableProxy(final ABIVersion version) {
87 return new ConnectClientSuccessProxyV1(this);
91 protected ConnectClientSuccess cloneAsVersion(final ABIVersion version) {
96 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
97 return super.addToStringAttributes(toStringHelper).add("alternates", alternates)
98 .add("dataTree present", getDataTree().isPresent()).add("maxMessages", maxMessages);