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.md.sal.dom.api.DOMDataBroker
12 import org.opendaylight.controller.md.sal.dom.broker.impl.compat.BackwardsCompatibleDataBroker
13 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry
14 import org.opendaylight.controller.sal.core.api.data.DataBrokerService
15 import org.opendaylight.controller.sal.core.api.data.DataProviderService
16 import org.opendaylight.controller.sal.core.api.data.DataStore
17 import org.opendaylight.controller.sal.core.api.model.SchemaService
18 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService
19 import org.opendaylight.controller.sal.core.api.mount.MountService
20 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareDataStoreAdapter
21 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker
22 import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProviders
23 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
24 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener
25 import org.osgi.framework.BundleContext
26 import org.osgi.framework.ServiceRegistration
28 class BrokerConfigActivator implements AutoCloseable {
30 private static val ROOT = InstanceIdentifier.builder().toInstance();
33 private var DataProviderService dataService;
35 private var ServiceRegistration<DataBrokerService> dataReg;
36 private var ServiceRegistration<DataProviderService> dataProviderReg;
37 private var ServiceRegistration<MountService> mountReg;
38 private var ServiceRegistration<MountProvisionService> mountProviderReg;
39 private var SchemaService schemaService;
40 private var ServiceRegistration<RpcProvisionRegistry> rpcProvisionRegistryReg;
41 private var MountPointManagerImpl mountService;
43 SchemaAwareDataStoreAdapter wrappedStore
45 public def void start(BrokerImpl broker, DataStore store, DOMDataBroker asyncBroker,BundleContext context) {
46 val emptyProperties = new Hashtable<String, String>();
47 broker.setBundleContext(context);
49 val serviceRef = context.getServiceReference(SchemaService);
50 schemaService = context.getService(serviceRef);
52 broker.setRouter(new SchemaAwareRpcBroker("/", SchemaContextProviders.fromSchemaService(schemaService)));
55 if(asyncBroker == null) {
56 dataService = new DataBrokerImpl();
57 dataProviderReg = context.registerService(DataProviderService, dataService, emptyProperties);
59 wrappedStore = new SchemaAwareDataStoreAdapter();
60 wrappedStore.changeDelegate(store);
61 wrappedStore.setValidationEnabled(false);
62 context.registerService(SchemaServiceListener, wrappedStore, emptyProperties)
64 dataService.registerConfigurationReader(ROOT, wrappedStore);
65 dataService.registerCommitHandler(ROOT, wrappedStore);
66 dataService.registerOperationalReader(ROOT, wrappedStore);
68 val compatibleDataBroker = new BackwardsCompatibleDataBroker(asyncBroker);
69 context.registerService(SchemaServiceListener,compatibleDataBroker,emptyProperties);
70 dataService = compatibleDataBroker;
76 mountService = new MountPointManagerImpl();
77 dataReg = context.registerService(DataBrokerService, dataService, emptyProperties);
78 mountReg = context.registerService(MountService, mountService, emptyProperties);
79 mountProviderReg = context.registerService(MountProvisionService, mountService, emptyProperties);
81 rpcProvisionRegistryReg = context.registerService(RpcProvisionRegistry, broker.getRouter(), emptyProperties);
84 override def close() {
85 dataReg?.unregister();
86 dataProviderReg?.unregister();
87 mountReg?.unregister();
88 mountProviderReg?.unregister();
89 rpcProvisionRegistryReg?.unregister();