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