Merge "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 /*
2  * Copyright (c) 2014 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.osgi;
9
10 import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
11 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
12 import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService;
13 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
14 import org.osgi.framework.BundleActivator;
15 import org.osgi.framework.BundleContext;
16 import org.osgi.framework.ServiceRegistration;
17
18 import java.util.Hashtable;
19
20 public class Activator implements BundleActivator {
21
22     private ServiceRegistration<?> reg;
23     private ServiceRegistration<SchemaServiceListener> listenerReg;
24     private ServiceRegistration<BindingIndependentMappingService> mappingReg;
25
26     @Override
27     public void start(BundleContext context) throws Exception {
28                 RuntimeGeneratedMappingServiceImpl service = new RuntimeGeneratedMappingServiceImpl();
29         service.setPool(SingletonHolder.CLASS_POOL);
30         service.init();
31         startRuntimeMappingService(service, context);
32     }
33
34     private void startRuntimeMappingService(RuntimeGeneratedMappingServiceImpl service, BundleContext context) {
35         Hashtable<String, String> properties = new Hashtable<String, String>();
36         listenerReg = context.registerService(SchemaServiceListener.class, service, properties);
37         mappingReg = context.registerService(BindingIndependentMappingService.class, service, properties);
38         
39     }
40
41     @Override
42     public void stop(BundleContext context) throws Exception {
43         if(listenerReg != null) {
44             listenerReg.unregister();
45         }
46         if(mappingReg != null) {
47             mappingReg.unregister();
48         }
49     }
50 }