2b5144aa5ee432e48308f6d9a1968bacc4418817
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / TransactionContextFactory.java
1 /*
2  * Copyright (c) 2015 Cisco 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.ActorSelection;
11 import java.util.Collection;
12 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
13 import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo;
14 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
15 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
17 import scala.concurrent.Future;
18
19 /**
20  * An {@link AbstractTransactionContextFactory} which produces TransactionContext instances for single
21  * transactions (ie not chained).
22  */
23 final class TransactionContextFactory extends AbstractTransactionContextFactory<LocalTransactionFactoryImpl> {
24
25     private TransactionContextFactory(final ActorContext actorContext) {
26         super(actorContext);
27     }
28
29     static TransactionContextFactory create(final ActorContext actorContext) {
30         return new TransactionContextFactory(actorContext);
31     }
32
33     @Override
34     public void close() {
35     }
36
37     @Override
38     protected TransactionIdentifier nextIdentifier() {
39         return TransactionIdentifier.create(getMemberName(), TX_COUNTER.getAndIncrement());
40     }
41
42     @Override
43     protected LocalTransactionFactoryImpl factoryForShard(final String shardName, final ActorSelection shardLeader, final DataTree dataTree) {
44         return new LocalTransactionFactoryImpl(getActorContext(), shardLeader, dataTree);
45     }
46
47     @Override
48     protected Future<PrimaryShardInfo> findPrimaryShard(final String shardName) {
49         return getActorContext().findPrimaryShardAsync(shardName);
50     }
51
52     @Override
53     protected <T> void onTransactionReady(final TransactionIdentifier transaction, final Collection<Future<T>> cohortFutures) {
54         // Transactions are disconnected, this is a no-op
55     }
56
57     DOMStoreTransactionChain createTransactionChain() {
58         return new TransactionChainProxy(this);
59     }
60 }