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