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.controller.md.sal.dom.store.impl;
10 import com.google.common.util.concurrent.ListeningExecutorService;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import java.util.concurrent.ExecutorService;
13 import javax.annotation.Nullable;
14 import org.opendaylight.controller.sal.core.api.model.SchemaService;
15 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
18 * A factory for creating InMemoryDOMDataStore instances.
20 * @author Thomas Pantelis
22 public final class InMemoryDOMDataStoreFactory {
24 private InMemoryDOMDataStoreFactory() {
27 public static InMemoryDOMDataStore create(final String name,
28 @Nullable final SchemaService schemaService) {
29 return create(name, schemaService, null);
33 * Creates an InMemoryDOMDataStore instance.
35 * @param name the name of the data store
36 * @param schemaService the SchemaService to which to register the data store.
37 * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
38 * default property values are used.
39 * @return an InMemoryDOMDataStore instance
41 public static InMemoryDOMDataStore create(final String name,
42 @Nullable final SchemaService schemaService,
43 @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
44 return create(name, schemaService, false, properties);
48 * Creates an InMemoryDOMDataStore instance.
50 * @param name the name of the data store
51 * @param schemaService the SchemaService to which to register the data store.
52 * @param debugTransactions enable transaction debugging
53 * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
54 * default property values are used.
55 * @return an InMemoryDOMDataStore instance
57 public static InMemoryDOMDataStore create(final String name,
58 @Nullable final SchemaService schemaService, final boolean debugTransactions,
59 @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
61 InMemoryDOMDataStoreConfigProperties actualProperties = properties;
62 if (actualProperties == null) {
63 actualProperties = InMemoryDOMDataStoreConfigProperties.getDefault();
66 // For DataChangeListener notifications we use an executor that provides the fastest
67 // task execution time to get higher throughput as DataChangeListeners typically provide
68 // much of the business logic for a data model. If the executor queue size limit is reached,
69 // subsequent submitted notifications will block the calling thread.
70 int dclExecutorMaxQueueSize = actualProperties.getMaxDataChangeExecutorQueueSize();
71 int dclExecutorMaxPoolSize = actualProperties.getMaxDataChangeExecutorPoolSize();
73 ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool(
74 dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL" );
76 final ListeningExecutorService commitExecutor = MoreExecutors.sameThreadExecutor();
77 final InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name,
78 commitExecutor, dataChangeListenerExecutor,
79 actualProperties.getMaxDataChangeListenerQueueSize(), debugTransactions);
81 if (schemaService != null) {
82 schemaService.registerSchemaContextListener(dataStore);