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 com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableMap;
12 import com.google.common.collect.RangeSet;
13 import com.google.common.collect.TreeRangeSet;
14 import com.google.common.primitives.UnsignedLong;
15 import java.util.HashMap;
17 import java.util.Optional;
18 import java.util.SortedSet;
19 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
20 import org.opendaylight.controller.cluster.access.concepts.RequestException;
21 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
26 * Chained transaction specialization of {@link AbstractFrontendHistory}. It prevents concurrent open transactions.
28 * @author Robert Varga
30 final class LocalFrontendHistory extends AbstractFrontendHistory {
31 private final ShardDataTreeTransactionChain chain;
33 private LocalFrontendHistory(final String persistenceId, final ShardDataTree tree,
34 final ShardDataTreeTransactionChain chain, final Map<UnsignedLong, Boolean> closedTransactions,
35 final RangeSet<UnsignedLong> purgedTransactions) {
36 super(persistenceId, tree, closedTransactions, purgedTransactions);
37 this.chain = Preconditions.checkNotNull(chain);
40 static LocalFrontendHistory create(final String persistenceId, final ShardDataTree tree,
41 final ShardDataTreeTransactionChain chain) {
42 return new LocalFrontendHistory(persistenceId, tree, chain, ImmutableMap.of(), TreeRangeSet.create());
45 static LocalFrontendHistory recreate(final String persistenceId, final ShardDataTree tree,
46 final ShardDataTreeTransactionChain chain, final Map<UnsignedLong, Boolean> closedTransactions,
47 final RangeSet<UnsignedLong> purgedTransactions) {
48 return new LocalFrontendHistory(persistenceId, tree, chain, new HashMap<>(closedTransactions),
49 TreeRangeSet.create(purgedTransactions));
53 public LocalHistoryIdentifier getIdentifier() {
54 return chain.getIdentifier();
58 FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) throws RequestException {
59 return FrontendReadOnlyTransaction.create(this, chain.newReadOnlyTransaction(id));
63 FrontendTransaction createOpenTransaction(final TransactionIdentifier id) throws RequestException {
64 return FrontendReadWriteTransaction.createOpen(this, chain.newReadWriteTransaction(id));
68 FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod)
69 throws RequestException {
70 return FrontendReadWriteTransaction.createReady(this, id, mod);
74 ShardDataTreeCohort createFailedCohort(final TransactionIdentifier id, final DataTreeModification mod,
75 final Exception failure) {
76 return chain.createFailedCohort(id, mod, failure);
80 ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod,
81 final Optional<SortedSet<String>> participatingShardNames) {
82 return chain.createReadyCohort(id, mod, participatingShardNames);