Move byte-based serialization method
[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.collect.RangeSet;
14 import com.google.common.collect.TreeRangeSet;
15 import com.google.common.primitives.UnsignedLong;
16 import java.util.HashMap;
17 import java.util.Map;
18 import java.util.Optional;
19 import java.util.SortedSet;
20 import org.eclipse.jdt.annotation.NonNull;
21 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
22 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
23 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
25
26 /**
27  * Standalone transaction specialization of {@link AbstractFrontendHistory}. There can be multiple open transactions
28  * and they are submitted in any order.
29  *
30  * @author Robert Varga
31  */
32 final class StandaloneFrontendHistory extends AbstractFrontendHistory {
33     private final LocalHistoryIdentifier identifier;
34     private final ShardDataTree tree;
35
36     private StandaloneFrontendHistory(final String persistenceId, final ClientIdentifier clientId,
37             final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
38             final RangeSet<UnsignedLong> purgedTransactions) {
39         super(persistenceId, tree, closedTransactions, purgedTransactions);
40         this.identifier = new LocalHistoryIdentifier(clientId, 0);
41         this.tree = requireNonNull(tree);
42     }
43
44     static @NonNull StandaloneFrontendHistory create(final String persistenceId, final ClientIdentifier clientId,
45             final ShardDataTree tree) {
46         return new StandaloneFrontendHistory(persistenceId, clientId, tree, ImmutableMap.of(),
47             TreeRangeSet.create());
48     }
49
50     static @NonNull StandaloneFrontendHistory recreate(final String persistenceId, final ClientIdentifier clientId,
51             final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
52             final RangeSet<UnsignedLong> purgedTransactions) {
53         return new StandaloneFrontendHistory(persistenceId, clientId, tree, new HashMap<>(closedTransactions),
54             purgedTransactions);
55     }
56
57     @Override
58     public LocalHistoryIdentifier getIdentifier() {
59         return identifier;
60     }
61
62     @Override
63     FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) {
64         return FrontendReadOnlyTransaction.create(this, tree.newReadOnlyTransaction(id));
65     }
66
67     @Override
68     FrontendTransaction createOpenTransaction(final TransactionIdentifier id) {
69         return FrontendReadWriteTransaction.createOpen(this, tree.newReadWriteTransaction(id));
70     }
71
72     @Override
73     FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod) {
74         return FrontendReadWriteTransaction.createReady(this, id, mod);
75     }
76
77     @Override
78     ShardDataTreeCohort createFailedCohort(final TransactionIdentifier id, final DataTreeModification mod,
79             final Exception failure) {
80         return tree.createFailedCohort(id, mod, failure);
81     }
82
83     @Override
84     ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod,
85             final Optional<SortedSet<String>> participatingShardNames) {
86         return tree.createReadyCohort(id, mod, participatingShardNames);
87     }
88 }