709217d7a553ba1074742e69a0ccc4245719f34b
[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 com.google.common.annotations.Beta;
11 import com.google.common.base.Preconditions;
12 import javax.annotation.Nonnull;
13
14 /**
15  * Abstract base exception used for reporting version mismatches from {@link PayloadVersion}.
16  *
17  * @author Robert Varga
18  */
19 @Beta
20 public abstract class AbstractVersionException extends Exception {
21     private static final long serialVersionUID = 1L;
22     private final PayloadVersion closestVersion;
23     private final int version;
24
25     AbstractVersionException(final String message, final short version, final PayloadVersion closestVersion) {
26         super(message);
27         this.closestVersion = Preconditions.checkNotNull(closestVersion);
28         this.version = Short.toUnsignedInt(version);
29     }
30
31     /**
32      * Return the numeric version which has caused this exception.
33      *
34      * @return Numeric version
35      */
36     public final int getVersion() {
37         return version;
38     }
39
40     /**
41      * Return the closest version supported by this codebase.
42      *
43      * @return Closest supported {@link PayloadVersion}
44      */
45     public final @Nonnull PayloadVersion getClosestVersion() {
46         return closestVersion;
47     }
48
49 }