/* * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.cluster.access.commands; 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 java.util.List; import java.util.Optional; import javax.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; /** * Successful reply to an {@link ConnectClientRequest}. Client actor which initiated this connection should use * the version reported via {@link #getVersion()} of this message to communicate with this backend. Should this backend * fail, the client can try accessing the provided alternates. * * @author Robert Varga */ @Beta public final class ConnectClientSuccess extends RequestSuccess { private static final long serialVersionUID = 1L; private final List alternates; private final DataTree dataTree; private final ActorRef backend; private final int maxMessages; ConnectClientSuccess(final ClientIdentifier target, final long sequence, final ActorRef backend, final List alternates, final Optional dataTree, final int maxMessages) { super(target, sequence); this.backend = Preconditions.checkNotNull(backend); this.alternates = ImmutableList.copyOf(alternates); this.dataTree = dataTree.orElse(null); Preconditions.checkArgument(maxMessages > 0, "Maximum messages has to be positive, not %s", maxMessages); this.maxMessages = maxMessages; } public ConnectClientSuccess(final @Nonnull ClientIdentifier target, final long sequence, final @Nonnull ActorRef backend, final @Nonnull List alternates, final @Nonnull DataTree dataTree, final int maxMessages) { this(target, sequence, backend, alternates, Optional.of(dataTree), maxMessages); } /** * Return the list of known alternate backends. The client can use this list to perform recovery procedures. * * @return a list of known backend alternates */ public @Nonnull List getAlternates() { return alternates; } public @Nonnull ActorRef getBackend() { return backend; } public Optional getDataTree() { return Optional.ofNullable(dataTree); } public int getMaxMessages() { return maxMessages; } @Override protected ConnectClientSuccessProxyV1 externalizableProxy(final ABIVersion version) { return new ConnectClientSuccessProxyV1(this); } @Override protected ConnectClientSuccess cloneAsVersion(final ABIVersion version) { return this; } @Override protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { return super.addToStringAttributes(toStringHelper).add("alternates", alternates).add("dataTree", dataTree) .add("maxMessages", maxMessages); } }