Merge "Make configuration push timeout configurable"
[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.controller.sal.core.api.model.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
25 class BrokerConfigActivator implements AutoCloseable {
26
27     private static val ROOT = InstanceIdentifier.builder().toInstance();
28
29     @Property
30     private var DataBrokerImpl dataService;
31
32     private var ServiceRegistration<SchemaService> schemaReg;
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 MountPointManagerImpl mountService;
39
40     SchemaAwareDataStoreAdapter wrappedStore
41
42     public def void start(BrokerImpl broker, DataStore store, BundleContext context) {
43         val emptyProperties = new Hashtable<String, String>();
44         broker.setBundleContext(context);
45
46         val serviceRef = context.getServiceReference(SchemaService);
47         schemaService = context.getService(serviceRef);
48         schemaReg = context.registerService(SchemaService, schemaService, emptyProperties);
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
75     override def close() {
76         schemaReg?.unregister();
77         dataReg?.unregister();
78         dataProviderReg?.unregister();
79         mountReg?.unregister();
80         mountProviderReg?.unregister();
81     }
82
83 }