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 org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
19 import org.opendaylight.controller.cluster.access.concepts.RequestException;
20 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
24 * Standalone transaction specialization of {@link AbstractFrontendHistory}. There can be multiple open transactions
25 * and they are submitted in any order.
27 * @author Robert Varga
29 final class StandaloneFrontendHistory extends AbstractFrontendHistory {
30 private final LocalHistoryIdentifier identifier;
31 private final ShardDataTree tree;
33 private StandaloneFrontendHistory(final String persistenceId, final ClientIdentifier clientId,
34 final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
35 final RangeSet<UnsignedLong> purgedTransactions) {
36 super(persistenceId, tree, closedTransactions, purgedTransactions);
37 this.identifier = new LocalHistoryIdentifier(clientId, 0);
38 this.tree = Preconditions.checkNotNull(tree);
41 static StandaloneFrontendHistory create(final String persistenceId, final ClientIdentifier clientId,
42 final ShardDataTree tree) {
43 return new StandaloneFrontendHistory(persistenceId, clientId, tree, ImmutableMap.of(),
44 TreeRangeSet.create());
47 static StandaloneFrontendHistory recreate(final String persistenceId, final ClientIdentifier clientId,
48 final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
49 final RangeSet<UnsignedLong> purgedTransactions) {
50 return new StandaloneFrontendHistory(persistenceId, clientId, tree, new HashMap<>(closedTransactions),
55 public LocalHistoryIdentifier getIdentifier() {
60 FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) throws RequestException {
61 return FrontendReadOnlyTransaction.create(this, tree.newReadOnlyTransaction(id));
65 FrontendTransaction createOpenTransaction(final TransactionIdentifier id) throws RequestException {
66 return FrontendReadWriteTransaction.createOpen(this, tree.newReadWriteTransaction(id));
70 FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod)
71 throws RequestException {
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 return tree.createReadyCohort(id, mod);