2 * Copyright (c) 2014 Brocade Communications 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.mdsal.dom.store.inmemory;
10 import java.util.concurrent.ExecutorService;
11 import org.eclipse.jdt.annotation.NonNullByDefault;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
14 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
17 * A factory for creating InMemoryDOMDataStore instances.
19 * @author Thomas Pantelis
22 public final class InMemoryDOMDataStoreFactory {
24 private InMemoryDOMDataStoreFactory() {
28 * Creates an InMemoryDOMDataStore instance with default properties.
30 * @param name the name of the data store
31 * @param schemaService the SchemaService to which to register the data store.
32 * @return an InMemoryDOMDataStore instance
34 public static InMemoryDOMDataStore create(final String name, final @Nullable DOMSchemaService schemaService) {
35 return create(name, InMemoryDOMDataStoreConfigProperties.getDefault(), schemaService);
39 * Creates an InMemoryDOMDataStore instance.
41 * @param name the name of the data store
42 * @param properties configuration properties for the InMemoryDOMDataStore instance.
43 * @param schemaService the SchemaService to which to register the data store.
44 * @return an InMemoryDOMDataStore instance
46 public static InMemoryDOMDataStore create(final String name, final InMemoryDOMDataStoreConfigProperties properties,
47 @Nullable final DOMSchemaService schemaService) {
48 final ExecutorService dataChangeListenerExecutor = createExecutorService(name, properties);
49 final InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name, dataChangeListenerExecutor,
50 properties.getMaxDataChangeListenerQueueSize(), properties.getDebugTransactions());
52 if (schemaService != null) {
53 schemaService.registerSchemaContextListener(dataStore::onModelContextUpdated);
59 private static ExecutorService createExecutorService(final String name,
60 final InMemoryDOMDataStoreConfigProperties props) {
61 // For DataChangeListener notifications we use an executor that provides the fastest
62 // task execution time to get higher throughput as DataChangeListeners typically provide
63 // much of the business logic for a data model. If the executor queue size limit is reached,
64 // subsequent submitted notifications will block the calling thread.
65 return SpecialExecutors.newBlockingBoundedFastThreadPool(
66 props.getMaxDataChangeExecutorPoolSize(), props.getMaxDataChangeExecutorQueueSize(),
67 name + "-DCL", InMemoryDOMDataStoreFactory.class);