2 * Copyright (c) 2016 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 static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableMap;
13 import com.google.common.collect.RangeSet;
14 import com.google.common.collect.TreeRangeSet;
15 import com.google.common.primitives.UnsignedLong;
16 import java.util.HashMap;
18 import java.util.Optional;
19 import java.util.SortedSet;
20 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
21 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
25 * Chained transaction specialization of {@link AbstractFrontendHistory}. It prevents concurrent open transactions.
27 * @author Robert Varga
29 final class LocalFrontendHistory extends AbstractFrontendHistory {
30 private final ShardDataTreeTransactionChain chain;
32 private LocalFrontendHistory(final String persistenceId, final ShardDataTree tree,
33 final ShardDataTreeTransactionChain chain, final Map<UnsignedLong, Boolean> closedTransactions,
34 final RangeSet<UnsignedLong> purgedTransactions) {
35 super(persistenceId, tree, closedTransactions, purgedTransactions);
36 this.chain = requireNonNull(chain);
39 static LocalFrontendHistory create(final String persistenceId, final ShardDataTree tree,
40 final ShardDataTreeTransactionChain chain) {
41 return new LocalFrontendHistory(persistenceId, tree, chain, ImmutableMap.of(), TreeRangeSet.create());
44 static LocalFrontendHistory recreate(final String persistenceId, final ShardDataTree tree,
45 final ShardDataTreeTransactionChain chain, final Map<UnsignedLong, Boolean> closedTransactions,
46 final RangeSet<UnsignedLong> purgedTransactions) {
47 return new LocalFrontendHistory(persistenceId, tree, chain, new HashMap<>(closedTransactions),
48 TreeRangeSet.create(purgedTransactions));
52 public LocalHistoryIdentifier getIdentifier() {
53 return chain.getIdentifier();
57 FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) {
58 return FrontendReadOnlyTransaction.create(this, chain.newReadOnlyTransaction(id));
62 FrontendTransaction createOpenTransaction(final TransactionIdentifier id) {
63 return FrontendReadWriteTransaction.createOpen(this, chain.newReadWriteTransaction(id));
67 FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod) {
68 return FrontendReadWriteTransaction.createReady(this, id, mod);
72 ShardDataTreeCohort createFailedCohort(final TransactionIdentifier id, final DataTreeModification mod,
73 final Exception failure) {
74 return chain.createFailedCohort(id, mod, failure);
78 ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod,
79 final Optional<SortedSet<String>> participatingShardNames) {
80 return chain.createReadyCohort(id, mod, participatingShardNames);