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.identifiers.ShardTransactionIdentifier;
14 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
17 * A factory for creating ShardTransaction actors.
19 * @author Thomas Pantelis
21 class ShardTransactionActorFactory {
23 private final ShardDataTree dataTree;
24 private final DatastoreContext datastoreContext;
25 private final String txnDispatcherPath;
26 private final ShardStats shardMBean;
27 private final UntypedActorContext actorContext;
28 private final ActorRef shardActor;
30 ShardTransactionActorFactory(ShardDataTree dataTree, DatastoreContext datastoreContext,
31 String txnDispatcherPath, ActorRef shardActor, UntypedActorContext actorContext, ShardStats shardMBean) {
32 this.dataTree = Preconditions.checkNotNull(dataTree);
33 this.datastoreContext = datastoreContext;
34 this.txnDispatcherPath = txnDispatcherPath;
35 this.shardMBean = shardMBean;
36 this.actorContext = actorContext;
37 this.shardActor = shardActor;
40 ActorRef newShardTransaction(TransactionType type, ShardTransactionIdentifier transactionID,
41 String transactionChainID) {
42 final AbstractShardDataTreeTransaction<?> transaction;
45 transaction = dataTree.newReadOnlyTransaction(transactionID.toString(), transactionChainID);
46 shardMBean.incrementReadOnlyTransactionCount();
49 transaction = dataTree.newReadWriteTransaction(transactionID.toString(), transactionChainID);
50 shardMBean.incrementReadWriteTransactionCount();
53 transaction = dataTree.newReadWriteTransaction(transactionID.toString(), transactionChainID);
54 shardMBean.incrementWriteOnlyTransactionCount();
57 throw new IllegalArgumentException("Unsupported transaction type " + type);
60 return actorContext.actorOf(ShardTransaction.props(type, transaction, shardActor, datastoreContext, shardMBean,
61 transactionID.getRemoteTransactionId()).withDispatcher(txnDispatcherPath),
62 transactionID.toString());