4800cea5e2a292db468103c1585ad7353185e2e2
[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 akka.actor.ActorRef;
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import com.google.common.base.Preconditions;
14 import javax.annotation.Nonnull;
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  * It also includes request stream sequencing information.
28  *
29  * @author Robert Varga
30  */
31 @Beta
32 public final class ConnectClientRequest extends Request<ClientIdentifier, ConnectClientRequest> {
33     private static final long serialVersionUID = 1L;
34
35     private final ABIVersion minVersion;
36     private final ABIVersion maxVersion;
37     private final long resumeSequence;
38
39     public ConnectClientRequest(final ClientIdentifier identifier, final ActorRef replyTo, final ABIVersion minVersion,
40             final ABIVersion maxVersion) {
41         this(identifier, replyTo, minVersion, maxVersion, 0);
42     }
43
44     public ConnectClientRequest(final ClientIdentifier identifier, final ActorRef replyTo, final ABIVersion minVersion,
45             final ABIVersion maxVersion, final long resumeSequence) {
46         super(identifier, replyTo);
47         this.minVersion = Preconditions.checkNotNull(minVersion);
48         this.maxVersion = Preconditions.checkNotNull(maxVersion);
49         this.resumeSequence = resumeSequence;
50     }
51
52     private ConnectClientRequest(final ConnectClientRequest request, final ABIVersion version) {
53         super(request, version);
54         this.minVersion = request.minVersion;
55         this.maxVersion = request.maxVersion;
56         this.resumeSequence = request.resumeSequence;
57     }
58
59     public ABIVersion getMinVersion() {
60         return minVersion;
61     }
62
63     public ABIVersion getMaxVersion() {
64         return maxVersion;
65     }
66
67     public long getResumeSequence() {
68         return resumeSequence;
69     }
70
71     @Override
72     public final ConnectClientFailure toRequestFailure(final RequestException cause) {
73         return new ConnectClientFailure(getTarget(), cause);
74     }
75
76     @Override
77     protected AbstractRequestProxy<ClientIdentifier, ConnectClientRequest> externalizableProxy(final ABIVersion version) {
78         return new ConnectClientRequestProxyV1(this);
79     }
80
81     @Override
82     protected ConnectClientRequest cloneAsVersion(final ABIVersion version) {
83         return new ConnectClientRequest(this, version);
84     }
85
86     @Override
87     protected @Nonnull ToStringHelper addToStringAttributes(final @Nonnull ToStringHelper toStringHelper) {
88         return super.addToStringAttributes(toStringHelper).add("minVersion", minVersion).add("maxVersion", maxVersion)
89                 .add("resumeSequence", resumeSequence);
90     }
91 }