Add new cds-access-api proxies
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / ExistsTransactionSuccess.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 com.google.common.base.MoreObjects.ToStringHelper;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.access.ABIVersion;
15 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
16
17 /**
18  * Successful reply to an {@link ExistsTransactionRequest}. It indicates presence of requested data via
19  * {@link #getExists()}.
20  */
21 public final class ExistsTransactionSuccess extends TransactionSuccess<ExistsTransactionSuccess> {
22     interface SerialForm extends TransactionSuccess.SerialForm<ExistsTransactionSuccess> {
23         @Override
24         default ExistsTransactionSuccess readExternal(final ObjectInput in, final TransactionIdentifier target,
25                 final long sequence) throws IOException {
26             return new ExistsTransactionSuccess(target, sequence, in.readBoolean());
27         }
28
29         @Override
30         default void writeExternal(final ObjectOutput out, final ExistsTransactionSuccess msg) throws IOException {
31             out.writeBoolean(msg.getExists());
32         }
33     }
34
35     @java.io.Serial
36     private static final long serialVersionUID = 1L;
37
38     private final boolean exists;
39
40     private ExistsTransactionSuccess(final ExistsTransactionSuccess success, final ABIVersion version) {
41         super(success, version);
42         exists = success.exists;
43     }
44
45     public ExistsTransactionSuccess(final TransactionIdentifier target, final long sequence, final boolean exists) {
46         super(target, sequence);
47         this.exists = exists;
48     }
49
50     public boolean getExists() {
51         return exists;
52     }
53
54     @Override
55     protected SerialForm externalizableProxy(final ABIVersion version) {
56         return ABIVersion.MAGNESIUM.lt(version) ? new ETS(this) : new ExistsTransactionSuccessProxyV1(this);
57     }
58
59     @Override
60     protected ExistsTransactionSuccess cloneAsVersion(final ABIVersion version) {
61         return new ExistsTransactionSuccess(this, version);
62     }
63
64     @Override
65     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
66         return super.addToStringAttributes(toStringHelper).add("exists", exists);
67     }
68 }