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 org.opendaylight.yangtools.util.PropertyUtils;
19 import com.google.common.util.concurrent.MoreExecutors;
22 * A factory for creating InMemoryDOMDataStore instances.
24 * @author Thomas Pantelis
26 public final class InMemoryDOMDataStoreFactory {
28 private static final String DCL_EXECUTOR_MAX_QUEUE_SIZE_PROP =
29 "mdsal.datastore-dcl-notification-queue.size";
30 private static final int DEFAULT_DCL_EXECUTOR_MAX_QUEUE_SIZE = 1000;
32 private static final String DCL_EXECUTOR_MAX_POOL_SIZE_PROP =
33 "mdsal.datastore-dcl-notification-pool.size";
34 private static final int DEFAULT_DCL_EXECUTOR_MAX_POOL_SIZE = 20;
36 private InMemoryDOMDataStoreFactory() {
40 * Creates an InMemoryDOMDataStore instance.
42 * @param name the name of the data store
43 * @param schemaService the SchemaService to which to register the data store.
44 * @return an InMemoryDOMDataStore instance
46 public static InMemoryDOMDataStore create(final String name,
47 @Nullable final SchemaService schemaService) {
49 // For DataChangeListener notifications we use an executor that provides the fastest
50 // task execution time to get higher throughput as DataChangeListeners typically provide
51 // much of the business logic for a data model. If the executor queue size limit is reached,
52 // subsequent submitted notifications will block the calling thread.
54 int dclExecutorMaxQueueSize = PropertyUtils.getIntSystemProperty(
55 DCL_EXECUTOR_MAX_QUEUE_SIZE_PROP, DEFAULT_DCL_EXECUTOR_MAX_QUEUE_SIZE);
56 int dclExecutorMaxPoolSize = PropertyUtils.getIntSystemProperty(
57 DCL_EXECUTOR_MAX_POOL_SIZE_PROP, DEFAULT_DCL_EXECUTOR_MAX_POOL_SIZE);
59 ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool(
60 dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL" );
62 InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name,
63 MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()),
64 dataChangeListenerExecutor);
66 if(schemaService != null) {
67 schemaService.registerSchemaContextListener(dataStore);