1159d5650e6599a72db0af912909244d17cf612b
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / BrokerConfigActivator.xtend
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.dom.broker
9
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
26 class BrokerConfigActivator implements AutoCloseable {
27
28     private static val ROOT = InstanceIdentifier.builder().toInstance();
29
30     @Property
31     private var DataBrokerImpl dataService;
32
33     private var ServiceRegistration<DataBrokerService> dataReg;
34     private var ServiceRegistration<DataProviderService> dataProviderReg;
35     private var ServiceRegistration<MountService> mountReg;
36     private var ServiceRegistration<MountProvisionService> mountProviderReg;
37     private var SchemaService schemaService;
38     private var ServiceRegistration<RpcProvisionRegistry> rpcProvisionRegistryReg;
39     private var MountPointManagerImpl mountService;
40
41     SchemaAwareDataStoreAdapter wrappedStore
42
43     public def void start(BrokerImpl broker, DataStore store, BundleContext context) {
44         val emptyProperties = new Hashtable<String, String>();
45         broker.setBundleContext(context);
46
47         val serviceRef = context.getServiceReference(SchemaService);
48         schemaService = context.getService(serviceRef);
49
50         broker.setRouter(new SchemaAwareRpcBroker("/", SchemaContextProviders.fromSchemaService(schemaService)));
51
52         dataService = new DataBrokerImpl();
53         dataService.setExecutor(broker.getExecutor());
54
55         dataReg = context.registerService(DataBrokerService, dataService, emptyProperties);
56         dataProviderReg = context.registerService(DataProviderService, dataService, emptyProperties);
57
58         wrappedStore = new SchemaAwareDataStoreAdapter();
59         wrappedStore.changeDelegate(store);
60         wrappedStore.setValidationEnabled(false);
61
62         context.registerService(SchemaServiceListener, wrappedStore, emptyProperties)
63
64         dataService.registerConfigurationReader(ROOT, wrappedStore);
65         dataService.registerCommitHandler(ROOT, wrappedStore);
66         dataService.registerOperationalReader(ROOT, wrappedStore);
67
68         mountService = new MountPointManagerImpl();
69         mountService.setDataBroker(dataService);
70
71         mountReg = context.registerService(MountService, mountService, emptyProperties);
72         mountProviderReg = context.registerService(MountProvisionService, mountService, emptyProperties);
73
74         rpcProvisionRegistryReg = context.registerService(RpcProvisionRegistry, broker.getRouter(), emptyProperties);
75     }
76
77     override def close() {
78         dataReg?.unregister();
79         dataProviderReg?.unregister();
80         mountReg?.unregister();
81         mountProviderReg?.unregister();
82         rpcProvisionRegistryReg?.unregister();
83     }
84
85 }