2 * Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.md.sal.dom.store.impl;
11 import java.util.concurrent.ExecutorService;
12 import java.util.concurrent.Executors;
14 import javax.annotation.Nullable;
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;
21 * A factory for creating InMemoryDOMDataStore instances.
23 * @author Thomas Pantelis
25 public final class InMemoryDOMDataStoreFactory {
27 private InMemoryDOMDataStoreFactory() {
30 public static InMemoryDOMDataStore create(final String name,
31 @Nullable final SchemaService schemaService) {
32 return create(name, schemaService, null);
36 * Creates an InMemoryDOMDataStore instance.
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
44 public static InMemoryDOMDataStore create(final String name,
45 @Nullable final SchemaService schemaService,
46 @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
48 InMemoryDOMDataStoreConfigProperties actualProperties = properties;
49 if(actualProperties == null) {
50 actualProperties = InMemoryDOMDataStoreConfigProperties.getDefault();
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.
58 int dclExecutorMaxQueueSize = actualProperties.getMaxDataChangeExecutorQueueSize();
59 int dclExecutorMaxPoolSize = actualProperties.getMaxDataChangeExecutorPoolSize();
61 ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool(
62 dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL" );
64 InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name,
65 MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()),
66 dataChangeListenerExecutor, actualProperties.getMaxDataChangeListenerQueueSize());
68 if(schemaService != null) {
69 schemaService.registerSchemaContextListener(dataStore);