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.MutableUnsignedLongSet;
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 @NonNull LocalHistoryIdentifier identifier;
33 private final @NonNull ShardDataTree tree;
35 private StandaloneFrontendHistory(final String persistenceId, final ClientIdentifier clientId,
36 final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
37 final MutableUnsignedLongSet 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(),
46 MutableUnsignedLongSet.of());
49 static @NonNull StandaloneFrontendHistory recreate(final String persistenceId, final ClientIdentifier clientId,
50 final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
51 final MutableUnsignedLongSet purgedTransactions) {
52 return new StandaloneFrontendHistory(persistenceId, clientId, tree, new HashMap<>(closedTransactions),
53 purgedTransactions.mutableCopy());
57 public LocalHistoryIdentifier getIdentifier() {
62 FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) {
63 return FrontendReadOnlyTransaction.create(this, tree.newReadOnlyTransaction(id));
67 FrontendTransaction createOpenTransaction(final TransactionIdentifier id) {
68 return FrontendReadWriteTransaction.createOpen(this, tree.newReadWriteTransaction(id));
72 FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod) {
73 return FrontendReadWriteTransaction.createReady(this, id, mod);
77 ShardDataTreeCohort createFailedCohort(final TransactionIdentifier id, final DataTreeModification mod,
78 final Exception failure) {
79 return tree.createFailedCohort(id, mod, failure);
83 ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod,
84 final Optional<SortedSet<String>> participatingShardNames) {
85 return tree.createReadyCohort(id, mod, participatingShardNames);