Do not leak DataTree from backend actor
[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 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.ActorUtils;
18 import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.ReadOnlyDataTree;
20 import scala.concurrent.Future;
21
22 /**
23  * An {@link AbstractTransactionContextFactory} which produces TransactionContext instances for single
24  * transactions (ie not chained).
25  */
26 final class TransactionContextFactory extends AbstractTransactionContextFactory<LocalTransactionFactoryImpl> {
27     private final AtomicLong nextHistory = new AtomicLong(1);
28
29     TransactionContextFactory(final ActorUtils actorUtils, final ClientIdentifier clientId) {
30         super(actorUtils, new LocalHistoryIdentifier(clientId, 0));
31     }
32
33     @Override
34     public void close() {
35     }
36
37     @Override
38     protected LocalTransactionFactoryImpl factoryForShard(final String shardName, final ActorSelection shardLeader,
39             final ReadOnlyDataTree dataTree) {
40         return new LocalTransactionFactoryImpl(getActorUtils(), shardLeader, dataTree);
41     }
42
43     @Override
44     protected Future<PrimaryShardInfo> findPrimaryShard(final String shardName, TransactionIdentifier txId) {
45         return getActorUtils().findPrimaryShardAsync(shardName);
46     }
47
48     @Override
49     protected <T> void onTransactionReady(final TransactionIdentifier transaction,
50             final Collection<Future<T>> cohortFutures) {
51         // Transactions are disconnected, this is a no-op
52     }
53
54     DOMStoreTransactionChain createTransactionChain() {
55         return new TransactionChainProxy(this, new LocalHistoryIdentifier(getHistoryId().getClientId(),
56                 nextHistory.getAndIncrement()));
57     }
58
59     @Override
60     protected void onTransactionContextCreated(final TransactionIdentifier transactionId) {
61     }
62 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.