Unit tests for ClientBackedDataStore class
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / ClientBackedDataStore.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.databroker;
9
10 import akka.actor.ActorSystem;
11 import com.google.common.annotations.VisibleForTesting;
12 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
13 import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
14 import org.opendaylight.controller.cluster.datastore.AbstractDataStore;
15 import org.opendaylight.controller.cluster.datastore.ClusterWrapper;
16 import org.opendaylight.controller.cluster.datastore.DatastoreContextFactory;
17 import org.opendaylight.controller.cluster.datastore.config.Configuration;
18 import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot;
19 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
20 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
21 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
22 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
23 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
24
25 /**
26  * Implements a distributed DOMStore using ClientActor.
27  */
28 public class ClientBackedDataStore extends AbstractDataStore {
29
30     public ClientBackedDataStore(final ActorSystem actorSystem, final ClusterWrapper cluster,
31             final Configuration configuration, final DatastoreContextFactory datastoreContextFactory,
32             final DatastoreSnapshot restoreFromSnapshot) {
33         super(actorSystem, cluster, configuration, datastoreContextFactory, restoreFromSnapshot);
34     }
35
36     @VisibleForTesting
37     ClientBackedDataStore(final ActorContext actorContext, final ClientIdentifier identifier,
38                           final DataStoreClient clientActor) {
39         super(actorContext, identifier, clientActor);
40     }
41
42     @Override
43     public DOMStoreTransactionChain createTransactionChain() {
44         return new ClientBackedTransactionChain(getClient().createLocalHistory());
45     }
46
47     @Override
48     public DOMStoreReadTransaction newReadOnlyTransaction() {
49         return new ClientBackedReadTransaction(getClient().createSnapshot(), null);
50     }
51
52     @Override
53     public DOMStoreWriteTransaction newWriteOnlyTransaction() {
54         return new ClientBackedWriteTransaction(getClient().createTransaction());
55     }
56
57     @Override
58     public DOMStoreReadWriteTransaction newReadWriteTransaction() {
59         return new ClientBackedReadWriteTransaction(getClient().createTransaction());
60     }
61 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.