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.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
26 class BrokerConfigActivator implements AutoCloseable {
28 private static val ROOT = InstanceIdentifier.builder().toInstance();
31 private var DataBrokerImpl dataService;
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;
41 SchemaAwareDataStoreAdapter wrappedStore
43 public def void start(BrokerImpl broker, DataStore store, BundleContext context) {
44 val emptyProperties = new Hashtable<String, String>();
45 broker.setBundleContext(context);
47 val serviceRef = context.getServiceReference(SchemaService);
48 schemaService = context.getService(serviceRef);
50 broker.setRouter(new SchemaAwareRpcBroker("/", SchemaContextProviders.fromSchemaService(schemaService)));
52 dataService = new DataBrokerImpl();
53 dataService.setExecutor(broker.getExecutor());
55 dataReg = context.registerService(DataBrokerService, dataService, emptyProperties);
56 dataProviderReg = context.registerService(DataProviderService, dataService, emptyProperties);
58 wrappedStore = new SchemaAwareDataStoreAdapter();
59 wrappedStore.changeDelegate(store);
60 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 mountService = new MountPointManagerImpl();
69 mountService.setDataBroker(dataService);
71 mountReg = context.registerService(MountService, mountService, emptyProperties);
72 mountProviderReg = context.registerService(MountProvisionService, mountService, emptyProperties);
74 rpcProvisionRegistryReg = context.registerService(RpcProvisionRegistry, broker.getRouter(), emptyProperties);
77 override def close() {
78 dataReg?.unregister();
79 dataProviderReg?.unregister();
80 mountReg?.unregister();
81 mountProviderReg?.unregister();
82 rpcProvisionRegistryReg?.unregister();