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 java.util.List;
17 import java.util.Optional;
18 import javax.annotation.Nonnull;
19 import org.opendaylight.controller.cluster.access.ABIVersion;
20 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
21 import org.opendaylight.controller.cluster.access.concepts.RequestSuccess;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
25 * Successful reply to an {@link ConnectClientRequest}. Client actor which initiated this connection should use
26 * the version reported via {@link #getVersion()} of this message to communicate with this backend. Should this backend
27 * fail, the client can try accessing the provided alternates.
29 * @author Robert Varga
32 public final class ConnectClientSuccess extends RequestSuccess<ClientIdentifier, ConnectClientSuccess> {
33 private static final long serialVersionUID = 1L;
35 private final List<ActorSelection> alternates;
36 private final DataTree dataTree;
37 private final ActorRef backend;
39 ConnectClientSuccess(final ClientIdentifier target, final ActorRef backend, final List<ActorSelection> alternates,
40 final Optional<DataTree> dataTree) {
42 this.backend = Preconditions.checkNotNull(backend);
43 this.alternates = ImmutableList.copyOf(alternates);
44 this.dataTree = dataTree.orElse(null);
47 public ConnectClientSuccess(final @Nonnull ClientIdentifier target, final @Nonnull ActorRef backend,
48 final @Nonnull List<ActorSelection> alternates,
49 final @Nonnull DataTree dataTree) {
50 this(target, backend, alternates, Optional.of(dataTree));
54 * Return the list of known alternate backends. The client can use this list to perform recovery procedures.
56 * @return a list of known backend alternates
58 public @Nonnull List<ActorSelection> getAlternates() {
62 public @Nonnull ActorRef getBackend() {
66 public Optional<DataTree> getDataTree() {
67 return Optional.ofNullable(dataTree);
71 protected ConnectClientSuccessProxyV1 externalizableProxy(final ABIVersion version) {
72 return new ConnectClientSuccessProxyV1(this);
76 protected ConnectClientSuccess cloneAsVersion(final ABIVersion version) {
81 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
82 return super.addToStringAttributes(toStringHelper).add("alternates", alternates).add("dataTree", dataTree);