Merge "BUG-3018: report DataTreeChangeListener initial state"
authorTony Tkacik <ttkacik@cisco.com>
Mon, 20 Apr 2015 15:12:52 +0000 (15:12 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 20 Apr 2015 15:12:53 +0000 (15:12 +0000)
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataExistsReply.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/OperationCompleterTest.java

index 066f01b092d701b08556c5fd7319db4d64a6859c..81125a7152bf562baede534f7b84b2560f4f9bae 100644 (file)
@@ -137,14 +137,13 @@ public abstract class ShardTransaction extends AbstractUntypedActorWithMetering
         final YangInstanceIdentifier path = message.getPath();
 
         try {
-            Boolean exists = transaction.exists(path).checkedGet();
-            DataExistsReply dataExistsReply = new DataExistsReply(exists);
+            boolean exists = transaction.exists(path).checkedGet();
+            DataExistsReply dataExistsReply = DataExistsReply.create(exists);
             getSender().tell(returnSerialized ? dataExistsReply.toSerializable() :
                 dataExistsReply, getSelf());
         } catch (ReadFailedException e) {
             getSender().tell(new akka.actor.Status.Failure(e),getSelf());
         }
-
     }
 
     private static class ShardTransactionCreator implements Creator<ShardTransaction> {
index 24ca6464543911c9d4c6d05fe1f3f2d8731c920e..0ea865aa07e06b8f201955d9bfcac61c27d83725 100644 (file)
@@ -10,28 +10,47 @@ package org.opendaylight.controller.cluster.datastore.messages;
 
 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
 
-public class DataExistsReply implements SerializableMessage{
+public class DataExistsReply implements SerializableMessage {
     public static final Class<ShardTransactionMessages.DataExistsReply> SERIALIZABLE_CLASS =
             ShardTransactionMessages.DataExistsReply.class;
 
+    private static final DataExistsReply TRUE = new DataExistsReply(true, null);
+    private static final DataExistsReply FALSE = new DataExistsReply(false, null);
+    private static final ShardTransactionMessages.DataExistsReply SERIALIZABLE_TRUE =
+            ShardTransactionMessages.DataExistsReply.newBuilder().setExists(true).build();
+    private static final ShardTransactionMessages.DataExistsReply SERIALIZABLE_FALSE =
+            ShardTransactionMessages.DataExistsReply.newBuilder().setExists(false).build();
+
     private final boolean exists;
 
-    public DataExistsReply(final boolean exists) {
+    private DataExistsReply(final boolean exists, final Void dummy) {
         this.exists = exists;
     }
 
+    /**
+     * @deprecated Use {@link #create(boolean)} instead.
+     * @param exists
+     */
+    @Deprecated
+    public DataExistsReply(final boolean exists) {
+        this(exists, null);
+    }
+
+    public static DataExistsReply create(final boolean exists) {
+        return exists ? TRUE : FALSE;
+    }
+
     public boolean exists() {
         return exists;
     }
 
-    @Override public Object toSerializable() {
-        return ShardTransactionMessages.DataExistsReply.newBuilder()
-            .setExists(exists).build();
+    @Override
+    public Object toSerializable() {
+        return exists ? SERIALIZABLE_TRUE : SERIALIZABLE_FALSE;
     }
 
-    public static DataExistsReply fromSerializable(final Object serializable){
+    public static DataExistsReply fromSerializable(final Object serializable) {
         ShardTransactionMessages.DataExistsReply o = (ShardTransactionMessages.DataExistsReply) serializable;
-        return new DataExistsReply(o.getExists());
+        return create(o.getExists());
     }
-
 }
index 6a1e12a96b6e9cd2eb7a3a89204a87d21a64f1da..aa7ad259b4ea3ed02f79d6c423d15805b4ae3ad3 100644 (file)
@@ -221,18 +221,18 @@ public abstract class AbstractTransactionProxyTest {
     }
 
     protected Future<Object> dataExistsSerializedReply(boolean exists) {
-        return Futures.successful(new DataExistsReply(exists).toSerializable());
+        return Futures.successful(DataExistsReply.create(exists).toSerializable());
     }
 
     protected Future<DataExistsReply> dataExistsReply(boolean exists) {
-        return Futures.successful(new DataExistsReply(exists));
+        return Futures.successful(DataExistsReply.create(exists));
     }
 
     protected Future<BatchedModificationsReply> batchedModificationsReply(int count) {
         return Futures.successful(new BatchedModificationsReply(count));
     }
 
-    protected Future<Object> incompleteFuture(){
+    protected Future<Object> incompleteFuture() {
         return mock(Future.class);
     }
 
index e7afe262b96a6f564b5b672f7473b6c6e12d48db..00900d35fb0a29f9a79ef748ca2916610647c748 100644 (file)
@@ -29,10 +29,10 @@ public class OperationCompleterTest {
 
         OperationCompleter completer = new OperationCompleter(operationLimiter );
 
-        completer.onComplete(null, new DataExistsReply(true));
+        completer.onComplete(null, DataExistsReply.create(true));
         assertEquals("availablePermits", ++availablePermits, operationLimiter.availablePermits());
 
-        completer.onComplete(null, new DataExistsReply(true));
+        completer.onComplete(null, DataExistsReply.create(true));
         assertEquals("availablePermits", ++availablePermits, operationLimiter.availablePermits());
 
         completer.onComplete(null, new IllegalArgumentException());