Deprecate CloseTransactionChain protobuff message 08/33508/7
authorTom Pantelis <tpanteli@brocade.com>
Sat, 23 Jan 2016 05:31:21 +0000 (00:31 -0500)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 5 Feb 2016 16:24:21 +0000 (16:24 +0000)
Deprecate the associated CloseTransactionChain protobuff message and
change the message classes to extend VersionedExternalizableMessage.
Backwards compatibility with pre-boron is maintained. Related code was
modified accordingly.

The CloseTransactionChainReply message isn't used so it was removed.

Change-Id: I58d29eac9cb2f300f92dd4e5cb11484b215ddc48
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/protobuff/messages/transaction/ShardTransactionChainMessages.java
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/TransactionChainProxy.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChain.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainReply.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java

index feb60ae829d418b200300cba4faecc42cca5f942..c3f7d98b5561ee91eb000fcde7f98c67193232d8 100644 (file)
@@ -3,6 +3,7 @@
 
 package org.opendaylight.controller.protobuff.messages.transaction;
 
+@Deprecated
 public final class ShardTransactionChainMessages {
   private ShardTransactionChainMessages() {}
   public static void registerAllExtensions(
@@ -44,6 +45,7 @@ public final class ShardTransactionChainMessages {
       return defaultInstance;
     }
 
+    @Override
     public CloseTransactionChain getDefaultInstanceForType() {
       return defaultInstance;
     }
@@ -99,6 +101,7 @@ public final class ShardTransactionChainMessages {
       return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChain_descriptor;
     }
 
+    @Override
     protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
         internalGetFieldAccessorTable() {
       return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChain_fieldAccessorTable
@@ -108,7 +111,8 @@ public final class ShardTransactionChainMessages {
 
     public static com.google.protobuf.Parser<CloseTransactionChain> PARSER =
         new com.google.protobuf.AbstractParser<CloseTransactionChain>() {
-      public CloseTransactionChain parsePartialFrom(
+      @Override
+    public CloseTransactionChain parsePartialFrom(
           com.google.protobuf.CodedInputStream input,
           com.google.protobuf.ExtensionRegistryLite extensionRegistry)
           throws com.google.protobuf.InvalidProtocolBufferException {
@@ -128,12 +132,14 @@ public final class ShardTransactionChainMessages {
     /**
      * <code>optional string transactionChainId = 1;</code>
      */
+    @Override
     public boolean hasTransactionChainId() {
       return ((bitField0_ & 0x00000001) == 0x00000001);
     }
     /**
      * <code>optional string transactionChainId = 1;</code>
      */
+    @Override
     public java.lang.String getTransactionChainId() {
       java.lang.Object ref = transactionChainId_;
       if (ref instanceof java.lang.String) {
@@ -151,6 +157,7 @@ public final class ShardTransactionChainMessages {
     /**
      * <code>optional string transactionChainId = 1;</code>
      */
+    @Override
     public com.google.protobuf.ByteString
         getTransactionChainIdBytes() {
       java.lang.Object ref = transactionChainId_;
@@ -169,14 +176,18 @@ public final class ShardTransactionChainMessages {
       transactionChainId_ = "";
     }
     private byte memoizedIsInitialized = -1;
+    @Override
     public final boolean isInitialized() {
       byte isInitialized = memoizedIsInitialized;
-      if (isInitialized != -1) return isInitialized == 1;
+      if (isInitialized != -1) {
+        return isInitialized == 1;
+    }
 
       memoizedIsInitialized = 1;
       return true;
     }
 
+    @Override
     public void writeTo(com.google.protobuf.CodedOutputStream output)
                         throws java.io.IOException {
       getSerializedSize();
@@ -187,9 +198,12 @@ public final class ShardTransactionChainMessages {
     }
 
     private int memoizedSerializedSize = -1;
+    @Override
     public int getSerializedSize() {
       int size = memoizedSerializedSize;
-      if (size != -1) return size;
+      if (size != -1) {
+        return size;
+    }
 
       size = 0;
       if (((bitField0_ & 0x00000001) == 0x00000001)) {
@@ -262,10 +276,12 @@ public final class ShardTransactionChainMessages {
     }
 
     public static Builder newBuilder() { return Builder.create(); }
+    @Override
     public Builder newBuilderForType() { return newBuilder(); }
     public static Builder newBuilder(org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain prototype) {
       return newBuilder().mergeFrom(prototype);
     }
+    @Override
     public Builder toBuilder() { return newBuilder(this); }
 
     @java.lang.Override
@@ -285,7 +301,8 @@ public final class ShardTransactionChainMessages {
         return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChain_descriptor;
       }
 
-      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+      @Override
+    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
           internalGetFieldAccessorTable() {
         return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChain_fieldAccessorTable
             .ensureFieldAccessorsInitialized(
@@ -310,27 +327,32 @@ public final class ShardTransactionChainMessages {
         return new Builder();
       }
 
-      public Builder clear() {
+      @Override
+    public Builder clear() {
         super.clear();
         transactionChainId_ = "";
         bitField0_ = (bitField0_ & ~0x00000001);
         return this;
       }
 
-      public Builder clone() {
+      @Override
+    public Builder clone() {
         return create().mergeFrom(buildPartial());
       }
 
-      public com.google.protobuf.Descriptors.Descriptor
+      @Override
+    public com.google.protobuf.Descriptors.Descriptor
           getDescriptorForType() {
         return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChain_descriptor;
       }
 
-      public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain getDefaultInstanceForType() {
+      @Override
+    public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain getDefaultInstanceForType() {
         return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain.getDefaultInstance();
       }
 
-      public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain build() {
+      @Override
+    public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain build() {
         org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain result = buildPartial();
         if (!result.isInitialized()) {
           throw newUninitializedMessageException(result);
@@ -338,7 +360,8 @@ public final class ShardTransactionChainMessages {
         return result;
       }
 
-      public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain buildPartial() {
+      @Override
+    public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain buildPartial() {
         org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain result = new org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain(this);
         int from_bitField0_ = bitField0_;
         int to_bitField0_ = 0;
@@ -351,7 +374,8 @@ public final class ShardTransactionChainMessages {
         return result;
       }
 
-      public Builder mergeFrom(com.google.protobuf.Message other) {
+      @Override
+    public Builder mergeFrom(com.google.protobuf.Message other) {
         if (other instanceof org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain) {
           return mergeFrom((org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain)other);
         } else {
@@ -361,7 +385,9 @@ public final class ShardTransactionChainMessages {
       }
 
       public Builder mergeFrom(org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain other) {
-        if (other == org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain.getDefaultInstance()) return this;
+        if (other == org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain.getDefaultInstance()) {
+            return this;
+        }
         if (other.hasTransactionChainId()) {
           bitField0_ |= 0x00000001;
           transactionChainId_ = other.transactionChainId_;
@@ -371,11 +397,13 @@ public final class ShardTransactionChainMessages {
         return this;
       }
 
-      public final boolean isInitialized() {
+      @Override
+    public final boolean isInitialized() {
         return true;
       }
 
-      public Builder mergeFrom(
+      @Override
+    public Builder mergeFrom(
           com.google.protobuf.CodedInputStream input,
           com.google.protobuf.ExtensionRegistryLite extensionRegistry)
           throws java.io.IOException {
@@ -399,13 +427,15 @@ public final class ShardTransactionChainMessages {
       /**
        * <code>optional string transactionChainId = 1;</code>
        */
-      public boolean hasTransactionChainId() {
+      @Override
+    public boolean hasTransactionChainId() {
         return ((bitField0_ & 0x00000001) == 0x00000001);
       }
       /**
        * <code>optional string transactionChainId = 1;</code>
        */
-      public java.lang.String getTransactionChainId() {
+      @Override
+    public java.lang.String getTransactionChainId() {
         java.lang.Object ref = transactionChainId_;
         if (!(ref instanceof java.lang.String)) {
           java.lang.String s = ((com.google.protobuf.ByteString) ref)
@@ -419,7 +449,8 @@ public final class ShardTransactionChainMessages {
       /**
        * <code>optional string transactionChainId = 1;</code>
        */
-      public com.google.protobuf.ByteString
+      @Override
+    public com.google.protobuf.ByteString
           getTransactionChainIdBytes() {
         java.lang.Object ref = transactionChainId_;
         if (ref instanceof String) {
@@ -500,6 +531,7 @@ public final class ShardTransactionChainMessages {
       return defaultInstance;
     }
 
+    @Override
     public CloseTransactionChainReply getDefaultInstanceForType() {
       return defaultInstance;
     }
@@ -549,6 +581,7 @@ public final class ShardTransactionChainMessages {
       return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChainReply_descriptor;
     }
 
+    @Override
     protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
         internalGetFieldAccessorTable() {
       return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChainReply_fieldAccessorTable
@@ -558,7 +591,8 @@ public final class ShardTransactionChainMessages {
 
     public static com.google.protobuf.Parser<CloseTransactionChainReply> PARSER =
         new com.google.protobuf.AbstractParser<CloseTransactionChainReply>() {
-      public CloseTransactionChainReply parsePartialFrom(
+      @Override
+    public CloseTransactionChainReply parsePartialFrom(
           com.google.protobuf.CodedInputStream input,
           com.google.protobuf.ExtensionRegistryLite extensionRegistry)
           throws com.google.protobuf.InvalidProtocolBufferException {
@@ -574,14 +608,18 @@ public final class ShardTransactionChainMessages {
     private void initFields() {
     }
     private byte memoizedIsInitialized = -1;
+    @Override
     public final boolean isInitialized() {
       byte isInitialized = memoizedIsInitialized;
-      if (isInitialized != -1) return isInitialized == 1;
+      if (isInitialized != -1) {
+        return isInitialized == 1;
+    }
 
       memoizedIsInitialized = 1;
       return true;
     }
 
+    @Override
     public void writeTo(com.google.protobuf.CodedOutputStream output)
                         throws java.io.IOException {
       getSerializedSize();
@@ -589,9 +627,12 @@ public final class ShardTransactionChainMessages {
     }
 
     private int memoizedSerializedSize = -1;
+    @Override
     public int getSerializedSize() {
       int size = memoizedSerializedSize;
-      if (size != -1) return size;
+      if (size != -1) {
+        return size;
+    }
 
       size = 0;
       size += getUnknownFields().getSerializedSize();
@@ -660,10 +701,12 @@ public final class ShardTransactionChainMessages {
     }
 
     public static Builder newBuilder() { return Builder.create(); }
+    @Override
     public Builder newBuilderForType() { return newBuilder(); }
     public static Builder newBuilder(org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply prototype) {
       return newBuilder().mergeFrom(prototype);
     }
+    @Override
     public Builder toBuilder() { return newBuilder(this); }
 
     @java.lang.Override
@@ -683,7 +726,8 @@ public final class ShardTransactionChainMessages {
         return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChainReply_descriptor;
       }
 
-      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+      @Override
+    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
           internalGetFieldAccessorTable() {
         return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChainReply_fieldAccessorTable
             .ensureFieldAccessorsInitialized(
@@ -708,25 +752,30 @@ public final class ShardTransactionChainMessages {
         return new Builder();
       }
 
-      public Builder clear() {
+      @Override
+    public Builder clear() {
         super.clear();
         return this;
       }
 
-      public Builder clone() {
+      @Override
+    public Builder clone() {
         return create().mergeFrom(buildPartial());
       }
 
-      public com.google.protobuf.Descriptors.Descriptor
+      @Override
+    public com.google.protobuf.Descriptors.Descriptor
           getDescriptorForType() {
         return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChainReply_descriptor;
       }
 
-      public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply getDefaultInstanceForType() {
+      @Override
+    public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply getDefaultInstanceForType() {
         return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply.getDefaultInstance();
       }
 
-      public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply build() {
+      @Override
+    public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply build() {
         org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply result = buildPartial();
         if (!result.isInitialized()) {
           throw newUninitializedMessageException(result);
@@ -734,13 +783,15 @@ public final class ShardTransactionChainMessages {
         return result;
       }
 
-      public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply buildPartial() {
+      @Override
+    public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply buildPartial() {
         org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply result = new org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply(this);
         onBuilt();
         return result;
       }
 
-      public Builder mergeFrom(com.google.protobuf.Message other) {
+      @Override
+    public Builder mergeFrom(com.google.protobuf.Message other) {
         if (other instanceof org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply) {
           return mergeFrom((org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply)other);
         } else {
@@ -750,16 +801,20 @@ public final class ShardTransactionChainMessages {
       }
 
       public Builder mergeFrom(org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply other) {
-        if (other == org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply.getDefaultInstance()) return this;
+        if (other == org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply.getDefaultInstance()) {
+            return this;
+        }
         this.mergeUnknownFields(other.getUnknownFields());
         return this;
       }
 
-      public final boolean isInitialized() {
+      @Override
+    public final boolean isInitialized() {
         return true;
       }
 
-      public Builder mergeFrom(
+      @Override
+    public Builder mergeFrom(
           com.google.protobuf.CodedInputStream input,
           com.google.protobuf.ExtensionRegistryLite extensionRegistry)
           throws java.io.IOException {
@@ -816,6 +871,7 @@ public final class ShardTransactionChainMessages {
     };
     com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
       new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
+        @Override
         public com.google.protobuf.ExtensionRegistry assignDescriptors(
             com.google.protobuf.Descriptors.FileDescriptor root) {
           descriptor = root;
index 74e25323bc711434dac93efe71594defc761f3f0..b63cb862acd8a35d23b4c21425ec76a7d1d2df5f 100644 (file)
@@ -240,7 +240,7 @@ public class Shard extends RaftActor {
                 handleCommitTransaction(CommitTransaction.fromSerializable(message));
             } else if (AbortTransaction.isSerializedType(message)) {
                 handleAbortTransaction(AbortTransaction.fromSerializable(message));
-            } else if (CloseTransactionChain.SERIALIZABLE_CLASS.isInstance(message)) {
+            } else if (CloseTransactionChain.isSerializedType(message)) {
                 closeTransactionChain(CloseTransactionChain.fromSerializable(message));
             } else if (message instanceof RegisterChangeListener) {
                 changeSupport.onMessage((RegisterChangeListener) message, isLeader(), hasLeader());
index d230a956c250d0bb359c2889bffa18ac4346d48f..cf00d5fa39e3d317fe99af05d2f30f112fcb6f22 100644 (file)
@@ -19,6 +19,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import java.util.function.Function;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionChainIdentifier;
 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
@@ -184,7 +185,13 @@ final class TransactionChainProxy extends AbstractTransactionContextFactory<Loca
         currentState = CLOSED_STATE;
 
         // Send a close transaction chain request to each and every shard
-        getActorContext().broadcast(new CloseTransactionChain(transactionChainId.toString()).toSerializable());
+
+        getActorContext().broadcast(new Function<Short, Object>() {
+            @Override
+            public Object apply(Short version) {
+                return new CloseTransactionChain(transactionChainId.toString(), version).toSerializable();
+            }
+        });
     }
 
     private TransactionProxy allocateWriteTransaction(final TransactionType type) {
index 7db39b77a3063878f5fad44cbb61b3594b7b720f..bc59c544ca63c3935753435b0c2d49a29f886e76 100644 (file)
@@ -8,31 +8,64 @@
 
 package org.opendaylight.controller.cluster.datastore.messages;
 
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages;
 
-public class CloseTransactionChain implements SerializableMessage {
-    public static final Class<ShardTransactionChainMessages.CloseTransactionChain> SERIALIZABLE_CLASS =
-        ShardTransactionChainMessages.CloseTransactionChain.class;
-    private final String transactionChainId;
+public class CloseTransactionChain extends VersionedExternalizableMessage {
+    private static final long serialVersionUID = 1L;
 
-    public CloseTransactionChain(final String transactionChainId){
+    private String transactionChainId;
+
+    public CloseTransactionChain() {
+    }
+
+    public CloseTransactionChain(final String transactionChainId, final short version) {
+        super(version);
         this.transactionChainId = transactionChainId;
     }
 
+    public String getTransactionChainId() {
+        return transactionChainId;
+    }
+
     @Override
-    public Object toSerializable() {
-        return ShardTransactionChainMessages.CloseTransactionChain.newBuilder()
-            .setTransactionChainId(transactionChainId).build();
+    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        super.readExternal(in);
+        transactionChainId = in.readUTF();
     }
 
-    public static CloseTransactionChain fromSerializable(final Object message){
-        ShardTransactionChainMessages.CloseTransactionChain closeTransactionChain
-            = (ShardTransactionChainMessages.CloseTransactionChain) message;
+    @Override
+    public void writeExternal(ObjectOutput out) throws IOException {
+        super.writeExternal(out);
+        out.writeUTF(transactionChainId);
+    }
+
+    @Override
+    public Object toSerializable() {
+        if(getVersion() >= DataStoreVersions.BORON_VERSION) {
+            return this;
+        } else {
+            return ShardTransactionChainMessages.CloseTransactionChain.newBuilder()
+                .setTransactionChainId(transactionChainId).build();
+        }
+    }
 
-        return new CloseTransactionChain(closeTransactionChain.getTransactionChainId());
+    public static CloseTransactionChain fromSerializable(final Object serializable){
+        if(serializable instanceof CloseTransactionChain) {
+            return (CloseTransactionChain)serializable;
+        } else {
+            ShardTransactionChainMessages.CloseTransactionChain closeTransactionChain =
+                    (ShardTransactionChainMessages.CloseTransactionChain) serializable;
+            return new CloseTransactionChain(closeTransactionChain.getTransactionChainId(),
+                    DataStoreVersions.LITHIUM_VERSION);
+        }
     }
 
-    public String getTransactionChainId() {
-        return transactionChainId;
+    public static boolean isSerializedType(Object message) {
+        return message instanceof CloseTransactionChain ||
+                message instanceof ShardTransactionChainMessages.CloseTransactionChain;
     }
 }
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainReply.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainReply.java
deleted file mode 100644 (file)
index b4673e8..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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;
-
-import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages;
-
-public class CloseTransactionChainReply implements SerializableMessage {
-    public static final Class<ShardTransactionChainMessages.CloseTransactionChainReply> SERIALIZABLE_CLASS =
-            ShardTransactionChainMessages.CloseTransactionChainReply.class;
-
-    private static final Object SERIALIZED_INSTANCE =
-            ShardTransactionChainMessages.CloseTransactionChainReply.newBuilder().build();
-
-    public static final CloseTransactionChainReply INSTANCE = new CloseTransactionChainReply();
-
-    @Override
-    public Object toSerializable() {
-        return SERIALIZED_INSTANCE;
-    }
-}
index 1915621efd80d4e47eedd1fb9369aa350ed6f23d..e7ab144a5a034dfd0b868d33f34bd81c9aeafbb5 100644 (file)
@@ -25,6 +25,7 @@ import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
 import org.opendaylight.controller.cluster.datastore.ClusterWrapper;
 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
@@ -399,13 +400,14 @@ public class ActorContext {
      *
      * @param message
      */
-    public void broadcast(final Object message){
+    public void broadcast(final Function<Short, Object> messageSupplier){
         for(final String shardName : configuration.getAllShardNames()){
 
             Future<PrimaryShardInfo> primaryFuture = findPrimaryShardAsync(shardName);
             primaryFuture.onComplete(new OnComplete<PrimaryShardInfo>() {
                 @Override
                 public void onComplete(Throwable failure, PrimaryShardInfo primaryShardInfo) {
+                    Object message = messageSupplier.apply(primaryShardInfo.getPrimaryShardVersion());
                     if(failure != null) {
                         LOG.warn("broadcast failed to send message {} to shard {}:  {}",
                                 message.getClass().getSimpleName(), shardName, failure);
index 8338e7083ab4a64f1c8e7883bdeeec60934a35b5..66b8c0ec8df3dfd353d39ba5887f04bce65b8000 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.controller.cluster.datastore;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyObject;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Matchers.isA;
 import static org.mockito.Mockito.doReturn;
@@ -21,12 +20,12 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.opendaylight.controller.cluster.datastore.TransactionType.READ_WRITE;
 import static org.opendaylight.controller.cluster.datastore.TransactionType.WRITE_ONLY;
-
 import akka.actor.ActorRef;
 import akka.util.Timeout;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Function;
 import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications;
@@ -72,7 +71,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest {
     public void testClose() throws Exception {
         new TransactionChainProxy(mockComponentFactory).close();
 
-        verify(mockActorContext, times(1)).broadcast(anyObject());
+        verify(mockActorContext, times(1)).broadcast(any(Function.class));
     }
 
     @Test
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainTest.java
new file mode 100644 (file)
index 0000000..0e9c5d8
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2016 Brocade Communications 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;
+
+import static org.junit.Assert.assertEquals;
+import java.io.Serializable;
+import org.apache.commons.lang.SerializationUtils;
+import org.junit.Test;
+import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
+import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages;
+
+/**
+ * Unit tests for CloseTransactionChain.
+ *
+ * @author Thomas Pantelis
+ */
+public class CloseTransactionChainTest {
+
+    @Test
+    public void testSerialization() {
+        CloseTransactionChain expected = new CloseTransactionChain("txId", DataStoreVersions.CURRENT_VERSION);
+
+        Object serialized = expected.toSerializable();
+        assertEquals("Serialized type", CloseTransactionChain.class, serialized.getClass());
+
+        CloseTransactionChain actual = CloseTransactionChain.fromSerializable(
+                SerializationUtils.clone((Serializable) serialized));
+        assertEquals("getTransactionChainId", expected.getTransactionChainId(), actual.getTransactionChainId());
+        assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
+    }
+
+    @Test
+    public void testSerializationWithPreBoronVersion() {
+        CloseTransactionChain expected = new CloseTransactionChain("txId", DataStoreVersions.LITHIUM_VERSION);
+
+        Object serialized = expected.toSerializable();
+        assertEquals("Serialized type", ShardTransactionChainMessages.CloseTransactionChain.class, serialized.getClass());
+
+        CloseTransactionChain actual = CloseTransactionChain.fromSerializable(
+                SerializationUtils.clone((Serializable) serialized));
+        assertEquals("getTransactionChainId", expected.getTransactionChainId(), actual.getTransactionChainId());
+        assertEquals("getVersion", DataStoreVersions.LITHIUM_VERSION, actual.getVersion());
+    }
+
+    @Test
+    public void testIsSerializedType() {
+        assertEquals("isSerializedType", true, CloseTransactionChain.isSerializedType(
+                ShardTransactionChainMessages.CloseTransactionChain.newBuilder().setTransactionChainId("").build()));
+
+        assertEquals("isSerializedType", true, CloseTransactionChain.isSerializedType(new CloseTransactionChain()));
+        assertEquals("isSerializedType", false, CloseTransactionChain.isSerializedType(new Object()));
+    }
+}
index 14536ba7a0429fe53c43228d54a1fd8247a6e107..405fe5221b64255e086db7b37eb1af1679e4da18 100644 (file)
@@ -35,6 +35,7 @@ import com.typesafe.config.ConfigFactory;
 import java.util.Arrays;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -497,7 +498,12 @@ public class ActorContextTest extends AbstractActorTest{
                     mock(ClusterWrapper.class), mockConfig,
                     DatastoreContext.newBuilder().shardInitializationTimeout(200, TimeUnit.MILLISECONDS).build(), new PrimaryShardInfoFutureCache());
 
-            actorContext.broadcast(new TestMessage());
+            actorContext.broadcast(new Function<Short, Object>() {
+                @Override
+                public Object apply(Short v) {
+                    return new TestMessage();
+                }
+            });
 
             MessageCollectorActor.expectFirstMatching(shardActorRef1, TestMessage.class);
             MessageCollectorActor.expectFirstMatching(shardActorRef2, TestMessage.class);