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;
13 import javax.annotation.Nullable;
15 import org.opendaylight.controller.sal.core.api.model.SchemaService;
16 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
19 * A factory for creating InMemoryDOMDataStore instances.
21 * @author Thomas Pantelis
23 public final class InMemoryDOMDataStoreFactory {
25 private InMemoryDOMDataStoreFactory() {
28 public static InMemoryDOMDataStore create(final String name,
29 @Nullable final SchemaService schemaService) {
30 return create(name, schemaService, null);
34 * Creates an InMemoryDOMDataStore instance.
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
42 public static InMemoryDOMDataStore create(final String name,
43 @Nullable final SchemaService schemaService,
44 @Nullable final InMemoryDOMDataStoreConfigProperties properties) {
46 InMemoryDOMDataStoreConfigProperties actualProperties = properties;
47 if(actualProperties == null) {
48 actualProperties = InMemoryDOMDataStoreConfigProperties.getDefault();
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.
56 int dclExecutorMaxQueueSize = actualProperties.getMaxDataChangeExecutorQueueSize();
57 int dclExecutorMaxPoolSize = actualProperties.getMaxDataChangeExecutorPoolSize();
59 ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool(
60 dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL" );
62 ExecutorService domStoreExecutor = SpecialExecutors.newBoundedSingleThreadExecutor(
63 actualProperties.getMaxDataStoreExecutorQueueSize(), "DOMStore-" + name );
65 InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name,
66 domStoreExecutor, dataChangeListenerExecutor,
67 actualProperties.getMaxDataChangeListenerQueueSize());
69 if(schemaService != null) {
70 schemaService.registerSchemaContextListener(dataStore);