Deprecate CloseTransaction protobuff message
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / DataExists.java
index 84b8df167607701ea35caf4c32fa301451744e83..2541a04d5fe32969f6e4b0889a6c980033b155ba 100644 (file)
@@ -8,29 +8,27 @@
 
 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<Boolean> {
 
     public static final Class<ShardTransactionMessages.DataExists> SERIALIZABLE_CLASS =
             ShardTransactionMessages.DataExists.class;
 
-    private final YangInstanceIdentifier path;
-
     public DataExists(final YangInstanceIdentifier path) {
-        this.path = path;
-    }
-
-    public YangInstanceIdentifier getPath() {
-        return path;
+        super(path);
     }
 
     @Override public Object toSerializable() {
         return ShardTransactionMessages.DataExists.newBuilder()
             .setInstanceIdentifierPathArguments(
-                InstanceIdentifierUtils.toSerializable(path)).build();
+                InstanceIdentifierUtils.toSerializable(getPath())).build();
     }
 
     public static DataExists fromSerializable(final Object serializable){
@@ -38,4 +36,22 @@ public class DataExists implements SerializableMessage{
         return new DataExists(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments()));
     }
 
+    @Override
+    public CheckedFuture<Boolean, ReadFailedException> apply(DOMStoreReadTransaction readDelegate) {
+        return readDelegate.exists(getPath());
+    }
+
+    @Override
+    public void processResponse(Object response, SettableFuture<Boolean> 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()));
+        }
+    }
+
 }