*/
package org.opendaylight.controller.cluster.datastore;
+import static java.util.Objects.requireNonNull;
+
+import akka.actor.AbstractActor.ActorContext;
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;
* @author Thomas Pantelis
*/
class ShardTransactionActorFactory {
+ private static final AtomicLong ACTOR_NAME_COUNTER = new AtomicLong();
private final ShardDataTree dataTree;
private final DatastoreContext datastoreContext;
private final String txnDispatcherPath;
private final ShardStats shardMBean;
- private final UntypedActorContext actorContext;
+ private final ActorContext actorContext;
private final ActorRef shardActor;
+ private final String shardName;
ShardTransactionActorFactory(ShardDataTree dataTree, DatastoreContext datastoreContext,
- String txnDispatcherPath, ActorRef shardActor, UntypedActorContext actorContext, ShardStats shardMBean) {
- this.dataTree = Preconditions.checkNotNull(dataTree);
- this.datastoreContext = datastoreContext;
- this.txnDispatcherPath = txnDispatcherPath;
- this.shardMBean = shardMBean;
- this.actorContext = actorContext;
- this.shardActor = shardActor;
+ String txnDispatcherPath, ActorRef shardActor, ActorContext actorContext, ShardStats shardMBean,
+ String shardName) {
+ this.dataTree = requireNonNull(dataTree);
+ this.datastoreContext = requireNonNull(datastoreContext);
+ this.txnDispatcherPath = requireNonNull(txnDispatcherPath);
+ this.shardMBean = requireNonNull(shardMBean);
+ this.actorContext = requireNonNull(actorContext);
+ this.shardActor = requireNonNull(shardActor);
+ this.shardName = requireNonNull(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) {
switch (type) {
case READ_ONLY:
transaction = dataTree.newReadOnlyTransaction(transactionID);
- shardMBean.incrementReadOnlyTransactionCount();
break;
case READ_WRITE:
- transaction = dataTree.newReadWriteTransaction(transactionID);
- shardMBean.incrementReadWriteTransactionCount();
- break;
case WRITE_ONLY:
transaction = dataTree.newReadWriteTransaction(transactionID);
- shardMBean.incrementWriteOnlyTransactionCount();
break;
default:
throw new IllegalArgumentException("Unsupported transaction type " + type);