2 * Copyright (c) 2014 Cisco 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
9 package org.opendaylight.controller.cluster.datastore.messages;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
15 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
17 public class DataExistsReply extends VersionedExternalizableMessage {
18 private static final long serialVersionUID = 1L;
20 private static final ShardTransactionMessages.DataExistsReply SERIALIZABLE_TRUE =
21 ShardTransactionMessages.DataExistsReply.newBuilder().setExists(true).build();
22 private static final ShardTransactionMessages.DataExistsReply SERIALIZABLE_FALSE =
23 ShardTransactionMessages.DataExistsReply.newBuilder().setExists(false).build();
25 private boolean exists;
27 public DataExistsReply() {
30 public DataExistsReply(final boolean exists, final short version) {
35 public boolean exists() {
40 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
41 super.readExternal(in);
42 exists = in.readBoolean();
46 public void writeExternal(ObjectOutput out) throws IOException {
47 super.writeExternal(out);
48 out.writeBoolean(exists);
52 public Object toSerializable() {
53 if(getVersion() >= DataStoreVersions.BORON_VERSION) {
56 return exists ? SERIALIZABLE_TRUE : SERIALIZABLE_FALSE;
60 public static DataExistsReply fromSerializable(final Object serializable) {
61 if(serializable instanceof DataExistsReply) {
62 return (DataExistsReply)serializable;
64 ShardTransactionMessages.DataExistsReply o = (ShardTransactionMessages.DataExistsReply) serializable;
65 return new DataExistsReply(o.getExists(), DataStoreVersions.LITHIUM_VERSION);
69 public static boolean isSerializedType(Object message) {
70 return message instanceof DataExistsReply || message instanceof ShardTransactionMessages.DataExistsReply;