Updated implementation of broker (data services, generated code), added Integration...
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / BrokerActivator.java
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.binding.impl;
9
10 import java.util.Hashtable;
11
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
13 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
14 import org.osgi.framework.BundleActivator;
15 import org.osgi.framework.BundleContext;
16 import org.osgi.framework.ServiceRegistration;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class BrokerActivator implements BundleActivator {
21
22     private static final Logger log = LoggerFactory.getLogger(BrokerActivator.class);
23     private BindingAwareBrokerImpl baSal;
24     private ServiceRegistration<BindingAwareBroker> baSalRegistration;
25     private HashMapDataStore store = new HashMapDataStore();
26     private InstanceIdentifier<?> root = InstanceIdentifier.builder().toInstance();
27     
28     @Override
29     public void start(BundleContext context) throws Exception {
30         log.info("Binding Aware Broker initialized");
31         baSal = new BindingAwareBrokerImpl();
32         baSal.setBrokerBundleContext(context);
33         baSal.start();
34         baSal.getDataBroker().registerDataReader(root, store);
35         baSal.getDataBroker().registerCommitHandler(root, store);
36
37         BindingAwareBroker baSalService = baSal;
38         Hashtable<String, String> properties = new Hashtable<>();
39         this.baSalRegistration = context.registerService(BindingAwareBroker.class, baSalService, properties);
40
41     }
42
43     @Override
44     public void stop(BundleContext context) throws Exception {
45         log.info("Binding Aware Broker stopped");
46         baSalRegistration.unregister();
47     }
48
49 }