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