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