Adjust to yangtools-2.0.0 changes
[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.mdsal.dom.api.DOMSchemaService;
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     /**
28      * @deprecated Use {@link #create(String, DOMSchemaService)} instead.
29      */
30     @Deprecated
31     public static InMemoryDOMDataStore create(final String name,
32             @Nullable final SchemaService schemaService) {
33         return create(name, (DOMSchemaService)schemaService);
34     }
35
36     public static InMemoryDOMDataStore create(final String name,
37             @Nullable final DOMSchemaService schemaService) {
38         return create(name, schemaService, null);
39     }
40
41     /**
42      * Creates an InMemoryDOMDataStore instance.
43      *
44      * @param name the name of the data store
45      * @param schemaService the SchemaService to which to register the data store.
46      * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
47      *                   default property values are used.
48      * @return an InMemoryDOMDataStore instance
49      *
50      * @deprecated Use {@link #create(String, DOMSchemaService, InMemoryDOMDataStoreConfigProperties)} instead.
51      */
52     @Deprecated
53     public static InMemoryDOMDataStore create(final String name,
54             @Nullable final SchemaService schemaService,
55             @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
56         return create(name, (DOMSchemaService) schemaService, properties);
57     }
58
59     /**
60      * Creates an InMemoryDOMDataStore instance.
61      *
62      * @param name the name of the data store
63      * @param schemaService the SchemaService to which to register the data store.
64      * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
65      *                   default property values are used.
66      * @return an InMemoryDOMDataStore instance
67      */
68     public static InMemoryDOMDataStore create(final String name,
69             @Nullable final DOMSchemaService schemaService,
70             @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
71         return create(name, LogicalDatastoreType.OPERATIONAL, schemaService, false, properties);
72     }
73
74     /**
75      * Creates an InMemoryDOMDataStore instance.
76      *
77      * @param name the name of the data store
78      * @param schemaService the SchemaService to which to register the data store.
79      * @param debugTransactions enable transaction debugging
80      * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
81      *                   default property values are used.
82      * @return an InMemoryDOMDataStore instance
83      *
84      * @deprecated Use {@link #create(String, LogicalDatastoreType, SchemaService, boolean, InMemoryDOMDataStoreConfigProperties)}
85      *             instead.
86      */
87     @Deprecated
88     public static InMemoryDOMDataStore create(final String name,
89             @Nullable final SchemaService schemaService, final boolean debugTransactions,
90             @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
91         return create(name, LogicalDatastoreType.OPERATIONAL, schemaService, debugTransactions, properties);
92     }
93
94     /**
95      * Creates an InMemoryDOMDataStore instance.
96      *
97      * @param name the name of the data store
98      * @param type Data store type
99      * @param schemaService the SchemaService to which to register the data store.
100      * @param debugTransactions enable transaction debugging
101      * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
102      *                   default property values are used.
103      * @return an InMemoryDOMDataStore instance
104      *
105      * @deprecated Use {@link #create(String, LogicalDatastoreType, DOMSchemaService, boolean,
106      *                                InMemoryDOMDataStoreConfigProperties)} instead.
107      */
108     @Deprecated
109     public static InMemoryDOMDataStore create(final String name, final LogicalDatastoreType type,
110             @Nullable final SchemaService schemaService, final boolean debugTransactions,
111             @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
112         return create(name, type, (DOMSchemaService) schemaService, debugTransactions, properties);
113     }
114
115     /**
116      * Creates an InMemoryDOMDataStore instance.
117      *
118      * @param name the name of the data store
119      * @param type Data store type
120      * @param schemaService the SchemaService to which to register the data store.
121      * @param debugTransactions enable transaction debugging
122      * @param properties configuration properties for the InMemoryDOMDataStore instance. If null,
123      *                   default property values are used.
124      * @return an InMemoryDOMDataStore instance
125      */
126     public static InMemoryDOMDataStore create(final String name, final LogicalDatastoreType type,
127             @Nullable final DOMSchemaService schemaService, final boolean debugTransactions,
128             @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
129
130         InMemoryDOMDataStoreConfigProperties actualProperties = properties;
131         if (actualProperties == null) {
132             actualProperties = InMemoryDOMDataStoreConfigProperties.getDefault();
133         }
134
135         // For DataChangeListener notifications we use an executor that provides the fastest
136         // task execution time to get higher throughput as DataChangeListeners typically provide
137         // much of the business logic for a data model. If the executor queue size limit is reached,
138         // subsequent submitted notifications will block the calling thread.
139         int dclExecutorMaxQueueSize = actualProperties.getMaxDataChangeExecutorQueueSize();
140         int dclExecutorMaxPoolSize = actualProperties.getMaxDataChangeExecutorPoolSize();
141
142         ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool(
143                 dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL", InMemoryDOMDataStore.class);
144
145         final InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name, type, dataChangeListenerExecutor,
146                 actualProperties.getMaxDataChangeListenerQueueSize(), debugTransactions);
147
148         if (schemaService != null) {
149             schemaService.registerSchemaContextListener(dataStore);
150         }
151
152         return dataStore;
153     }
154 }