Merge "Bug 1666: Fixing the clustering config file issue"
[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
13 import javax.annotation.Nullable;
14
15 import org.opendaylight.controller.sal.core.api.model.SchemaService;
16 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
17
18 /**
19  * A factory for creating InMemoryDOMDataStore instances.
20  *
21  * @author Thomas Pantelis
22  */
23 public final class InMemoryDOMDataStoreFactory {
24
25     private InMemoryDOMDataStoreFactory() {
26     }
27
28     public static InMemoryDOMDataStore create(final String name,
29             @Nullable final SchemaService 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,
43             @Nullable final SchemaService schemaService,
44             @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
45
46         InMemoryDOMDataStoreConfigProperties actualProperties = properties;
47         if(actualProperties == null) {
48             actualProperties = InMemoryDOMDataStoreConfigProperties.getDefault();
49         }
50
51         // For DataChangeListener notifications we use an executor that provides the fastest
52         // task execution time to get higher throughput as DataChangeListeners typically provide
53         // much of the business logic for a data model. If the executor queue size limit is reached,
54         // subsequent submitted notifications will block the calling thread.
55
56         int dclExecutorMaxQueueSize = actualProperties.getMaxDataChangeExecutorQueueSize();
57         int dclExecutorMaxPoolSize = actualProperties.getMaxDataChangeExecutorPoolSize();
58
59         ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool(
60                 dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL" );
61
62         ExecutorService domStoreExecutor = SpecialExecutors.newBoundedSingleThreadExecutor(
63                 actualProperties.getMaxDataStoreExecutorQueueSize(), "DOMStore-" + name );
64
65         InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name,
66                 domStoreExecutor, dataChangeListenerExecutor,
67                 actualProperties.getMaxDataChangeListenerQueueSize());
68
69         if(schemaService != null) {
70             schemaService.registerSchemaContextListener(dataStore);
71         }
72
73         return dataStore;
74     }
75 }