12534e037def93dbcd50a40655c3904eb076dc86
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / ConnectClientRequest.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 static java.util.Objects.requireNonNull;
11
12 import akka.actor.ActorRef;
13 import com.google.common.base.MoreObjects.ToStringHelper;
14 import java.io.Serial;
15 import org.opendaylight.controller.cluster.access.ABIVersion;
16 import org.opendaylight.controller.cluster.access.concepts.AbstractRequestProxy;
17 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.Request;
19 import org.opendaylight.controller.cluster.access.concepts.RequestException;
20
21 /**
22  * Request to connect a frontend instance to the backend. It carries basic information about the frontend:
23  * - its coordinates in {@link #getReplyTo()}.
24  * - its minimum supported ABI version
25  * - its maximum supported ABI version
26  *
27  * <p>
28  * It also includes request stream sequencing information.
29  */
30 public final class ConnectClientRequest extends Request<ClientIdentifier, ConnectClientRequest> {
31     @Serial
32     private static final long serialVersionUID = 1L;
33
34     private final ABIVersion minVersion;
35     private final ABIVersion maxVersion;
36
37     ConnectClientRequest(final ClientIdentifier identifier, final long txSequence, final ActorRef replyTo,
38             final ABIVersion minVersion, final ABIVersion maxVersion) {
39         super(identifier, txSequence, replyTo);
40         this.minVersion = requireNonNull(minVersion);
41         this.maxVersion = requireNonNull(maxVersion);
42     }
43
44     public ConnectClientRequest(final ClientIdentifier identifier, final ActorRef replyTo, final ABIVersion minVersion,
45             final ABIVersion maxVersion) {
46         this(identifier, 0, replyTo, minVersion, maxVersion);
47     }
48
49     private ConnectClientRequest(final ConnectClientRequest request, final ABIVersion version) {
50         super(request, version);
51         minVersion = request.minVersion;
52         maxVersion = request.maxVersion;
53     }
54
55     public ABIVersion getMinVersion() {
56         return minVersion;
57     }
58
59     public ABIVersion getMaxVersion() {
60         return maxVersion;
61     }
62
63     @Override
64     public ConnectClientFailure toRequestFailure(final RequestException cause) {
65         return new ConnectClientFailure(getTarget(), getSequence(), cause);
66     }
67
68     @Override
69     protected AbstractRequestProxy<ClientIdentifier, ConnectClientRequest> externalizableProxy(
70             final ABIVersion version) {
71         return new ConnectClientRequestProxyV1(this);
72     }
73
74     @Override
75     protected ConnectClientRequest cloneAsVersion(final ABIVersion version) {
76         return new ConnectClientRequest(this, version);
77     }
78
79     @Override
80     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
81         return super.addToStringAttributes(toStringHelper).add("minVersion", minVersion).add("maxVersion", maxVersion);
82     }
83 }