Allow shard settle timeout to be tuned
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DistributedDataStoreFactory.java
1 /*
2  * Copyright (c) 2014 Cisco 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.cluster.datastore;
9
10 import akka.actor.ActorSystem;
11 import org.opendaylight.controller.cluster.ActorSystemProvider;
12 import org.opendaylight.controller.cluster.databroker.ClientBackedDataStore;
13 import org.opendaylight.controller.cluster.datastore.config.Configuration;
14 import org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl;
15 import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot;
16 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public final class DistributedDataStoreFactory {
21
22     private static final Logger LOG = LoggerFactory.getLogger(DistributedDataStoreFactory.class);
23     private static final String DEFAULT_MODULE_SHARDS_PATH = "./configuration/initial/module-shards.conf";
24     private static final String DEFAULT_MODULES_PATH = "./configuration/initial/modules.conf";
25
26     private DistributedDataStoreFactory() {
27     }
28
29     public static AbstractDataStore createInstance(final DOMSchemaService schemaService,
30             final DatastoreContext initialDatastoreContext, final DatastoreSnapshotRestore datastoreSnapshotRestore,
31             final ActorSystemProvider actorSystemProvider, final DatastoreContextIntrospector introspector,
32             final DatastoreContextPropertiesUpdater updater) {
33         return createInstance(schemaService, initialDatastoreContext, datastoreSnapshotRestore, actorSystemProvider,
34                 introspector, updater, null);
35     }
36
37     // TODO: separate out settle wait so it is better controlled
38     public static AbstractDataStore createInstance(final DOMSchemaService schemaService,
39             final DatastoreContext initialDatastoreContext, final DatastoreSnapshotRestore datastoreSnapshotRestore,
40             final ActorSystemProvider actorSystemProvider, final DatastoreContextIntrospector introspector,
41             final DatastoreContextPropertiesUpdater updater, final Configuration orgConfig) {
42
43         final String datastoreName = initialDatastoreContext.getDataStoreName();
44         LOG.info("Create data store instance of type : {}", datastoreName);
45
46         final ActorSystem actorSystem = actorSystemProvider.getActorSystem();
47         final DatastoreSnapshot restoreFromSnapshot = datastoreSnapshotRestore.getAndRemove(datastoreName);
48
49         Configuration config;
50         if (orgConfig == null) {
51             config = new ConfigurationImpl(DEFAULT_MODULE_SHARDS_PATH, DEFAULT_MODULES_PATH);
52         } else {
53             config = orgConfig;
54         }
55         final ClusterWrapper clusterWrapper = new ClusterWrapperImpl(actorSystem);
56         final DatastoreContextFactory contextFactory = introspector.newContextFactory();
57
58         // This is the potentially-updated datastore context, distinct from the initial one
59         final DatastoreContext datastoreContext = contextFactory.getBaseDatastoreContext();
60
61         final AbstractDataStore dataStore;
62         if (datastoreContext.isUseTellBasedProtocol()) {
63             dataStore = new ClientBackedDataStore(actorSystem, clusterWrapper, config, contextFactory,
64                 restoreFromSnapshot);
65             LOG.info("Data store {} is using tell-based protocol", datastoreName);
66         } else {
67             dataStore = new DistributedDataStore(actorSystem, clusterWrapper, config, contextFactory,
68                 restoreFromSnapshot);
69             LOG.info("Data store {} is using ask-based protocol", datastoreName);
70         }
71         updater.setListener(dataStore);
72
73         schemaService.registerSchemaContextListener(dataStore);
74
75         dataStore.setCloseable(updater);
76         dataStore.waitTillReady();
77
78         return dataStore;
79     }
80 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.