Improve segmented journal actor metrics
[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 org.eclipse.jdt.annotation.NonNull;
13
14 /**
15  * Abstract base exception used for reporting version mismatches from {@link ABIVersion}.
16  */
17 public abstract class AbstractVersionException extends Exception {
18     @java.io.Serial
19     private static final long serialVersionUID = 1L;
20
21     private final @NonNull ABIVersion closestVersion;
22     private final int version;
23
24     AbstractVersionException(final String message, final short version, final ABIVersion closestVersion) {
25         super(message);
26         this.closestVersion = requireNonNull(closestVersion);
27         this.version = Short.toUnsignedInt(version);
28     }
29
30     /**
31      * Return the numeric version which has caused this exception.
32      *
33      * @return Numeric version
34      */
35     public final int version() {
36         return version;
37     }
38
39     /**
40      * Return the closest version supported by this codebase.
41      *
42      * @return Closest supported {@link ABIVersion}
43      */
44     public final @NonNull ABIVersion closestVersion() {
45         return closestVersion;
46     }
47 }