From: Tony Tkacik Date: Mon, 20 Apr 2015 15:12:52 +0000 (+0000) Subject: Merge "BUG-3018: report DataTreeChangeListener initial state" X-Git-Tag: release/lithium~251 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=874b36cfb71a3c138521831de204374fdbd64372;hp=3d238a5647ee15331849fbe9269e11969229ee5a Merge "BUG-3018: report DataTreeChangeListener initial state" --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java index 066f01b092..81125a7152 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java @@ -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 { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataExistsReply.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataExistsReply.java index 24ca646454..0ea865aa07 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataExistsReply.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataExistsReply.java @@ -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 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()); } - } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java index 6a1e12a96b..aa7ad259b4 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java @@ -221,18 +221,18 @@ public abstract class AbstractTransactionProxyTest { } protected Future dataExistsSerializedReply(boolean exists) { - return Futures.successful(new DataExistsReply(exists).toSerializable()); + return Futures.successful(DataExistsReply.create(exists).toSerializable()); } protected Future dataExistsReply(boolean exists) { - return Futures.successful(new DataExistsReply(exists)); + return Futures.successful(DataExistsReply.create(exists)); } protected Future batchedModificationsReply(int count) { return Futures.successful(new BatchedModificationsReply(count)); } - protected Future incompleteFuture(){ + protected Future incompleteFuture() { return mock(Future.class); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/OperationCompleterTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/OperationCompleterTest.java index e7afe262b9..00900d35fb 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/OperationCompleterTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/OperationCompleterTest.java @@ -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());