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;
21 private static final ShardTransactionMessages.DataExistsReply SERIALIZABLE_TRUE =
22 ShardTransactionMessages.DataExistsReply.newBuilder().setExists(true).build();
24 private static final ShardTransactionMessages.DataExistsReply SERIALIZABLE_FALSE =
25 ShardTransactionMessages.DataExistsReply.newBuilder().setExists(false).build();
27 private boolean exists;
29 public DataExistsReply() {
32 public DataExistsReply(final boolean exists, final short version) {
37 public boolean exists() {
42 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
43 super.readExternal(in);
44 exists = in.readBoolean();
48 public void writeExternal(ObjectOutput out) throws IOException {
49 super.writeExternal(out);
50 out.writeBoolean(exists);
55 protected Object newLegacySerializedInstance() {
56 return exists ? SERIALIZABLE_TRUE : SERIALIZABLE_FALSE;
59 public static DataExistsReply fromSerializable(final Object serializable) {
60 if(serializable instanceof DataExistsReply) {
61 return (DataExistsReply)serializable;
63 ShardTransactionMessages.DataExistsReply o = (ShardTransactionMessages.DataExistsReply) serializable;
64 return new DataExistsReply(o.getExists(), DataStoreVersions.LITHIUM_VERSION);
68 public static boolean isSerializedType(Object message) {
69 return message instanceof DataExistsReply || message instanceof ShardTransactionMessages.DataExistsReply;