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 java.util.concurrent.ExecutorService;
11 import javax.annotation.Nullable;
12 import org.opendaylight.controller.sal.core.api.model.SchemaService;
13 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
16 * A factory for creating InMemoryDOMDataStore instances.
18 * @author Thomas Pantelis
20 public final class InMemoryDOMDataStoreFactory {
22 private InMemoryDOMDataStoreFactory() {
25 public static InMemoryDOMDataStore create(final String name,
26 @Nullable final SchemaService schemaService) {
27 return create(name, schemaService, null);
31 * Creates an InMemoryDOMDataStore instance.
33 * @param name the name of the data store
34 * @param schemaService the SchemaService to which to register the data store.
35 * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
36 * default property values are used.
37 * @return an InMemoryDOMDataStore instance
39 public static InMemoryDOMDataStore create(final String name,
40 @Nullable final SchemaService schemaService,
41 @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
42 return create(name, schemaService, false, properties);
46 * Creates an InMemoryDOMDataStore instance.
48 * @param name the name of the data store
49 * @param schemaService the SchemaService to which to register the data store.
50 * @param debugTransactions enable transaction debugging
51 * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
52 * default property values are used.
53 * @return an InMemoryDOMDataStore instance
55 public static InMemoryDOMDataStore create(final String name,
56 @Nullable final SchemaService schemaService, final boolean debugTransactions,
57 @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
59 InMemoryDOMDataStoreConfigProperties actualProperties = properties;
60 if(actualProperties == null) {
61 actualProperties = InMemoryDOMDataStoreConfigProperties.getDefault();
64 // For DataChangeListener notifications we use an executor that provides the fastest
65 // task execution time to get higher throughput as DataChangeListeners typically provide
66 // much of the business logic for a data model. If the executor queue size limit is reached,
67 // subsequent submitted notifications will block the calling thread.
69 int dclExecutorMaxQueueSize = actualProperties.getMaxDataChangeExecutorQueueSize();
70 int dclExecutorMaxPoolSize = actualProperties.getMaxDataChangeExecutorPoolSize();
72 ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool(
73 dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL" );
75 ExecutorService domStoreExecutor = SpecialExecutors.newBoundedSingleThreadExecutor(
76 actualProperties.getMaxDataStoreExecutorQueueSize(), "DOMStore-" + name );
78 InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name,
79 domStoreExecutor, dataChangeListenerExecutor,
80 actualProperties.getMaxDataChangeListenerQueueSize(), debugTransactions);
82 if(schemaService != null) {
83 schemaService.registerSchemaContextListener(dataStore);