Use separate instance of serializer for ClusterMessaging and ECMap

- might be related to CORD-199
- Builder was not intended to be shared, since they are mutable

- also unsubscribe from cluster communicator on deactivate()

Change-Id: I0eebec1d5420277b33e2fb373119ffcb40a31c43
diff --git a/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java b/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java
index 5551ecf..a999ee7 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java
@@ -128,6 +128,8 @@
 
     private final AtomicLong sequenceNumber = new AtomicLong(0);
 
+    private KryoNamespace clusterMsgSerializer;
+
     @Activate
     public void activate() {
         kryoBuilder = new KryoNamespace.Builder()
@@ -150,13 +152,15 @@
                       GroupStoreMapKey.class
             );
 
+        clusterMsgSerializer = kryoBuilder.build();
+
         messageHandlingExecutor = Executors.
                 newFixedThreadPool(MESSAGE_HANDLER_THREAD_POOL_SIZE,
                                    groupedThreads("onos/store/group",
                                                   "message-handlers"));
 
         clusterCommunicator.addSubscriber(GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST,
-                kryoBuilder.build()::deserialize,
+                clusterMsgSerializer::deserialize,
                 this::process,
                 messageHandlingExecutor);
 
@@ -192,6 +196,7 @@
 
     @Deactivate
     public void deactivate() {
+        clusterCommunicator.removeSubscriber(GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST);
         groupStoreEntriesByKey.destroy();
         auditPendingReqQueue.destroy();
         log.info("Stopped");
@@ -366,7 +371,7 @@
 
             clusterCommunicator.unicast(groupOp,
                     GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST,
-                    m -> kryoBuilder.build().serialize(m),
+                    clusterMsgSerializer::serialize,
                     mastershipService.getMasterFor(groupDesc.deviceId())).whenComplete((result, error) -> {
                         if (error != null) {
                             log.warn("Failed to send request to master: {} to {}",
@@ -564,7 +569,7 @@
 
             clusterCommunicator.unicast(groupOp,
                     GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST,
-                    m -> kryoBuilder.build().serialize(m),
+                    clusterMsgSerializer::serialize,
                     mastershipService.getMasterFor(deviceId)).whenComplete((result, error) -> {
                         if (error !=  null) {
                             log.warn("Failed to send request to master: {} to {}",
@@ -696,7 +701,7 @@
 
             clusterCommunicator.unicast(groupOp,
                     GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST,
-                    m -> kryoBuilder.build().serialize(m),
+                    clusterMsgSerializer::serialize,
                     mastershipService.getMasterFor(deviceId)).whenComplete((result, error) -> {
                         if (error != null) {
                             log.warn("Failed to send request to master: {} to {}",