Merge "Avoiding hash collisions of a match with its reverse"
[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 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareDataStoreAdapter
16 import org.opendaylight.controller.sal.core.api.model.SchemaServiceListener
17 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker
18
19 class BrokerConfigActivator implements AutoCloseable {
20     
21     
22     private static val ROOT = InstanceIdentifier.builder().toInstance();
23
24     @Property
25     private var DataBrokerImpl dataService;
26     
27     private var ServiceRegistration<SchemaService> schemaReg;
28     private var ServiceRegistration<DataBrokerService> dataReg;
29     private var ServiceRegistration<DataProviderService> dataProviderReg;
30     private var ServiceRegistration<MountService> mountReg;
31     private var ServiceRegistration<MountProvisionService> mountProviderReg;
32     private var SchemaServiceImpl schemaService;
33     private var MountPointManagerImpl mountService;
34     
35     SchemaAwareDataStoreAdapter wrappedStore
36
37     public def void start(BrokerImpl broker,DataStore store,BundleContext context) {
38         val emptyProperties = new Hashtable<String, String>();
39         broker.setBundleContext(context);
40         
41         
42         schemaService = new SchemaServiceImpl();
43         schemaService.setContext(context);
44         schemaService.setParser(new YangParserImpl());
45         schemaService.start();
46         schemaReg = context.registerService(SchemaService, schemaService, emptyProperties);
47         
48         broker.setRouter(new SchemaAwareRpcBroker("/",schemaService));
49         
50         dataService = new DataBrokerImpl();
51         dataService.setExecutor(broker.getExecutor());
52         
53         dataReg = context.registerService(DataBrokerService, dataService, emptyProperties);
54         dataProviderReg = context.registerService(DataProviderService, dataService, emptyProperties);
55
56         wrappedStore = new SchemaAwareDataStoreAdapter();
57         wrappedStore.changeDelegate(store);
58         wrappedStore.setValidationEnabled(false);
59        
60         context.registerService(SchemaServiceListener,wrappedStore,emptyProperties)  
61         
62         dataService.registerConfigurationReader(ROOT, wrappedStore);
63         dataService.registerCommitHandler(ROOT, wrappedStore);
64         dataService.registerOperationalReader(ROOT, wrappedStore);
65         
66         mountService = new MountPointManagerImpl();
67         mountService.setDataBroker(dataService);
68         
69         mountReg = context.registerService(MountService, mountService, emptyProperties);
70         mountProviderReg =  context.registerService(MountProvisionService, mountService, emptyProperties);
71     }
72
73     override def close() {
74         schemaReg?.unregister();
75         dataReg?.unregister();
76         dataProviderReg?.unregister();
77         mountReg?.unregister();
78         mountProviderReg?.unregister();
79     }
80     
81 }