Merge "Bug 164"
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / BrokerConfigActivator.xtend
1 package org.opendaylight.controller.sal.dom.broker
2
3 import org.osgi.framework.ServiceRegistration
4 import org.opendaylight.controller.sal.core.api.model.SchemaService
5 import org.opendaylight.controller.sal.core.api.data.DataBrokerService
6 import org.opendaylight.controller.sal.core.api.data.DataProviderService
7 import org.opendaylight.controller.sal.dom.broker.impl.HashMapDataStore
8 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService
9 import org.opendaylight.controller.sal.core.api.mount.MountService
10 import org.osgi.framework.BundleContext
11 import java.util.Hashtable
12 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl
13 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
14 import org.opendaylight.controller.sal.core.api.data.DataStore
15
16 class BrokerConfigActivator implements AutoCloseable {
17     
18     
19     private static val ROOT = InstanceIdentifier.builder().toInstance();
20     
21     private var ServiceRegistration<SchemaService> schemaReg;
22     private var ServiceRegistration<DataBrokerService> dataReg;
23     private var ServiceRegistration<DataProviderService> dataProviderReg;
24     private var ServiceRegistration<MountService> mountReg;
25     private var ServiceRegistration<MountProvisionService> mountProviderReg;
26     
27     private var SchemaServiceImpl schemaService;
28     private var DataBrokerImpl dataService;
29     private var MountPointManagerImpl mountService;
30
31     public def void start(BrokerImpl broker,DataStore store,BundleContext context) {
32         val emptyProperties = new Hashtable<String, String>();
33         broker.setBundleContext(context);
34         
35
36         schemaService = new SchemaServiceImpl();
37         schemaService.setContext(context);
38         schemaService.setParser(new YangParserImpl());
39         schemaService.start();
40         schemaReg = context.registerService(SchemaService, schemaService, emptyProperties);
41         
42         dataService = new DataBrokerImpl();
43         dataService.setExecutor(broker.getExecutor());
44         
45         dataReg = context.registerService(DataBrokerService, dataService, emptyProperties);
46         dataProviderReg = context.registerService(DataProviderService, dataService, emptyProperties);
47
48         dataService.registerConfigurationReader(ROOT, store);
49         dataService.registerCommitHandler(ROOT, store);
50         dataService.registerOperationalReader(ROOT, store);
51         
52         mountService = new MountPointManagerImpl();
53         mountService.setDataBroker(dataService);
54         
55         mountReg = context.registerService(MountService, mountService, emptyProperties);
56         mountProviderReg =  context.registerService(MountProvisionService, mountService, emptyProperties);
57     }
58
59     override def close() {
60         schemaReg?.unregister();
61         dataReg?.unregister();
62         dataProviderReg?.unregister();
63         mountReg?.unregister();
64         mountProviderReg?.unregister();
65     }
66     
67 }