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 akka.actor.ActorRef;
11 import akka.actor.UntypedActorContext;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
16 * A factory for creating ShardTransaction actors.
18 * @author Thomas Pantelis
20 class ShardTransactionActorFactory {
22 private final ShardDataTree dataTree;
23 private final DatastoreContext datastoreContext;
24 private final String txnDispatcherPath;
25 private final ShardStats shardMBean;
26 private final UntypedActorContext actorContext;
27 private final ActorRef shardActor;
29 ShardTransactionActorFactory(ShardDataTree dataTree, DatastoreContext datastoreContext,
30 String txnDispatcherPath, ActorRef shardActor, UntypedActorContext actorContext, ShardStats shardMBean) {
31 this.dataTree = Preconditions.checkNotNull(dataTree);
32 this.datastoreContext = datastoreContext;
33 this.txnDispatcherPath = txnDispatcherPath;
34 this.shardMBean = shardMBean;
35 this.actorContext = actorContext;
36 this.shardActor = shardActor;
39 ActorRef newShardTransaction(TransactionType type, String transactionID, String transactionChainID) {
40 final AbstractShardDataTreeTransaction<?> transaction;
43 transaction = dataTree.newReadOnlyTransaction(transactionID, transactionChainID);
44 shardMBean.incrementReadOnlyTransactionCount();
47 transaction = dataTree.newReadWriteTransaction(transactionID, transactionChainID);
48 shardMBean.incrementReadWriteTransactionCount();
51 transaction = dataTree.newReadWriteTransaction(transactionID, transactionChainID);
52 shardMBean.incrementWriteOnlyTransactionCount();
55 throw new IllegalArgumentException("Unsupported transaction type " + type);
58 return actorContext.actorOf(ShardTransaction.props(type, transaction, shardActor, datastoreContext, shardMBean)
59 .withDispatcher(txnDispatcherPath), "shard-" + transactionID);