Remove use of {String,UUID}Identifier
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardTransactionFactory.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore;
9
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;
14
15 /**
16  * A factory for creating ShardTransaction actors.
17  *
18  * @author Thomas Pantelis
19  */
20 class ShardTransactionActorFactory {
21
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;
28
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;
37     }
38
39     ActorRef newShardTransaction(TransactionType type, String transactionID, String transactionChainID) {
40         final AbstractShardDataTreeTransaction<?> transaction;
41         switch (type) {
42         case READ_ONLY:
43             transaction = dataTree.newReadOnlyTransaction(transactionID, transactionChainID);
44             shardMBean.incrementReadOnlyTransactionCount();
45             break;
46         case READ_WRITE:
47             transaction = dataTree.newReadWriteTransaction(transactionID, transactionChainID);
48             shardMBean.incrementReadWriteTransactionCount();
49             break;
50         case WRITE_ONLY:
51             transaction = dataTree.newReadWriteTransaction(transactionID, transactionChainID);
52             shardMBean.incrementWriteOnlyTransactionCount();
53             break;
54         default:
55             throw new IllegalArgumentException("Unsupported transaction type " + type);
56         }
57
58         return actorContext.actorOf(ShardTransaction.props(type, transaction, shardActor, datastoreContext, shardMBean)
59             .withDispatcher(txnDispatcherPath), "shard-" + transactionID);
60     }
61 }