2 * Copyright (c) 2013 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.sal.dom.broker
10 import java.util.Hashtable
11 import org.opendaylight.controller.sal.core.api.data.DataBrokerService
12 import org.opendaylight.controller.sal.core.api.data.DataProviderService
13 import org.opendaylight.controller.sal.core.api.data.DataStore
14 import org.opendaylight.controller.sal.core.api.model.SchemaService
15 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener
16 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService
17 import org.opendaylight.controller.sal.core.api.mount.MountService
18 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareDataStoreAdapter
19 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker
20 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
21 import org.osgi.framework.BundleContext
22 import org.osgi.framework.ServiceRegistration
23 import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProviders
24 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry
25 import org.opendaylight.controller.md.sal.dom.broker.impl.compat.BackwardsCompatibleDataBroker
26 import org.opendaylight.controller.md.sal.dom.broker.impl.DOMDataBrokerImpl
27 import com.google.common.util.concurrent.MoreExecutors
28 import com.google.common.collect.ImmutableMap
29 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType
30 import org.opendaylight.controller.sal.core.spi.data.DOMStore
31 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore
32 import java.util.concurrent.Executors
33 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker
35 class BrokerConfigActivator implements AutoCloseable {
37 private static val ROOT = InstanceIdentifier.builder().toInstance();
40 private var DataProviderService dataService;
42 private var ServiceRegistration<DataBrokerService> dataReg;
43 private var ServiceRegistration<DataProviderService> dataProviderReg;
44 private var ServiceRegistration<MountService> mountReg;
45 private var ServiceRegistration<MountProvisionService> mountProviderReg;
46 private var SchemaService schemaService;
47 private var ServiceRegistration<RpcProvisionRegistry> rpcProvisionRegistryReg;
48 private var MountPointManagerImpl mountService;
50 SchemaAwareDataStoreAdapter wrappedStore
52 public def void start(BrokerImpl broker, DataStore store, DOMDataBroker asyncBroker,BundleContext context) {
53 val emptyProperties = new Hashtable<String, String>();
54 broker.setBundleContext(context);
56 val serviceRef = context.getServiceReference(SchemaService);
57 schemaService = context.getService(serviceRef);
59 broker.setRouter(new SchemaAwareRpcBroker("/", SchemaContextProviders.fromSchemaService(schemaService)));
62 if(asyncBroker == null) {
63 dataService = new DataBrokerImpl();
64 dataProviderReg = context.registerService(DataProviderService, dataService, emptyProperties);
66 wrappedStore = new SchemaAwareDataStoreAdapter();
67 wrappedStore.changeDelegate(store);
68 wrappedStore.setValidationEnabled(false);
69 context.registerService(SchemaServiceListener, wrappedStore, emptyProperties)
71 dataService.registerConfigurationReader(ROOT, wrappedStore);
72 dataService.registerCommitHandler(ROOT, wrappedStore);
73 dataService.registerOperationalReader(ROOT, wrappedStore);
75 val compatibleDataBroker = new BackwardsCompatibleDataBroker(asyncBroker);
76 context.registerService(SchemaServiceListener,compatibleDataBroker,emptyProperties);
77 dataService = compatibleDataBroker;
83 mountService = new MountPointManagerImpl();
84 dataReg = context.registerService(DataBrokerService, dataService, emptyProperties);
85 mountReg = context.registerService(MountService, mountService, emptyProperties);
86 mountProviderReg = context.registerService(MountProvisionService, mountService, emptyProperties);
88 rpcProvisionRegistryReg = context.registerService(RpcProvisionRegistry, broker.getRouter(), emptyProperties);
91 override def close() {
92 dataReg?.unregister();
93 dataProviderReg?.unregister();
94 mountReg?.unregister();
95 mountProviderReg?.unregister();
96 rpcProvisionRegistryReg?.unregister();