Check registration being closed
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / main / java / org / opendaylight / mdsal / dom / store / inmemory / InMemoryDOMDataStoreFactory.java
index d823e29ecd52f300f2bc64f78dcce6c1db75311a..0db38fe3aa3df5c1188640391edf05c15507544c 100644 (file)
@@ -8,7 +8,8 @@
 package org.opendaylight.mdsal.dom.store.inmemory;
 
 import java.util.concurrent.ExecutorService;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
 
@@ -17,62 +18,36 @@ import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
  *
  * @author Thomas Pantelis
  */
+@NonNullByDefault
 public final class InMemoryDOMDataStoreFactory {
 
     private InMemoryDOMDataStoreFactory() {
     }
 
-    public static InMemoryDOMDataStore create(final String name,
-            @Nullable final DOMSchemaService schemaService) {
-        return create(name, schemaService, null);
-    }
-
     /**
-     * Creates an InMemoryDOMDataStore instance.
+     * Creates an InMemoryDOMDataStore instance with default properties.
      *
      * @param name the name of the data store
      * @param schemaService the SchemaService to which to register the data store.
-     * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
-     *                   default property values are used.
      * @return an InMemoryDOMDataStore instance
      */
-    public static InMemoryDOMDataStore create(final String name,
-            @Nullable final DOMSchemaService schemaService,
-            @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
-        return create(name, schemaService, false, properties);
+    public static InMemoryDOMDataStore create(final String name, final @Nullable DOMSchemaService schemaService) {
+        return create(name, InMemoryDOMDataStoreConfigProperties.getDefault(), schemaService);
     }
 
     /**
      * Creates an InMemoryDOMDataStore instance.
      *
      * @param name the name of the data store
+     * @param properties configuration properties for the InMemoryDOMDataStore instance.
      * @param schemaService the SchemaService to which to register the data store.
-     * @param debugTransactions enable transaction debugging
-     * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
-     *                   default property values are used.
      * @return an InMemoryDOMDataStore instance
      */
-    public static InMemoryDOMDataStore create(final String name,
-            @Nullable final DOMSchemaService schemaService, final boolean debugTransactions,
-            @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
-
-        InMemoryDOMDataStoreConfigProperties actualProperties = properties;
-        if (actualProperties == null) {
-            actualProperties = InMemoryDOMDataStoreConfigProperties.getDefault();
-        }
-
-        // For DataChangeListener notifications we use an executor that provides the fastest
-        // task execution time to get higher throughput as DataChangeListeners typically provide
-        // much of the business logic for a data model. If the executor queue size limit is reached,
-        // subsequent submitted notifications will block the calling thread.
-        int dclExecutorMaxQueueSize = actualProperties.getMaxDataChangeExecutorQueueSize();
-        int dclExecutorMaxPoolSize = actualProperties.getMaxDataChangeExecutorPoolSize();
-
-        ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool(
-                dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL");
-
+    public static InMemoryDOMDataStore create(final String name, final InMemoryDOMDataStoreConfigProperties properties,
+            @Nullable final DOMSchemaService schemaService) {
+        final ExecutorService dataChangeListenerExecutor = createExecutorService(name, properties);
         final InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name, dataChangeListenerExecutor,
-                actualProperties.getMaxDataChangeListenerQueueSize(), debugTransactions);
+            properties.getMaxDataChangeListenerQueueSize(), properties.getDebugTransactions());
 
         if (schemaService != null) {
             schemaService.registerSchemaContextListener(dataStore);
@@ -80,4 +55,15 @@ public final class InMemoryDOMDataStoreFactory {
 
         return dataStore;
     }
+
+    private static ExecutorService createExecutorService(final String name,
+            final InMemoryDOMDataStoreConfigProperties props) {
+        // For DataChangeListener notifications we use an executor that provides the fastest
+        // task execution time to get higher throughput as DataChangeListeners typically provide
+        // much of the business logic for a data model. If the executor queue size limit is reached,
+        // subsequent submitted notifications will block the calling thread.
+        return SpecialExecutors.newBlockingBoundedFastThreadPool(
+            props.getMaxDataChangeExecutorPoolSize(), props.getMaxDataChangeExecutorQueueSize(),
+            name + "-DCL", InMemoryDOMDataStoreFactory.class);
+    }
 }