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 org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.RequestException;
19 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
24 * Chained transaction specialization of {@link AbstractFrontendHistory}. It prevents concurrent open transactions.
26 * @author Robert Varga
28 final class LocalFrontendHistory extends AbstractFrontendHistory {
29 private final ShardDataTreeTransactionChain chain;
31 private LocalFrontendHistory(final String persistenceId, final ShardDataTree tree,
32 final ShardDataTreeTransactionChain chain, final Map<UnsignedLong, Boolean> closedTransactions,
33 final RangeSet<UnsignedLong> purgedTransactions) {
34 super(persistenceId, tree, closedTransactions, purgedTransactions);
35 this.chain = Preconditions.checkNotNull(chain);
38 static LocalFrontendHistory create(final String persistenceId, final ShardDataTree tree,
39 final LocalHistoryIdentifier historyId) {
40 return new LocalFrontendHistory(persistenceId, tree, tree.ensureTransactionChain(historyId), ImmutableMap.of(),
41 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) throws RequestException {
58 return FrontendReadOnlyTransaction.create(this, chain.newReadOnlyTransaction(id));
62 FrontendTransaction createOpenTransaction(final TransactionIdentifier id) throws RequestException {
63 return FrontendReadWriteTransaction.createOpen(this, chain.newReadWriteTransaction(id));
67 FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod)
68 throws RequestException {
69 return FrontendReadWriteTransaction.createReady(this, id, mod);
73 ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod) {
74 return chain.createReadyCohort(id, mod);