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.RequestException;
22 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
26 * Standalone transaction specialization of {@link AbstractFrontendHistory}. There can be multiple open transactions
27 * and they are submitted in any order.
29 * @author Robert Varga
31 final class StandaloneFrontendHistory extends AbstractFrontendHistory {
32 private final LocalHistoryIdentifier identifier;
33 private final ShardDataTree tree;
35 private StandaloneFrontendHistory(final String persistenceId, final ClientIdentifier clientId,
36 final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
37 final RangeSet<UnsignedLong> purgedTransactions) {
38 super(persistenceId, tree, closedTransactions, purgedTransactions);
39 this.identifier = new LocalHistoryIdentifier(clientId, 0);
40 this.tree = Preconditions.checkNotNull(tree);
43 static StandaloneFrontendHistory create(final String persistenceId, final ClientIdentifier clientId,
44 final ShardDataTree tree) {
45 return new StandaloneFrontendHistory(persistenceId, clientId, tree, ImmutableMap.of(),
46 TreeRangeSet.create());
49 static StandaloneFrontendHistory recreate(final String persistenceId, final ClientIdentifier clientId,
50 final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
51 final RangeSet<UnsignedLong> purgedTransactions) {
52 return new StandaloneFrontendHistory(persistenceId, clientId, tree, new HashMap<>(closedTransactions),
57 public LocalHistoryIdentifier getIdentifier() {
62 FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) throws RequestException {
63 return FrontendReadOnlyTransaction.create(this, tree.newReadOnlyTransaction(id));
67 FrontendTransaction createOpenTransaction(final TransactionIdentifier id) throws RequestException {
68 return FrontendReadWriteTransaction.createOpen(this, tree.newReadWriteTransaction(id));
72 FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod)
73 throws RequestException {
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);