Fix warnings/javadocs in sal-distributed-datastore
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / VersionedExternalizableMessage.java
1 /*
2  * Copyright (c) 2015 Brocade Communications 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.messages;
9
10 import java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
15
16 /**
17  * Abstract base class for a versioned Externalizable message.
18  *
19  * @author Thomas Pantelis
20  */
21 public abstract class VersionedExternalizableMessage implements Externalizable, SerializableMessage {
22     private static final long serialVersionUID = 1L;
23
24     private short version = DataStoreVersions.CURRENT_VERSION;
25
26     public VersionedExternalizableMessage() {
27     }
28
29     public VersionedExternalizableMessage(short version) {
30         this.version = version <= DataStoreVersions.CURRENT_VERSION ? version : DataStoreVersions.CURRENT_VERSION;
31     }
32
33     public short getVersion() {
34         return version;
35     }
36
37     @Override
38     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
39         version = in.readShort();
40     }
41
42     @Override
43     public void writeExternal(ObjectOutput out) throws IOException {
44         out.writeShort(version);
45     }
46
47     @Override
48     public final Object toSerializable() {
49         if (getVersion() < DataStoreVersions.BORON_VERSION) {
50             throw new UnsupportedOperationException("Versions prior to " + DataStoreVersions.BORON_VERSION
51                     + " are not supported");
52         }
53
54         return this;
55     }
56
57     @Override
58     public String toString() {
59         return getClass().getSimpleName() + " [version=" + getVersion() + "]";
60     }
61 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.