Pattern for switching from POJO messages to Protocol Buffer messages 14/8814/6
authorMoiz Raja <moraja@cisco.com>
Tue, 8 Jul 2014 18:17:52 +0000 (11:17 -0700)
committerMoiz Raja <moraja@cisco.com>
Mon, 28 Jul 2014 20:56:28 +0000 (13:56 -0700)
Change-Id: I053581bc66cdd2627132af7366e01d8276a7c27e
Signed-off-by: Moiz Raja <moraja@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CreateTransactionChain.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CreateTransactionReply.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/SerializableMessage.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/BasicIntegrationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerProxyTest.java

index f61eec87083bed323bf8423a4f5a84000a02e0d6..a3437e28f04b60555ed0fbab6961a4353c209170 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionR
 import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChain;
 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChainReply;
+import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply;
 import org.opendaylight.controller.cluster.datastore.messages.ForwardedCommitTransaction;
 import org.opendaylight.controller.cluster.datastore.messages.NonPersistent;
 import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener;
@@ -36,7 +37,6 @@ import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCoh
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages.CreateTransactionReply;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -117,10 +117,7 @@ public class Shard extends UntypedProcessor {
         ActorRef transactionActor = getContext().actorOf(
             ShardTransaction.props(transaction, getSelf()), "shard-" + createTransaction.getTransactionId());
         getSender()
-            .tell(CreateTransactionReply.newBuilder()
-                    .setTransactionActorPath(transactionActor.path().toString())
-                    .setTransactionId(createTransaction.getTransactionId())
-                    .build(),
+            .tell(new CreateTransactionReply(transactionActor.path().toString(), createTransaction.getTransactionId()).toSerializable(),
                 getSelf());
     }
 
index 81fd6eeabf49e62e2ad5f53ee4dadd8dc4bc4068..18b29c67d09b87f5ea99d3d82b73d8c77759e46a 100644 (file)
@@ -8,30 +8,38 @@
 
 package org.opendaylight.controller.cluster.datastore.messages;
 
-import akka.actor.ActorPath;
+import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
 
-/**
- * This is being deprecated to use sal-protocolbuff-encoding ShardTransactionMessages.CreateTransactionReply
- * This classes will be removed once complete integration of distribute datastore with
- * sal-protocolbuff-encoding is done.
- */
+public class CreateTransactionReply implements SerializableMessage {
 
-@Deprecated
-public class CreateTransactionReply {
-    private final ActorPath transactionPath;
+    public static final Class SERIALIZABLE_CLASS = ShardTransactionMessages.CreateTransactionReply.class;
+    private final String transactionPath;
     private final String transactionId;
 
-    public CreateTransactionReply(ActorPath transactionPath,
+    public CreateTransactionReply(String transactionPath,
         String transactionId) {
         this.transactionPath = transactionPath;
         this.transactionId = transactionId;
     }
 
-    public ActorPath getTransactionPath() {
+    public String getTransactionPath() {
         return transactionPath;
     }
 
     public String getTransactionId() {
         return transactionId;
     }
+
+    public Object toSerializable(){
+        return ShardTransactionMessages.CreateTransactionReply.newBuilder()
+            .setTransactionActorPath(transactionPath.toString())
+            .setTransactionId(transactionId)
+            .build();
+    }
+
+    public static CreateTransactionReply fromSerializable(Object serializable){
+        ShardTransactionMessages.CreateTransactionReply o = (ShardTransactionMessages.CreateTransactionReply) serializable;
+        return new CreateTransactionReply(o.getTransactionActorPath(), o.getTransactionId());
+    }
+
 }
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/SerializableMessage.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/SerializableMessage.java
new file mode 100644 (file)
index 0000000..d87b903
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.cluster.datastore.messages;
+
+public interface SerializableMessage {
+    Object toSerializable();
+}
index 6b436ad95e5b14ec724fdc35cb5a5940f8e5fbb4..8d7f7c87aaf6f198168c5af2398b9fc58468703a 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionR
 import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChain;
 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChainReply;
-import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages.CreateTransactionReply;
+import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply;
 import org.opendaylight.controller.cluster.datastore.messages.PreCommitTransaction;
 import org.opendaylight.controller.cluster.datastore.messages.PreCommitTransactionReply;
 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
@@ -82,10 +82,11 @@ public class BasicIntegrationTest extends AbstractActorTest {
                     final ActorSelection transaction =
                         new ExpectMsg<ActorSelection>("CreateTransactionReply") {
                             protected ActorSelection match(Object in) {
-                                if (in instanceof CreateTransactionReply) {
+                                if (CreateTransactionReply.SERIALIZABLE_CLASS.equals(in.getClass())) {
+                                    CreateTransactionReply reply = CreateTransactionReply.fromSerializable(in);
                                     return getSystem()
-                                        .actorSelection((((CreateTransactionReply) in)
-                                            .getTransactionActorPath()));
+                                        .actorSelection(reply
+                                            .getTransactionPath());
                                 } else {
                                     throw noMatch();
                                 }