Reduce JSR305 proliferation
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / 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.access;
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 ABIVersion}.
17  *
18  * @author Robert Varga
19  */
20 @Beta
21 public abstract class AbstractVersionException extends Exception {
22     private static final long serialVersionUID = 1L;
23     private final @NonNull ABIVersion closestVersion;
24     private final int version;
25
26     AbstractVersionException(final String message, final short version, final ABIVersion closestVersion) {
27         super(message);
28         this.closestVersion = requireNonNull(closestVersion);
29         this.version = Short.toUnsignedInt(version);
30     }
31
32     /**
33      * Return the numeric version which has caused this exception.
34      *
35      * @return Numeric version
36      */
37     public final int getVersion() {
38         return version;
39     }
40
41     /**
42      * Return the closest version supported by this codebase.
43      *
44      * @return Closest supported {@link ABIVersion}
45      */
46     public final @NonNull ABIVersion getClosestVersion() {
47         return closestVersion;
48     }
49
50 }