Fix occasional NPEs in Connection manager
[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.osgi.framework.BundleActivator;
14 import org.osgi.framework.BundleContext;
15 import org.osgi.framework.ServiceRegistration;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class BrokerActivator implements BundleActivator {
20
21         private static final Logger log = LoggerFactory.getLogger(BrokerActivator.class);
22         private BindingAwareBrokerImpl baSal;
23         private ServiceRegistration<BindingAwareBroker> baSalRegistration;
24         
25         
26         @Override
27         public void start(BundleContext context) throws Exception {
28                 log.info("Binding Aware Broker initialized");
29                 baSal = new BindingAwareBrokerImpl();
30                 baSal.setBrokerBundleContext(context);
31                 baSal.start();
32                 
33                 BindingAwareBroker baSalService = baSal;
34                 Hashtable<String, String> properties = new Hashtable<>();
35                 this.baSalRegistration = context.registerService(BindingAwareBroker.class,baSalService, properties);
36                 
37         }
38
39         @Override
40         public void stop(BundleContext context) throws Exception {
41                 log.info("Binding Aware Broker stopped");
42                 baSalRegistration.unregister();
43         }
44
45 }