Prevent ConfigPusher from killing its thread
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / osgi / Activator.java
1 package org.opendaylight.controller.sal.binding.osgi;
2
3 import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
4 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
5 import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService;
6 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
7 import org.osgi.framework.BundleActivator;
8 import org.osgi.framework.BundleContext;
9 import org.osgi.framework.ServiceRegistration;
10
11 import java.util.Hashtable;
12
13 public class Activator implements BundleActivator {
14
15     private ServiceRegistration<?> reg;
16     private ServiceRegistration<SchemaServiceListener> listenerReg;
17     private ServiceRegistration<BindingIndependentMappingService> mappingReg;
18
19     @Override
20     public void start(BundleContext context) throws Exception {
21                 RuntimeGeneratedMappingServiceImpl service = new RuntimeGeneratedMappingServiceImpl();
22         service.setPool(SingletonHolder.CLASS_POOL);
23         service.init();
24         startRuntimeMappingService(service, context);
25     }
26
27     private void startRuntimeMappingService(RuntimeGeneratedMappingServiceImpl service, BundleContext context) {
28         Hashtable<String, String> properties = new Hashtable<String, String>();
29         listenerReg = context.registerService(SchemaServiceListener.class, service, properties);
30         mappingReg = context.registerService(BindingIndependentMappingService.class, service, properties);
31         
32     }
33
34     @Override
35     public void stop(BundleContext context) throws Exception {
36         if(listenerReg != null) {
37             listenerReg.unregister();
38         }
39         if(mappingReg != null) {
40             mappingReg.unregister();
41         }
42     }
43 }