BUG-5280: introduce base Transaction request/success
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / ReadTransactionSuccess.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.annotations.Beta;
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.controller.cluster.access.ABIVersion;
14 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16
17 /**
18  * Successful reply to an {@link ReadTransactionRequest}. It indicates presence of requested data via {@link #getData()}.
19  *
20  * @author Robert Varga
21  */
22 @Beta
23 public final class ReadTransactionSuccess extends TransactionSuccess<ReadTransactionSuccess> {
24     private static final long serialVersionUID = 1L;
25     private final Optional<NormalizedNode<?, ?>> data;
26
27     public ReadTransactionSuccess(final TransactionIdentifier identifier, final long sequence,
28             final Optional<NormalizedNode<?, ?>> data) {
29         this(identifier, sequence, 0, data);
30     }
31
32     ReadTransactionSuccess(final TransactionIdentifier identifier, final long sequence, final long retry,
33             final Optional<NormalizedNode<?, ?>> data) {
34         super(identifier, sequence, retry);
35         this.data = Preconditions.checkNotNull(data);
36     }
37
38     public Optional<NormalizedNode<?, ?>> getData() {
39         return data;
40     }
41
42     @Override
43     protected AbstractTransactionSuccessProxy<ReadTransactionSuccess> externalizableProxy(final ABIVersion version) {
44         return new ReadTransactionSuccessProxyV1(this);
45     }
46
47     @Override
48     protected ReadTransactionSuccess cloneAsVersion(final ABIVersion version) {
49         return this;
50     }
51 }