2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore;
10 import static java.util.Objects.requireNonNull;
12 import java.util.concurrent.atomic.AtomicLong;
13 import org.apache.pekko.actor.AbstractActor.ActorContext;
14 import org.apache.pekko.actor.ActorRef;
15 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
16 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
17 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
21 * A factory for creating ShardTransaction actors.
23 * @author Thomas Pantelis
25 @Deprecated(since = "9.0.0", forRemoval = true)
26 final class ShardTransactionActorFactory {
27 private static final AtomicLong ACTOR_NAME_COUNTER = new AtomicLong();
29 private final ShardDataTree dataTree;
30 private final DatastoreContext datastoreContext;
31 private final String txnDispatcherPath;
32 private final ShardStats shardMBean;
33 private final ActorContext actorContext;
34 private final ActorRef shardActor;
35 private final String shardName;
37 ShardTransactionActorFactory(final ShardDataTree dataTree, final DatastoreContext datastoreContext,
38 final String txnDispatcherPath, final ActorRef shardActor, final ActorContext actorContext,
39 final ShardStats shardMBean, final String shardName) {
40 this.dataTree = requireNonNull(dataTree);
41 this.datastoreContext = requireNonNull(datastoreContext);
42 this.txnDispatcherPath = requireNonNull(txnDispatcherPath);
43 this.shardMBean = requireNonNull(shardMBean);
44 this.actorContext = requireNonNull(actorContext);
45 this.shardActor = requireNonNull(shardActor);
46 this.shardName = requireNonNull(shardName);
49 private String actorNameFor(final TransactionIdentifier txId) {
50 final LocalHistoryIdentifier historyId = txId.getHistoryId();
51 final ClientIdentifier clientId = historyId.getClientId();
52 final FrontendIdentifier frontendId = clientId.getFrontendId();
54 final StringBuilder sb = new StringBuilder("shard-");
55 sb.append(shardName).append('-')
56 .append(frontendId.getMemberName().getName()).append(':')
57 .append(frontendId.getClientType().getName()).append('@')
58 .append(clientId.getGeneration()).append(':');
59 if (historyId.getHistoryId() != 0) {
60 sb.append(historyId.getHistoryId()).append('-');
63 return sb.append(txId.getTransactionId()).append('_').append(ACTOR_NAME_COUNTER.incrementAndGet()).toString();
66 ActorRef newShardTransaction(final TransactionType type, final TransactionIdentifier transactionID) {
67 final AbstractShardDataTreeTransaction<?> transaction = switch (type) {
68 case READ_ONLY -> dataTree.newReadOnlyTransaction(transactionID);
69 case READ_WRITE, WRITE_ONLY -> dataTree.newReadWriteTransaction(transactionID);
70 default -> throw new IllegalArgumentException("Unsupported transaction type " + type);
72 return actorContext.actorOf(ShardTransaction.props(type, transaction, shardActor, datastoreContext, shardMBean)
73 .withDispatcher(txnDispatcherPath), actorNameFor(transactionID));