* 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}.
* @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;
}
}
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;
*
* @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);
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);
+ }
}