2 * Copyright (c) 2015 Cisco 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.ActorSelection;
11 import java.util.Collection;
12 import java.util.concurrent.atomic.AtomicLong;
13 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
14 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
15 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
16 import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo;
17 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
20 import scala.concurrent.Future;
23 * An {@link AbstractTransactionContextFactory} which produces TransactionContext instances for single
24 * transactions (ie not chained).
26 final class TransactionContextFactory extends AbstractTransactionContextFactory<LocalTransactionFactoryImpl> {
27 private final AtomicLong nextHistory = new AtomicLong(1);
29 TransactionContextFactory(final ActorContext actorContext, final ClientIdentifier clientId) {
30 super(actorContext, new LocalHistoryIdentifier(clientId, 0));
38 protected LocalTransactionFactoryImpl factoryForShard(final String shardName, final ActorSelection shardLeader,
39 final DataTree dataTree) {
40 return new LocalTransactionFactoryImpl(getActorContext(), shardLeader, dataTree);
44 protected Future<PrimaryShardInfo> findPrimaryShard(final String shardName, TransactionIdentifier txId) {
45 return getActorContext().findPrimaryShardAsync(shardName);
49 protected <T> void onTransactionReady(final TransactionIdentifier transaction,
50 final Collection<Future<T>> cohortFutures) {
51 // Transactions are disconnected, this is a no-op
54 DOMStoreTransactionChain createTransactionChain() {
55 return new TransactionChainProxy(this, new LocalHistoryIdentifier(getHistoryId().getClientId(),
56 nextHistory.getAndIncrement()));
60 protected void onTransactionContextCreated(final TransactionIdentifier transactionId) {