Relax visibility on FrontendReadWriteTransaction methods
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / StandaloneFrontendHistory.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore;
9
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;
16 import java.util.Map;
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;
22
23 /**
24  * Standalone transaction specialization of {@link AbstractFrontendHistory}. There can be multiple open transactions
25  * and they are submitted in any order.
26  *
27  * @author Robert Varga
28  */
29 final class StandaloneFrontendHistory extends AbstractFrontendHistory {
30     private final LocalHistoryIdentifier identifier;
31     private final ShardDataTree tree;
32
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);
39     }
40
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());
45     }
46
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),
51             purgedTransactions);
52     }
53
54     @Override
55     public LocalHistoryIdentifier getIdentifier() {
56         return identifier;
57     }
58
59     @Override
60     FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) throws RequestException {
61         return FrontendReadOnlyTransaction.create(this, tree.newReadOnlyTransaction(id));
62     }
63
64     @Override
65     FrontendTransaction createOpenTransaction(final TransactionIdentifier id) throws RequestException {
66         return FrontendReadWriteTransaction.createOpen(this, tree.newReadWriteTransaction(id));
67     }
68
69     @Override
70     FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod)
71             throws RequestException {
72         return FrontendReadWriteTransaction.createReady(this, id, mod);
73     }
74
75     @Override
76     ShardDataTreeCohort createFailedCohort(final TransactionIdentifier id, final DataTreeModification mod,
77             final Exception failure) {
78         return tree.createFailedCohort(id, mod, failure);
79     }
80
81     @Override
82     ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod) {
83         return tree.createReadyCohort(id, mod);
84     }
85 }