Fix checkstyle problems not detected by the current version
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / AbstractReadTransactionRequest.java
1 /*
2  * Copyright (c) 2016, 2017 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.TransactionIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18
19 /**
20  * Abstract base class for {@link TransactionRequest}s accessing data as visible in the isolated context of a particular
21  * transaction. The path of the data being accessed is returned via {@link #getPath()}.
22  *
23  * <p>
24  * This class is visible outside of this package for the purpose of allowing common instanceof checks
25  * and simplified codepaths.
26  *
27  * @author Robert Varga
28  *
29  * @param <T> Message type
30  */
31 @Beta
32 public abstract class AbstractReadTransactionRequest<T extends AbstractReadTransactionRequest<T>>
33         extends TransactionRequest<T> {
34     private static final long serialVersionUID = 1L;
35     private final YangInstanceIdentifier path;
36     private final boolean snapshotOnly;
37
38     AbstractReadTransactionRequest(final TransactionIdentifier identifier, final long sequence, final ActorRef replyTo,
39         final YangInstanceIdentifier path, final boolean snapshotOnly) {
40         super(identifier, sequence, replyTo);
41         this.path = Preconditions.checkNotNull(path);
42         this.snapshotOnly = snapshotOnly;
43     }
44
45     AbstractReadTransactionRequest(final T request, final ABIVersion version) {
46         super(request, version);
47         this.path = request.getPath();
48         this.snapshotOnly = request.isSnapshotOnly();
49     }
50
51     @Nonnull
52     public final YangInstanceIdentifier getPath() {
53         return path;
54     }
55
56     public final boolean isSnapshotOnly() {
57         return snapshotOnly;
58     }
59
60     @Override
61     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
62         return super.addToStringAttributes(toStringHelper).add("path", path);
63     }
64
65     @Override
66     protected abstract AbstractReadTransactionRequestProxyV1<T> externalizableProxy(ABIVersion version);
67 }