Fixup checkstyle
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / AbstractVersionException.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.datastore.persisted;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14
15 /**
16  * Abstract base exception used for reporting version mismatches from {@link PayloadVersion}.
17  *
18  * @author Robert Varga
19  */
20 @Beta
21 public abstract class AbstractVersionException extends Exception {
22     private static final long serialVersionUID = 1L;
23
24     private final @NonNull PayloadVersion closestVersion;
25     private final int version;
26
27     AbstractVersionException(final String message, final short version, final PayloadVersion closestVersion) {
28         super(message);
29         this.closestVersion = requireNonNull(closestVersion);
30         this.version = Short.toUnsignedInt(version);
31     }
32
33     /**
34      * Return the numeric version which has caused this exception.
35      *
36      * @return Numeric version
37      */
38     public final int getVersion() {
39         return version;
40     }
41
42     /**
43      * Return the closest version supported by this codebase.
44      *
45      * @return Closest supported {@link PayloadVersion}
46      */
47     public final @NonNull PayloadVersion getClosestVersion() {
48         return closestVersion;
49     }
50 }