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;
38 private final int maxMessages;
40 ConnectClientSuccess(final ClientIdentifier target, final long sequence, final ActorRef backend,
41 final List<ActorSelection> alternates, final Optional<DataTree> dataTree, final int maxMessages) {
42 super(target, sequence);
43 this.backend = Preconditions.checkNotNull(backend);
44 this.alternates = ImmutableList.copyOf(alternates);
45 this.dataTree = dataTree.orElse(null);
46 Preconditions.checkArgument(maxMessages > 0, "Maximum messages has to be positive, not %s", maxMessages);
47 this.maxMessages = maxMessages;
50 public ConnectClientSuccess(@Nonnull final ClientIdentifier target, final long sequence,
51 @Nonnull final ActorRef backend, @Nonnull final List<ActorSelection> alternates,
52 @Nonnull final DataTree dataTree, final int maxMessages) {
53 this(target, sequence, backend, alternates, Optional.of(dataTree), maxMessages);
57 * Return the list of known alternate backends. The client can use this list to perform recovery procedures.
59 * @return a list of known backend alternates
62 public List<ActorSelection> getAlternates() {
67 public ActorRef getBackend() {
71 public Optional<DataTree> getDataTree() {
72 return Optional.ofNullable(dataTree);
75 public int getMaxMessages() {
80 protected ConnectClientSuccessProxyV1 externalizableProxy(final ABIVersion version) {
81 return new ConnectClientSuccessProxyV1(this);
85 protected ConnectClientSuccess cloneAsVersion(final ABIVersion version) {
90 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
91 return super.addToStringAttributes(toStringHelper).add("alternates", alternates).add("dataTree", dataTree)
92 .add("maxMessages", maxMessages);