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