2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore.messages;
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;
17 * Abstract base class for a versioned Externalizable message.
19 * @author Thomas Pantelis
21 public abstract class VersionedExternalizableMessage implements Externalizable, SerializableMessage {
22 private static final long serialVersionUID = 1L;
24 private short version = DataStoreVersions.CURRENT_VERSION;
26 public VersionedExternalizableMessage() {
29 public VersionedExternalizableMessage(short version) {
30 this.version = version <= DataStoreVersions.CURRENT_VERSION ? version : DataStoreVersions.CURRENT_VERSION;
33 public short getVersion() {
38 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
39 version = in.readShort();
43 public void writeExternal(ObjectOutput out) throws IOException {
44 out.writeShort(version);
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");
58 public String toString() {
59 return getClass().getSimpleName() + " [version=" + getVersion() + "]";