2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.databroker;
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.ActorUtils;
20 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
21 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
22 import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
23 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
26 * Implements a distributed DOMStore using ClientActor.
28 public class ClientBackedDataStore extends AbstractDataStore {
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);
37 ClientBackedDataStore(final ActorUtils actorUtils, final ClientIdentifier identifier,
38 final DataStoreClient clientActor) {
39 super(actorUtils, identifier, clientActor);
43 public DOMStoreTransactionChain createTransactionChain() {
44 return new ClientBackedTransactionChain(getClient().createLocalHistory(), debugAllocation());
48 public DOMStoreReadTransaction newReadOnlyTransaction() {
49 return new ClientBackedReadTransaction(getClient().createSnapshot(), null, allocationContext());
53 public DOMStoreWriteTransaction newWriteOnlyTransaction() {
54 return new ClientBackedWriteTransaction(getClient().createTransaction(), allocationContext());
58 public DOMStoreReadWriteTransaction newReadWriteTransaction() {
59 return new ClientBackedReadWriteTransaction(getClient().createTransaction(), allocationContext());
62 private boolean debugAllocation() {
63 return getActorUtils().getDatastoreContext().isTransactionDebugContextEnabled();
66 private Throwable allocationContext() {
67 return debugAllocation() ? new Throwable("allocated at") : null;