6423544aad8c195fe85a59faa0fa13828627cdb2
[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 java.util.concurrent.ExecutorService;
11 import javax.annotation.Nullable;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.sal.core.api.model.SchemaService;
14 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
15
16 /**
17  * A factory for creating InMemoryDOMDataStore instances.
18  *
19  * @author Thomas Pantelis
20  */
21 public final class InMemoryDOMDataStoreFactory {
22
23     private InMemoryDOMDataStoreFactory() {
24     }
25
26     public static InMemoryDOMDataStore create(final String name,
27             @Nullable final SchemaService schemaService) {
28         return create(name, schemaService, null);
29     }
30
31     /**
32      * Creates an InMemoryDOMDataStore instance.
33      *
34      * @param name the name of the data store
35      * @param schemaService the SchemaService to which to register the data store.
36      * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
37      *                   default property values are used.
38      * @return an InMemoryDOMDataStore instance
39      */
40     public static InMemoryDOMDataStore create(final String name,
41             @Nullable final SchemaService schemaService,
42             @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
43         return create(name, LogicalDatastoreType.OPERATIONAL, schemaService, false, properties);
44     }
45
46     /**
47      * Creates an InMemoryDOMDataStore instance.
48      *
49      * @param name the name of the data store
50      * @param schemaService the SchemaService to which to register the data store.
51      * @param debugTransactions enable transaction debugging
52      * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
53      *                   default property values are used.
54      * @return an InMemoryDOMDataStore instance
55      *
56      * @deprecated Use {@link #create(String, LogicalDatastoreType, SchemaService, boolean, InMemoryDOMDataStoreConfigProperties)}
57      *             instead.
58      */
59     @Deprecated
60     public static InMemoryDOMDataStore create(final String name,
61             @Nullable final SchemaService schemaService, final boolean debugTransactions,
62             @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
63         return create(name, LogicalDatastoreType.OPERATIONAL, schemaService, debugTransactions, properties);
64     }
65
66     /**
67      * Creates an InMemoryDOMDataStore instance.
68      *
69      * @param name the name of the data store
70      * @param type Data store type
71      * @param schemaService the SchemaService to which to register the data store.
72      * @param debugTransactions enable transaction debugging
73      * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
74      *                   default property values are used.
75      * @return an InMemoryDOMDataStore instance
76      */
77     public static InMemoryDOMDataStore create(final String name, final LogicalDatastoreType type,
78             @Nullable final SchemaService schemaService, final boolean debugTransactions,
79             @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
80
81         InMemoryDOMDataStoreConfigProperties actualProperties = properties;
82         if (actualProperties == null) {
83             actualProperties = InMemoryDOMDataStoreConfigProperties.getDefault();
84         }
85
86         // For DataChangeListener notifications we use an executor that provides the fastest
87         // task execution time to get higher throughput as DataChangeListeners typically provide
88         // much of the business logic for a data model. If the executor queue size limit is reached,
89         // subsequent submitted notifications will block the calling thread.
90         int dclExecutorMaxQueueSize = actualProperties.getMaxDataChangeExecutorQueueSize();
91         int dclExecutorMaxPoolSize = actualProperties.getMaxDataChangeExecutorPoolSize();
92
93         ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool(
94                 dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL" );
95
96         final InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name, type, dataChangeListenerExecutor,
97                 actualProperties.getMaxDataChangeListenerQueueSize(), debugTransactions);
98
99         if (schemaService != null) {
100             schemaService.registerSchemaContextListener(dataStore);
101         }
102
103         return dataStore;
104     }
105 }