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