MDSAL-370: expose LogicalDatastoreType-aware constructor 02/76202/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Sep 2018 08:30:13 +0000 (10:30 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 18 Sep 2018 08:35:21 +0000 (08:35 +0000)
This exposes the constructors needed to customize the underlying
data tree instances -- both through direct configuration and via
LogicalDatastoreType.

Change-Id: I056d74f4059cca792aa49e5463570b35e1d0005a
JIRA: MDSAL-370
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStore.java

index 61dbb025d073a97e13ee10cad2d88a36cffb1147..580190e702e738b6db68071baec2a5291af164df 100644 (file)
@@ -7,10 +7,12 @@
  */
 package org.opendaylight.mdsal.dom.store.inmemory;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.mdsal.dom.spi.store.DOMStore;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
@@ -53,8 +55,8 @@ public class InMemoryDOMDataStore extends TransactionReadyPrototype<String> impl
         Identifiable<String>, SchemaContextListener, AutoCloseable, DOMStoreTreeChangePublisher {
     private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataStore.class);
 
-    private final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL);
     private final AtomicLong txCounter = new AtomicLong(0);
+    private final DataTree dataTree;
 
     private final InMemoryDOMStoreTreeChangePublisher changePublisher;
     private final ExecutorService dataChangeListenerExecutor;
@@ -65,14 +67,28 @@ public class InMemoryDOMDataStore extends TransactionReadyPrototype<String> impl
 
     public InMemoryDOMDataStore(final String name, final ExecutorService dataChangeListenerExecutor) {
         this(name, dataChangeListenerExecutor,
-                InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_LISTENER_QUEUE_SIZE, false);
+            InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_LISTENER_QUEUE_SIZE, false);
     }
 
     public InMemoryDOMDataStore(final String name, final ExecutorService dataChangeListenerExecutor,
             final int maxDataChangeListenerQueueSize, final boolean debugTransactions) {
-        this.name = Preconditions.checkNotNull(name);
-        this.dataChangeListenerExecutor = Preconditions.checkNotNull(dataChangeListenerExecutor);
+        this(name, LogicalDatastoreType.OPERATIONAL, dataChangeListenerExecutor, maxDataChangeListenerQueueSize,
+            debugTransactions);
+    }
+
+    public InMemoryDOMDataStore(final String name, final LogicalDatastoreType type,
+            final ExecutorService dataChangeListenerExecutor, final int maxDataChangeListenerQueueSize,
+            final boolean debugTransactions) {
+        this(name, defaultConfig(type), dataChangeListenerExecutor, maxDataChangeListenerQueueSize, debugTransactions);
+    }
+
+    public InMemoryDOMDataStore(final String name, final DataTreeConfiguration config,
+            final ExecutorService dataChangeListenerExecutor, final int maxDataChangeListenerQueueSize,
+            final boolean debugTransactions) {
+        this.name = requireNonNull(name);
+        this.dataChangeListenerExecutor = requireNonNull(dataChangeListenerExecutor);
         this.debugTransactions = debugTransactions;
+        dataTree = new InMemoryDataTreeFactory().create(config);
         changePublisher = new InMemoryDOMStoreTreeChangePublisher(this.dataChangeListenerExecutor,
                 maxDataChangeListenerQueueSize);
     }
@@ -92,20 +108,20 @@ public class InMemoryDOMDataStore extends TransactionReadyPrototype<String> impl
 
     @Override
     public DOMStoreReadTransaction newReadOnlyTransaction() {
-        return SnapshotBackedTransactions.newReadTransaction(
-                nextIdentifier(),debugTransactions, dataTree.takeSnapshot());
+        return SnapshotBackedTransactions.newReadTransaction(nextIdentifier(), debugTransactions,
+            dataTree.takeSnapshot());
     }
 
     @Override
     public DOMStoreReadWriteTransaction newReadWriteTransaction() {
-        return SnapshotBackedTransactions.newReadWriteTransaction(nextIdentifier(),
-                debugTransactions, dataTree.takeSnapshot(), this);
+        return SnapshotBackedTransactions.newReadWriteTransaction(nextIdentifier(), debugTransactions,
+            dataTree.takeSnapshot(), this);
     }
 
     @Override
     public DOMStoreWriteTransaction newWriteOnlyTransaction() {
-        return SnapshotBackedTransactions.newWriteTransaction(nextIdentifier(),
-                debugTransactions, dataTree.takeSnapshot(), this);
+        return SnapshotBackedTransactions.newWriteTransaction(nextIdentifier(), debugTransactions,
+            dataTree.takeSnapshot(), this);
     }
 
     @Override
@@ -157,8 +173,7 @@ public class InMemoryDOMDataStore extends TransactionReadyPrototype<String> impl
 
     @Override
     protected DOMStoreThreePhaseCommitCohort transactionReady(final SnapshotBackedWriteTransaction<String> tx,
-                                                              final DataTreeModification modification,
-                                                              final Exception readyError) {
+            final DataTreeModification modification, final Exception readyError) {
         LOG.debug("Tx: {} is submitted. Modifications: {}", tx.getIdentifier(), modification);
         return new InMemoryDOMStoreThreePhaseCommitCohort(this, tx, modification, readyError);
     }
@@ -179,4 +194,15 @@ public class InMemoryDOMDataStore extends TransactionReadyPrototype<String> impl
         dataTree.commit(candidate);
         changePublisher.publishChange(candidate);
     }
+
+    private static DataTreeConfiguration defaultConfig(final LogicalDatastoreType type) {
+        switch (type) {
+            case CONFIGURATION:
+                return DataTreeConfiguration.DEFAULT_CONFIGURATION;
+            case OPERATIONAL:
+                return DataTreeConfiguration.DEFAULT_OPERATIONAL;
+            default:
+                throw new IllegalArgumentException("Unhandled datastore type " + type);
+        }
+    }
 }