Merge "BUG-1542 Remove netconf-ssh|tcp features from netconf-all feature"
[controller.git] / opendaylight / md-sal / sal-inmemory-datastore / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / InMemoryDOMDataStoreFactory.java
1 /*
2  * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.dom.store.impl;
9
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;
16
17 /**
18  * A factory for creating InMemoryDOMDataStore instances.
19  *
20  * @author Thomas Pantelis
21  */
22 public final class InMemoryDOMDataStoreFactory {
23
24     private InMemoryDOMDataStoreFactory() {
25     }
26
27     public static InMemoryDOMDataStore create(final String name,
28             @Nullable final SchemaService schemaService) {
29         return create(name, schemaService, null);
30     }
31
32     /**
33      * Creates an InMemoryDOMDataStore instance.
34      *
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
40      */
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);
45     }
46
47     /**
48      * Creates an InMemoryDOMDataStore instance.
49      *
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
56      */
57     public static InMemoryDOMDataStore create(final String name,
58             @Nullable final SchemaService schemaService, final boolean debugTransactions,
59             @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
60
61         InMemoryDOMDataStoreConfigProperties actualProperties = properties;
62         if (actualProperties == null) {
63             actualProperties = InMemoryDOMDataStoreConfigProperties.getDefault();
64         }
65
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();
72
73         ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool(
74                 dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL" );
75
76         final ListeningExecutorService commitExecutor = MoreExecutors.sameThreadExecutor();
77         final InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name,
78             commitExecutor, dataChangeListenerExecutor,
79                 actualProperties.getMaxDataChangeListenerQueueSize(), debugTransactions);
80
81         if (schemaService != null) {
82             schemaService.registerSchemaContextListener(dataStore);
83         }
84
85         return dataStore;
86     }
87 }