From c0388db3bb13351373982f985d8a4ecf2f4fa37b Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 26 Apr 2018 18:09:42 +0200 Subject: [PATCH] Rework InMemoryDOMDataStoreConfigProperties Rework InMemoryDOMDataStoreConfigProperties to use immutables.org, i.e. generate a builder. Also include debug transaction flag in properties. This cleans up InMemoryDOMDataStoreFactory, making it more straightforward. Change-Id: Ifae57b87fe8a87d183958e4826afc1e17c173273 Signed-off-by: Robert Varga --- dom/mdsal-dom-inmemory-datastore/pom.xml | 5 ++ .../InMemoryDOMDataStoreConfigProperties.java | 85 ++++++++----------- .../inmemory/InMemoryDOMDataStoreFactory.java | 58 +++++-------- 3 files changed, 64 insertions(+), 84 deletions(-) diff --git a/dom/mdsal-dom-inmemory-datastore/pom.xml b/dom/mdsal-dom-inmemory-datastore/pom.xml index dbc5c27603..e3ad524f49 100644 --- a/dom/mdsal-dom-inmemory-datastore/pom.xml +++ b/dom/mdsal-dom-inmemory-datastore/pom.xml @@ -84,6 +84,11 @@ org.osgi.core + + org.immutables + value + + junit diff --git a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStoreConfigProperties.java b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStoreConfigProperties.java index f23d66daf4..ba701d4684 100644 --- a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStoreConfigProperties.java +++ b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStoreConfigProperties.java @@ -5,9 +5,12 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.mdsal.dom.store.inmemory; +import org.eclipse.jdt.annotation.NonNull; +import org.immutables.value.Value; +import org.immutables.value.Value.Style.ImplementationVisibility; + /** * Holds configuration properties when creating an {@link InMemoryDOMDataStore} instance via the * {@link InMemoryDOMDataStoreFactory}. @@ -15,92 +18,78 @@ package org.opendaylight.mdsal.dom.store.inmemory; * @author Thomas Pantelis * @see InMemoryDOMDataStoreFactory */ -public final class InMemoryDOMDataStoreConfigProperties { +@Value.Immutable +@Value.Style(visibility = ImplementationVisibility.PRIVATE) +public abstract class InMemoryDOMDataStoreConfigProperties { public static final int DEFAULT_MAX_DATA_CHANGE_EXECUTOR_QUEUE_SIZE = 1000; public static final int DEFAULT_MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE = 20; public static final int DEFAULT_MAX_DATA_CHANGE_LISTENER_QUEUE_SIZE = 1000; public static final int DEFAULT_MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE = 5000; - private static final InMemoryDOMDataStoreConfigProperties DEFAULT = - create(DEFAULT_MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE, - DEFAULT_MAX_DATA_CHANGE_EXECUTOR_QUEUE_SIZE, - DEFAULT_MAX_DATA_CHANGE_LISTENER_QUEUE_SIZE, - DEFAULT_MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE); - - private final int maxDataChangeExecutorQueueSize; - private final int maxDataChangeExecutorPoolSize; - private final int maxDataChangeListenerQueueSize; - private final int maxDataStoreExecutorQueueSize; - - private InMemoryDOMDataStoreConfigProperties(final int maxDataChangeExecutorPoolSize, - final int maxDataChangeExecutorQueueSize, final int maxDataChangeListenerQueueSize, - final int maxDataStoreExecutorQueueSize) { - this.maxDataChangeExecutorQueueSize = maxDataChangeExecutorQueueSize; - this.maxDataChangeExecutorPoolSize = maxDataChangeExecutorPoolSize; - this.maxDataChangeListenerQueueSize = maxDataChangeListenerQueueSize; - this.maxDataStoreExecutorQueueSize = maxDataStoreExecutorQueueSize; - } + private static final @NonNull InMemoryDOMDataStoreConfigProperties DEFAULT = builder().build(); /** - * Constructs an instance with the given property values. + * Returns the InMemoryDOMDataStoreConfigProperties instance with default values. * - * @param maxDataChangeExecutorPoolSize - * maximum thread pool size for the data change notification executor. - * @param maxDataChangeExecutorQueueSize - * maximum queue size for the data change notification executor. - * @param maxDataChangeListenerQueueSize - * maximum queue size for the data change listeners. - * @param maxDataStoreExecutorQueueSize - * maximum queue size for the data store executor. + * @return the InMemoryDOMDataStoreConfigProperties instance with default values. */ - public static InMemoryDOMDataStoreConfigProperties create(final int maxDataChangeExecutorPoolSize, - final int maxDataChangeExecutorQueueSize, final int maxDataChangeListenerQueueSize, - final int maxDataStoreExecutorQueueSize) { - return new InMemoryDOMDataStoreConfigProperties(maxDataChangeExecutorPoolSize, - maxDataChangeExecutorQueueSize, maxDataChangeListenerQueueSize, - maxDataStoreExecutorQueueSize); + public static @NonNull InMemoryDOMDataStoreConfigProperties getDefault() { + return DEFAULT; } - public static InMemoryDOMDataStoreConfigProperties create(final int maxDataChangeExecutorPoolSize, - final int maxDataChangeExecutorQueueSize, final int maxDataChangeListenerQueueSize) { - return new InMemoryDOMDataStoreConfigProperties(maxDataChangeExecutorPoolSize, - maxDataChangeExecutorQueueSize, maxDataChangeListenerQueueSize, - DEFAULT_MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE); + /** + * Returns a new {@link InMemoryDOMDataStoreConfigPropertiesBuilder}. + * + * @return a new {@link InMemoryDOMDataStoreConfigPropertiesBuilder}. + */ + public static @NonNull InMemoryDOMDataStoreConfigPropertiesBuilder builder() { + return new InMemoryDOMDataStoreConfigPropertiesBuilder(); } /** - * Returns the InMemoryDOMDataStoreConfigProperties instance with default values. + * Returns true if transaction allocation debugging should be enabled. + * + * @return true if transaction allocation debugging should be enabled. */ - public static InMemoryDOMDataStoreConfigProperties getDefault() { - return DEFAULT; + @Value.Default + public boolean getDebugTransactions() { + return false; } /** * Returns the maximum queue size for the data change notification executor. + * + * @return the maximum queue size for the data change notification executor. */ + @Value.Default public int getMaxDataChangeExecutorQueueSize() { - return maxDataChangeExecutorQueueSize; + return DEFAULT_MAX_DATA_CHANGE_EXECUTOR_QUEUE_SIZE; } /** * Returns the maximum thread pool size for the data change notification executor. + * + * @return the maximum thread pool size for the data change notification executor. */ + @Value.Default public int getMaxDataChangeExecutorPoolSize() { - return maxDataChangeExecutorPoolSize; + return DEFAULT_MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE; } /** * Returns the maximum queue size for the data change listeners. */ + @Value.Default public int getMaxDataChangeListenerQueueSize() { - return maxDataChangeListenerQueueSize; + return DEFAULT_MAX_DATA_CHANGE_LISTENER_QUEUE_SIZE; } /** * Returns the maximum queue size for the data store executor. */ + @Value.Default public int getMaxDataStoreExecutorQueueSize() { - return maxDataStoreExecutorQueueSize; + return DEFAULT_MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE; } } diff --git a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStoreFactory.java b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStoreFactory.java index 947137c43f..c040b2ce82 100644 --- a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStoreFactory.java +++ b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStoreFactory.java @@ -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", InMemoryDOMDataStore.class); - + 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", InMemoryDOMDataStore.class); + } } -- 2.36.6