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