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.eclipse.jdt.annotation.NonNull;
21 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
22 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
23 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
27 * Standalone transaction specialization of {@link AbstractFrontendHistory}. There can be multiple open transactions
28 * and they are submitted in any order.
30 * @author Robert Varga
32 final class StandaloneFrontendHistory extends AbstractFrontendHistory {
33 private final LocalHistoryIdentifier identifier;
34 private final ShardDataTree tree;
36 private StandaloneFrontendHistory(final String persistenceId, final ClientIdentifier clientId,
37 final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
38 final RangeSet<UnsignedLong> purgedTransactions) {
39 super(persistenceId, tree, closedTransactions, purgedTransactions);
40 this.identifier = new LocalHistoryIdentifier(clientId, 0);
41 this.tree = requireNonNull(tree);
44 static @NonNull StandaloneFrontendHistory create(final String persistenceId, final ClientIdentifier clientId,
45 final ShardDataTree tree) {
46 return new StandaloneFrontendHistory(persistenceId, clientId, tree, ImmutableMap.of(),
47 TreeRangeSet.create());
50 static @NonNull StandaloneFrontendHistory recreate(final String persistenceId, final ClientIdentifier clientId,
51 final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
52 final RangeSet<UnsignedLong> purgedTransactions) {
53 return new StandaloneFrontendHistory(persistenceId, clientId, tree, new HashMap<>(closedTransactions),
58 public LocalHistoryIdentifier getIdentifier() {
63 FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) {
64 return FrontendReadOnlyTransaction.create(this, tree.newReadOnlyTransaction(id));
68 FrontendTransaction createOpenTransaction(final TransactionIdentifier id) {
69 return FrontendReadWriteTransaction.createOpen(this, tree.newReadWriteTransaction(id));
73 FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod) {
74 return FrontendReadWriteTransaction.createReady(this, id, mod);
78 ShardDataTreeCohort createFailedCohort(final TransactionIdentifier id, final DataTreeModification mod,
79 final Exception failure) {
80 return tree.createFailedCohort(id, mod, failure);
84 ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod,
85 final Optional<SortedSet<String>> participatingShardNames) {
86 return tree.createReadyCohort(id, mod, participatingShardNames);