X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fmessages%2FDataExists.java;h=2541a04d5fe32969f6e4b0889a6c980033b155ba;hb=11e722671c6dc194761471038a4e3ca5f7fd8970;hp=d52daabd845456b990f4f79300906134ec3744bb;hpb=54916d10764a5234881040e9a68ae35d63b3dac9;p=controller.git 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 d52daabd84..2541a04d5f 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 @@ -8,33 +8,50 @@ 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.util.InstanceIdentifierUtils; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages; +import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -public class DataExists implements SerializableMessage{ +public class DataExists extends AbstractRead { - public static final Class SERIALIZABLE_CLASS = ShardTransactionMessages.DataExists.class; + public static final Class SERIALIZABLE_CLASS = + ShardTransactionMessages.DataExists.class; - private final YangInstanceIdentifier path; - - public DataExists(YangInstanceIdentifier path) { - this.path = path; - } - - public YangInstanceIdentifier getPath() { - return path; + public DataExists(final YangInstanceIdentifier path) { + super(path); } @Override public Object toSerializable() { return ShardTransactionMessages.DataExists.newBuilder() .setInstanceIdentifierPathArguments( - InstanceIdentifierUtils.toSerializable(path)).build(); + InstanceIdentifierUtils.toSerializable(getPath())).build(); } - public static DataExists fromSerializable(Object serializable){ + public static DataExists fromSerializable(final Object serializable){ ShardTransactionMessages.DataExists o = (ShardTransactionMessages.DataExists) serializable; return new DataExists(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments())); } + @Override + public CheckedFuture apply(DOMStoreReadTransaction readDelegate) { + return readDelegate.exists(getPath()); + } + + @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)) { + returnFuture.set(Boolean.valueOf(DataExistsReply.fromSerializable(response).exists())); + + } else { + returnFuture.setException(new ReadFailedException("Invalid response checking exists for path " + getPath())); + } + } + }