Cleanup warnings
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardTransactionActorFactory.java
index 0ba36640a8f6368451478d0f28451a2c7a437db4..74c75dc2542b1e5b31370786874e74cfd1dc72bf 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.cluster.datastore;
 import akka.actor.ActorRef;
 import akka.actor.UntypedActorContext;
 import com.google.common.base.Preconditions;
+import java.util.concurrent.atomic.AtomicLong;
 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
@@ -22,6 +23,7 @@ import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats
  * @author Thomas Pantelis
  */
 class ShardTransactionActorFactory {
+    private static final AtomicLong ACTOR_NAME_COUNTER = new AtomicLong();
 
     private final ShardDataTree dataTree;
     private final DatastoreContext datastoreContext;
@@ -29,31 +31,35 @@ class ShardTransactionActorFactory {
     private final ShardStats shardMBean;
     private final UntypedActorContext actorContext;
     private final ActorRef shardActor;
+    private final String shardName;
 
     ShardTransactionActorFactory(ShardDataTree dataTree, DatastoreContext datastoreContext,
-            String txnDispatcherPath, ActorRef shardActor, UntypedActorContext actorContext, ShardStats shardMBean) {
+            String txnDispatcherPath, ActorRef shardActor, UntypedActorContext actorContext, ShardStats shardMBean,
+            String shardName) {
         this.dataTree = Preconditions.checkNotNull(dataTree);
-        this.datastoreContext = datastoreContext;
-        this.txnDispatcherPath = txnDispatcherPath;
-        this.shardMBean = shardMBean;
-        this.actorContext = actorContext;
-        this.shardActor = shardActor;
+        this.datastoreContext = Preconditions.checkNotNull(datastoreContext);
+        this.txnDispatcherPath = Preconditions.checkNotNull(txnDispatcherPath);
+        this.shardMBean = Preconditions.checkNotNull(shardMBean);
+        this.actorContext = Preconditions.checkNotNull(actorContext);
+        this.shardActor = Preconditions.checkNotNull(shardActor);
+        this.shardName = Preconditions.checkNotNull(shardName);
     }
 
-    private static String actorNameFor(final TransactionIdentifier txId) {
+    private String actorNameFor(final TransactionIdentifier txId) {
         final LocalHistoryIdentifier historyId = txId.getHistoryId();
         final ClientIdentifier clientId = historyId.getClientId();
         final FrontendIdentifier frontendId = clientId.getFrontendId();
 
         final StringBuilder sb = new StringBuilder("shard-");
-        sb.append(frontendId.getMemberName().getName()).append(':');
-        sb.append(frontendId.getClientType().getName()).append('@');
-        sb.append(clientId.getGeneration()).append(':');
+        sb.append(shardName).append('-')
+            .append(frontendId.getMemberName().getName()).append(':')
+            .append(frontendId.getClientType().getName()).append('@')
+            .append(clientId.getGeneration()).append(':');
         if (historyId.getHistoryId() != 0) {
             sb.append(historyId.getHistoryId()).append('-');
         }
 
-        return sb.append(txId.getTransactionId()).toString();
+        return sb.append(txId.getTransactionId()).append('_').append(ACTOR_NAME_COUNTER.incrementAndGet()).toString();
     }
 
     ActorRef newShardTransaction(TransactionType type, TransactionIdentifier transactionID) {