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()}.
28 * This class is visible outside of this package for the purpose of allowing common instanceof checks
29 * and simplified codepaths.
31 * @param <T> Message type
33 public abstract class AbstractReadPathTransactionRequest<T extends AbstractReadPathTransactionRequest<T>>
34 extends AbstractReadTransactionRequest<T> {
35 interface SerialForm<T extends AbstractReadPathTransactionRequest<T>>
36 extends AbstractReadTransactionRequest.SerialForm<T> {
39 default T readExternal(final ObjectInput in, final TransactionIdentifier target, final long sequence,
40 final ActorRef replyTo, final boolean snapshotOnly) throws IOException {
41 return readExternal(in, target, sequence, replyTo, snapshotOnly,
42 NormalizedNodeDataInput.newDataInput(in).readYangInstanceIdentifier());
45 @NonNull T readExternal(@NonNull ObjectInput in, @NonNull TransactionIdentifier target, long sequence,
46 @NonNull ActorRef replyTo, boolean snapshotOnly, @NonNull YangInstanceIdentifier path) throws IOException;
49 default void writeExternal(final ObjectOutput out, final T msg) throws IOException {
50 AbstractReadTransactionRequest.SerialForm.super.writeExternal(out, msg);
51 try (var nnout = msg.getVersion().getStreamVersion().newDataOutput(out)) {
52 nnout.writeYangInstanceIdentifier(msg.getPath());
58 private static final long serialVersionUID = 1L;
60 private final @NonNull YangInstanceIdentifier path;
62 AbstractReadPathTransactionRequest(final TransactionIdentifier identifier, final long sequence,
63 final ActorRef replyTo, final YangInstanceIdentifier path, final boolean snapshotOnly) {
64 super(identifier, sequence, replyTo, snapshotOnly);
65 this.path = requireNonNull(path);
68 AbstractReadPathTransactionRequest(final T request, final ABIVersion version) {
69 super(request, version);
70 this.path = request.getPath();
73 public final @NonNull YangInstanceIdentifier getPath() {
78 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
79 return super.addToStringAttributes(toStringHelper).add("path", path);
83 protected abstract SerialForm<T> externalizableProxy(ABIVersion version);