2 * Copyright (c) 2014 Cisco 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
8 package org.opendaylight.controller.cluster.datastore;
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;
20 public class DistributedDataStoreFactory {
21 private static final Logger LOG = LoggerFactory.getLogger(DistributedDataStoreFactory.class);
23 public static DistributedDataStore createInstance(SchemaService schemaService,
24 DatastoreContext datastoreContext, DatastoreSnapshotRestore datastoreSnapshotRestore,
25 ActorSystemProvider actorSystemProvider, BundleContext bundleContext) {
27 LOG.info("Create data store instance of type : {}", datastoreContext.getDataStoreName());
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);
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);
40 overlay.setListener(dataStore);
42 schemaService.registerSchemaContextListener(dataStore);
44 dataStore.setCloseable(overlay);
45 dataStore.waitTillReady();