2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.access.commands;
10 import static java.util.Objects.requireNonNull;
12 import akka.actor.ActorRef;
13 import com.google.common.base.MoreObjects.ToStringHelper;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.controller.cluster.access.ABIVersion;
19 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput;
24 * Abstract base class for {@link TransactionRequest}s accessing data as visible in the isolated context of a particular
25 * transaction. The path of the data being accessed is returned via {@link #getPath()}.
27 * <p>This class is visible outside of this package for the purpose of allowing common instanceof checks and simplified
30 * @param <T> Message type
32 public abstract class AbstractReadPathTransactionRequest<T extends AbstractReadPathTransactionRequest<T>>
33 extends AbstractReadTransactionRequest<T> {
34 interface SerialForm<T extends AbstractReadPathTransactionRequest<T>>
35 extends AbstractReadTransactionRequest.SerialForm<T> {
38 default T readExternal(final ObjectInput in, final TransactionIdentifier target, final long sequence,
39 final ActorRef replyTo, final boolean snapshotOnly) throws IOException {
40 return readExternal(in, target, sequence, replyTo, snapshotOnly,
41 NormalizedNodeDataInput.newDataInput(in).readYangInstanceIdentifier());
44 @NonNull T readExternal(@NonNull ObjectInput in, @NonNull TransactionIdentifier target, long sequence,
45 @NonNull ActorRef replyTo, boolean snapshotOnly, @NonNull YangInstanceIdentifier path) throws IOException;
48 default void writeExternal(final ObjectOutput out, final T msg) throws IOException {
49 AbstractReadTransactionRequest.SerialForm.super.writeExternal(out, msg);
50 try (var nnout = msg.getVersion().getStreamVersion().newDataOutput(out)) {
51 nnout.writeYangInstanceIdentifier(msg.getPath());
57 private static final long serialVersionUID = 1L;
59 private final @NonNull YangInstanceIdentifier path;
61 AbstractReadPathTransactionRequest(final TransactionIdentifier identifier, final long sequence,
62 final ActorRef replyTo, final YangInstanceIdentifier path, final boolean snapshotOnly) {
63 super(identifier, sequence, replyTo, snapshotOnly);
64 this.path = requireNonNull(path);
67 AbstractReadPathTransactionRequest(final T request, final ABIVersion version) {
68 super(request, version);
69 this.path = request.getPath();
72 public final @NonNull YangInstanceIdentifier getPath() {
77 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
78 return super.addToStringAttributes(toStringHelper).add("path", path);
82 protected abstract SerialForm<T> externalizableProxy(ABIVersion version);