X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fmessages%2FDataExists.java;h=08394622fbd7ec3a410914d1ff2d57c42cf909c1;hp=2541a04d5fe32969f6e4b0889a6c980033b155ba;hb=dd16edd5a758f0e51727de511f9868c72b2a1dd0;hpb=74926cb05f2e5e4937658ca61444f7d7c846eb00 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataExists.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataExists.java index 2541a04d5f..08394622fb 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataExists.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataExists.java @@ -10,6 +10,7 @@ package org.opendaylight.controller.cluster.datastore.messages; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.SettableFuture; +import org.opendaylight.controller.cluster.datastore.DataStoreVersions; import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages; @@ -17,23 +18,20 @@ import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; public class DataExists extends AbstractRead { + private static final long serialVersionUID = 1L; - public static final Class SERIALIZABLE_CLASS = - ShardTransactionMessages.DataExists.class; - - public DataExists(final YangInstanceIdentifier path) { - super(path); + public DataExists() { } - @Override public Object toSerializable() { - return ShardTransactionMessages.DataExists.newBuilder() - .setInstanceIdentifierPathArguments( - InstanceIdentifierUtils.toSerializable(getPath())).build(); + public DataExists(final YangInstanceIdentifier path, final short version) { + super(path, version); } - public static DataExists fromSerializable(final Object serializable){ - ShardTransactionMessages.DataExists o = (ShardTransactionMessages.DataExists) serializable; - return new DataExists(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments())); + @Deprecated + @Override + protected Object newLegacySerializedInstance() { + return ShardTransactionMessages.DataExists.newBuilder() + .setInstanceIdentifierPathArguments(InstanceIdentifierUtils.toSerializable(getPath())).build(); } @Override @@ -43,15 +41,29 @@ public class DataExists extends AbstractRead { @Override public void processResponse(Object response, SettableFuture returnFuture) { - if(response instanceof DataExistsReply) { - returnFuture.set(Boolean.valueOf(((DataExistsReply) response).exists())); - - } else if(response.getClass().equals(DataExistsReply.SERIALIZABLE_CLASS)) { + if(DataExistsReply.isSerializedType(response)) { returnFuture.set(Boolean.valueOf(DataExistsReply.fromSerializable(response).exists())); - } else { returnFuture.setException(new ReadFailedException("Invalid response checking exists for path " + getPath())); } } + @Override + protected AbstractRead newInstance(short withVersion) { + return new DataExists(getPath(), withVersion); + } + + public static DataExists fromSerializable(final Object serializable){ + if(serializable instanceof DataExists) { + return (DataExists)serializable; + } else { + ShardTransactionMessages.DataExists o = (ShardTransactionMessages.DataExists) serializable; + return new DataExists(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments()), + DataStoreVersions.LITHIUM_VERSION); + } + } + + public static boolean isSerializedType(Object message) { + return message instanceof DataExists || message instanceof ShardTransactionMessages.DataExists; + } }