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