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