Bug 1894: Add LISP configuration options to etc/custom.properties in Karaf
[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
69         int dclExecutorMaxQueueSize = actualProperties.getMaxDataChangeExecutorQueueSize();
70         int dclExecutorMaxPoolSize = actualProperties.getMaxDataChangeExecutorPoolSize();
71
72         ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool(
73                 dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL" );
74
75         ExecutorService domStoreExecutor = SpecialExecutors.newBoundedSingleThreadExecutor(
76                 actualProperties.getMaxDataStoreExecutorQueueSize(), "DOMStore-" + name );
77
78         InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name,
79                 domStoreExecutor, dataChangeListenerExecutor,
80                 actualProperties.getMaxDataChangeListenerQueueSize(), debugTransactions);
81
82         if(schemaService != null) {
83             schemaService.registerSchemaContextListener(dataStore);
84         }
85
86         return dataStore;
87     }
88 }