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.ClientIdentifier;
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 * Standalone transaction specialization of {@link AbstractFrontendHistory}. There can be multiple open transactions
26 * and they are submitted in any order.
28 * @author Robert Varga
30 final class StandaloneFrontendHistory extends AbstractFrontendHistory {
31 private final LocalHistoryIdentifier identifier;
32 private final ShardDataTree tree;
34 private StandaloneFrontendHistory(final String persistenceId, final ClientIdentifier clientId,
35 final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
36 final RangeSet<UnsignedLong> purgedTransactions) {
37 super(persistenceId, tree, closedTransactions, purgedTransactions);
38 this.identifier = new LocalHistoryIdentifier(clientId, 0);
39 this.tree = Preconditions.checkNotNull(tree);
42 static StandaloneFrontendHistory create(final String persistenceId, final ClientIdentifier clientId,
43 final ShardDataTree tree) {
44 return new StandaloneFrontendHistory(persistenceId, clientId, tree, ImmutableMap.of(),
45 TreeRangeSet.create());
48 static StandaloneFrontendHistory recreate(final String persistenceId, final ClientIdentifier clientId,
49 final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
50 final RangeSet<UnsignedLong> purgedTransactions) {
51 return new StandaloneFrontendHistory(persistenceId, clientId, tree, new HashMap<>(closedTransactions),
56 public LocalHistoryIdentifier getIdentifier() {
61 FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) {
62 return FrontendReadOnlyTransaction.create(this, tree.newReadOnlyTransaction(id));
66 FrontendTransaction createOpenTransaction(final TransactionIdentifier id) {
67 return FrontendReadWriteTransaction.createOpen(this, tree.newReadWriteTransaction(id));
71 FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod) {
72 return FrontendReadWriteTransaction.createReady(this, id, mod);
76 ShardDataTreeCohort createFailedCohort(final TransactionIdentifier id, final DataTreeModification mod,
77 final Exception failure) {
78 return tree.createFailedCohort(id, mod, failure);
82 ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod,
83 final Optional<SortedSet<String>> participatingShardNames) {
84 return tree.createReadyCohort(id, mod, participatingShardNames);