2 * Copyright (c) 2016, 2017 Cisco Systems, Inc. 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 akka.actor.ActorRef;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import java.io.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.controller.cluster.access.ABIVersion;
17 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
20 * Abstract base class for {@link TransactionRequest}s accessing transaction state without modifying it.
23 * This class is visible outside of this package for the purpose of allowing common instanceof checks
24 * and simplified codepaths.
26 * @param <T> Message type
28 public abstract class AbstractReadTransactionRequest<T extends AbstractReadTransactionRequest<T>>
29 extends TransactionRequest<T> {
30 interface SerialForm<T extends AbstractReadTransactionRequest<T>> extends TransactionRequest.SerialForm<T> {
32 default T readExternal(final ObjectInput in, final TransactionIdentifier target, final long sequence,
33 final ActorRef replyTo) throws IOException {
34 return readExternal(in, target, sequence, replyTo, in.readBoolean());
37 @NonNull T readExternal(@NonNull ObjectInput in, @NonNull TransactionIdentifier target, long sequence,
38 @NonNull ActorRef replyTo, boolean snapshotOnly) throws IOException;
41 default void writeExternal(final ObjectOutput out, final T msg) throws IOException {
42 TransactionRequest.SerialForm.super.writeExternal(out, msg);
43 out.writeBoolean(msg.isSnapshotOnly());
48 private static final long serialVersionUID = 1L;
50 private final boolean snapshotOnly;
52 AbstractReadTransactionRequest(final TransactionIdentifier identifier, final long sequence, final ActorRef replyTo,
53 final boolean snapshotOnly) {
54 super(identifier, sequence, replyTo);
55 this.snapshotOnly = snapshotOnly;
58 AbstractReadTransactionRequest(final T request, final ABIVersion version) {
59 super(request, version);
60 this.snapshotOnly = request.isSnapshotOnly();
63 public final boolean isSnapshotOnly() {
68 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
69 return super.addToStringAttributes(toStringHelper).add("snapshotOnly", snapshotOnly);
73 protected abstract SerialForm<T> externalizableProxy(ABIVersion version);