Fixup checkstyle
[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 static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ImmutableMap;
13 import com.google.common.primitives.UnsignedLong;
14 import java.util.HashMap;
15 import java.util.Map;
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.tree.api.DataTreeModification;
24
25 /**
26  * Standalone transaction specialization of {@link AbstractFrontendHistory}. There can be multiple open transactions
27  * and they are submitted in any order.
28  *
29  * @author Robert Varga
30  */
31 final class StandaloneFrontendHistory extends AbstractFrontendHistory {
32     private final @NonNull LocalHistoryIdentifier identifier;
33     private final @NonNull ShardDataTree tree;
34
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);
41     }
42
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());
47     }
48
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());
54     }
55
56     @Override
57     public LocalHistoryIdentifier getIdentifier() {
58         return identifier;
59     }
60
61     @Override
62     FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) {
63         return FrontendReadOnlyTransaction.create(this, tree.newStandaloneReadOnlyTransaction(id));
64     }
65
66     @Override
67     FrontendTransaction createOpenTransaction(final TransactionIdentifier id) {
68         return FrontendReadWriteTransaction.createOpen(this, tree.newStandaloneReadWriteTransaction(id));
69     }
70
71     @Override
72     FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod) {
73         return FrontendReadWriteTransaction.createReady(this, id, mod);
74     }
75
76     @Override
77     ShardDataTreeCohort createFailedCohort(final TransactionIdentifier id, final DataTreeModification mod,
78             final Exception failure) {
79         return tree.createFailedCohort(id, mod, failure);
80     }
81
82     @Override
83     ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod,
84             final Optional<SortedSet<String>> participatingShardNames) {
85         return tree.createReadyCohort(id, mod, participatingShardNames);
86     }
87 }