Bug 7521: Convert byte[] to ShardManagerSnapshot in DatastoreSnapshot
[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.base.Ticker;
12 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
13 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
14 import org.opendaylight.controller.cluster.access.concepts.RequestException;
15 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
17
18 /**
19  * Standalone transaction specialization of {@link AbstractFrontendHistory}. There can be multiple open transactions
20  * and they are submitted in any order.
21  *
22  * @author Robert Varga
23  */
24 final class StandaloneFrontendHistory extends AbstractFrontendHistory {
25     private final LocalHistoryIdentifier identifier;
26     private final ShardDataTree tree;
27
28     StandaloneFrontendHistory(final String persistenceId, final Ticker ticker, final ClientIdentifier clientId,
29             final ShardDataTree tree) {
30         super(persistenceId, ticker);
31         this.identifier = new LocalHistoryIdentifier(clientId, 0);
32         this.tree = Preconditions.checkNotNull(tree);
33     }
34
35     @Override
36     public LocalHistoryIdentifier getIdentifier() {
37         return identifier;
38     }
39
40     @Override
41     FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) throws RequestException {
42         return FrontendReadOnlyTransaction.create(this, tree.newReadOnlyTransaction(id));
43     }
44
45     @Override
46     FrontendTransaction createOpenTransaction(final TransactionIdentifier id) throws RequestException {
47         return FrontendReadWriteTransaction.createOpen(this, tree.newReadWriteTransaction(id));
48     }
49
50     @Override
51     FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod)
52             throws RequestException {
53         return FrontendReadWriteTransaction.createReady(this, id, mod);
54     }
55
56     @Override
57     ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod) {
58         return tree.createReadyCohort(id, mod);
59     }
60 }