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;
12 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
13 import org.opendaylight.controller.md.sal.dom.broker.impl.compat.BackwardsCompatibleDataBroker;
14 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
15 import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
16 import org.opendaylight.controller.sal.core.api.data.DataProviderService;
17 import org.opendaylight.controller.sal.core.api.data.DataStore;
18 import org.opendaylight.controller.sal.core.api.model.SchemaService;
19 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
20 import org.opendaylight.controller.sal.core.api.mount.MountService;
21 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareDataStoreAdapter;
22 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker;
23 import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProviders;
24 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
25 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
26 import org.osgi.framework.BundleContext;
27 import org.osgi.framework.ServiceReference;
28 import org.osgi.framework.ServiceRegistration;
30 public class BrokerConfigActivator implements AutoCloseable {
32 private static InstanceIdentifier ROOT = InstanceIdentifier.builder()
35 private DataProviderService dataService;
37 private ServiceRegistration<DataBrokerService> dataReg = null;
38 private ServiceRegistration<DataProviderService> dataProviderReg = null;
39 private ServiceRegistration<MountService> mountReg = null;
40 private ServiceRegistration<MountProvisionService> mountProviderReg = null;
41 private SchemaService schemaService = null;
42 private ServiceRegistration<RpcProvisionRegistry> rpcProvisionRegistryReg = null;
43 private MountPointManagerImpl mountService = null;
45 private SchemaAwareDataStoreAdapter wrappedStore = null;
47 public void start(final BrokerImpl broker, final DataStore store,
48 final DOMDataBroker asyncBroker, final BundleContext context) {
50 final Hashtable<String, String> emptyProperties = new Hashtable<String, String>();
51 broker.setBundleContext(context);
53 final ServiceReference<SchemaService> serviceRef = context
54 .getServiceReference(SchemaService.class);
55 schemaService = context.<SchemaService> getService(serviceRef);
57 broker.setRouter(new SchemaAwareRpcBroker("/", SchemaContextProviders
58 .fromSchemaService(schemaService)));
60 if (asyncBroker == null) {
61 dataService = new DataBrokerImpl();
62 dataProviderReg = context.registerService(
63 DataProviderService.class, dataService, emptyProperties);
65 wrappedStore = new SchemaAwareDataStoreAdapter();
66 wrappedStore.changeDelegate(store);
67 wrappedStore.setValidationEnabled(false);
68 context.registerService(SchemaServiceListener.class, wrappedStore,
71 dataService.registerConfigurationReader(ROOT, wrappedStore);
72 dataService.registerCommitHandler(ROOT, wrappedStore);
73 dataService.registerOperationalReader(ROOT, wrappedStore);
75 BackwardsCompatibleDataBroker compatibleDataBroker = new BackwardsCompatibleDataBroker(
77 context.registerService(SchemaServiceListener.class,
78 compatibleDataBroker, emptyProperties);
79 dataService = compatibleDataBroker;
82 mountService = new MountPointManagerImpl();
83 dataReg = context.registerService(DataBrokerService.class, dataService,
85 mountReg = context.registerService(MountService.class, mountService,
87 mountProviderReg = context.registerService(MountProvisionService.class,
88 mountService, emptyProperties);
90 rpcProvisionRegistryReg = context
91 .registerService(RpcProvisionRegistry.class,
92 broker.getRouter(), emptyProperties);
98 if (dataReg != null) {
102 if (dataProviderReg != null) {
103 dataProviderReg.unregister();
104 dataProviderReg = null;
106 if (mountReg != null) {
107 mountReg.unregister();
110 if (mountProviderReg != null) {
111 mountProviderReg.unregister();
112 mountProviderReg = null;
114 if (rpcProvisionRegistryReg != null) {
115 rpcProvisionRegistryReg.unregister();
116 rpcProvisionRegistryReg = null;
121 * @return the dataService
123 public DataProviderService getDataService() {
129 * the dataService to set
131 public void setDataService(final DataProviderService dataService) {
132 this.dataService = dataService;