BUG-5280: remove support for talking to pre-Boron clients
[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.datastore.config.Configuration;
13 import org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl;
14 import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshot;
15 import org.opendaylight.controller.sal.core.api.model.SchemaService;
16 import org.osgi.framework.BundleContext;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class DistributedDataStoreFactory {
21     private static final Logger LOG = LoggerFactory.getLogger(DistributedDataStoreFactory.class);
22
23     public static DistributedDataStore createInstance(SchemaService schemaService,
24             DatastoreContext datastoreContext, DatastoreSnapshotRestore datastoreSnapshotRestore,
25             ActorSystemProvider actorSystemProvider, BundleContext bundleContext) {
26
27         LOG.info("Create data store instance of type : {}", datastoreContext.getDataStoreName());
28
29         ActorSystem actorSystem = actorSystemProvider.getActorSystem();
30         DatastoreSnapshot restoreFromSnapshot = datastoreSnapshotRestore.getAndRemove(
31                 datastoreContext.getDataStoreName());
32         DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(datastoreContext);
33         DatastoreContextConfigAdminOverlay overlay = new DatastoreContextConfigAdminOverlay(
34                 introspector, bundleContext);
35
36         Configuration config = new ConfigurationImpl("module-shards.conf", "modules.conf");
37         final DistributedDataStore dataStore = new DistributedDataStore(actorSystem,
38                 new ClusterWrapperImpl(actorSystem), config, introspector.newContextFactory(), restoreFromSnapshot);
39
40         overlay.setListener(dataStore);
41
42         schemaService.registerSchemaContextListener(dataStore);
43
44         dataStore.setCloseable(overlay);
45         dataStore.waitTillReady();
46
47         return dataStore;
48     }
49 }