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.primitives.UnsignedLong;
14 import java.util.HashMap;
16 import java.util.Optional;
17 import java.util.SortedSet;
18 import org.eclipse.jdt.annotation.NonNull;
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.controller.cluster.datastore.utils.UnsignedLongSet;
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 UnsignedLongSet purgedTransactions) {
38 super(persistenceId, tree, closedTransactions, purgedTransactions);
39 identifier = new LocalHistoryIdentifier(clientId, 0);
40 this.tree = requireNonNull(tree);
43 static @NonNull StandaloneFrontendHistory create(final String persistenceId, final ClientIdentifier clientId,
44 final ShardDataTree tree) {
45 return new StandaloneFrontendHistory(persistenceId, clientId, tree, ImmutableMap.of(), UnsignedLongSet.of());
48 static @NonNull StandaloneFrontendHistory recreate(final String persistenceId, final ClientIdentifier clientId,
49 final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
50 final UnsignedLongSet purgedTransactions) {
51 return new StandaloneFrontendHistory(persistenceId, clientId, tree, new HashMap<>(closedTransactions),
52 purgedTransactions.copy());
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);