Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / TransactionRequest.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 java.io.DataInput;
12 import java.io.IOException;
13 import org.opendaylight.controller.cluster.access.ABIVersion;
14 import org.opendaylight.controller.cluster.access.concepts.Request;
15 import org.opendaylight.controller.cluster.access.concepts.RequestException;
16 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
17
18 /**
19  * Abstract base class for {@link Request}s involving specific transaction. This class is visible outside of this
20  * package solely for the ability to perform a unified instanceof check.
21  *
22  * @param <T> Message type
23  */
24 public abstract class TransactionRequest<T extends TransactionRequest<T>> extends Request<TransactionIdentifier, T> {
25     protected interface SerialForm<T extends TransactionRequest<T>>
26             extends Request.SerialForm<TransactionIdentifier, T> {
27         @Override
28         default TransactionIdentifier readTarget(final DataInput in) throws IOException {
29             return TransactionIdentifier.readFrom(in);
30         }
31     }
32
33     @java.io.Serial
34     private static final long serialVersionUID = 1L;
35
36     TransactionRequest(final TransactionIdentifier identifier, final long sequence, final ActorRef replyTo) {
37         super(identifier, sequence, replyTo);
38     }
39
40     TransactionRequest(final T request, final ABIVersion version) {
41         super(request, version);
42     }
43
44     @Override
45     public final TransactionFailure toRequestFailure(final RequestException cause) {
46         return new TransactionFailure(getTarget(), getSequence(), cause);
47     }
48
49     @Override
50     protected abstract SerialForm<T> externalizableProxy(ABIVersion version);
51 }